How to play mp3 file using volley with async task?

166 Views Asked by At

Hello friends I am new in android I want play online mp3 file from url I used it async task for playing online mp3 file but problem is that it takes too much time for processing request I heard volley is best for this purpose now I used volley but when request send to server it block my main Ui thread while I heard volley itself manage aysc task and faster performance but in my case I did see anything like that please help how play audio from url faster and second without block main thread with help of volley here audio url and my code

"http://wpaorg.wordproject.com/bibles/app/audio/21/1/1.mp3"

   RequestQueue queue = Volley.newRequestQueue(this);
            String url ="http://wpaorg.wordproject.com/bibles/app/audio/21/"+booknumber+"/"+chapternumber+".mp3";

// Request a string response from the provided URL.
            StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
                    new Response.Listener<String>() {
                        @Override
                        public void onResponse(String response) {
                            // Display the first 500 characters of the response string.

                            Toast.makeText(ALLVERSE.this, ""+response, Toast.LENGTH_SHORT).show();

                        }
                    }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                    Toast.makeText(ALLVERSE.this, ""+error, Toast.LENGTH_SHORT).show();

                }
            });

// Add the request to the RequestQueue.
            queue.add(stringRequest);

when i tried send request it takes to much time and second block ui thread why?

0

There are 0 best solutions below