Мне нужно использовать Mediaplayer внутри JsonObjectRequest. Мой код похож на этот
obreq = new JsonObjectRequest(Request.Method.GET, url,
// The third parameter Listener overrides the method onResponse() and passes
//JSONObject as a parameter
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
MediaPlayer mediaPlayer = MediaPlayer.create(this,R.raw.ok);
mediaPlayer.start();
JSONObject obj = response.getJSONObject("result");
}
// Try and catch are included to handle any errors due to JSON
catch (JSONException e) {
// If an error occurs, this prints the error to the log
Log.e("Errore: ", e.getLocalizedMessage());
e.printStackTrace();
}
}
},
// The final parameter overrides the method onErrorResponse() and passes VolleyError
//as a parameter
new Response.ErrorListener() {
@Override
// Handles errors that occur due to Volley
public void onErrorResponse(VolleyError error) {
Log.e("Volley", "Error");
MediaPlayer mediaPlayer = MediaPlayer.create(this,R.raw.error);
mediaPlayer.start();
throw new NullPointerException("uuuuuu");
}
}
) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> customHeaders = new HashMap<>();
String login_url = Helper.getConfigValue(getApplicationContext(), "login_url");
String pwd_url = Helper.getConfigValue(getApplicationContext(), "pwd_url");
String credentials = login_url + ":" + pwd_url;
String auth = "Basic "
+ Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
customHeaders.put("Content-Type", "application/json; charset=utf-8");
customHeaders.put("Authorization", auth);
return customHeaders;
}
};
флаг удаления shareedit
, но я получаю сообщение об ошибке
«Не удается разрешить метод» create (anonymous com. android .volley.Response.Listener, int) "
в строке MediaPlayer
Как решить проблему?
Спасибо