0

I am streaming a live .mp3 from an online source. The problem is that between prepareAsync() and onPrepared(), almost 1 minute passes. That means that prepareAsync is taking upwards of 1 minute to prepare before playback can start. The code is below:

    void start1(String a){


        mp.setDataSource(a);
        mp.setOnPreparedListener(this);
        mp.prepareAsync();

        running=true;
        }catch(Exception e){


    noerror=false;
            }
  }

    @Override
  public void onPrepared(MediaPlayer mp1){
      Log.d("in here2","okay");
        //mp.start();
        Log.d("in here2","okay");
    } 

This is happening in emulator. Is there something wrong with the code?

vergil corleone
  • 1,071
  • 3
  • 15
  • 33
  • 2
    If you have a device to use for development, I strongly recommend it. The emulators typically have horrible performance, don't reflect actual device performance and you end up wasting too much of your day waiting for them. – Corey Scott Jul 13 '13 at 02:34
  • @CoreyScott I don't have a real device.. Regarding the question, when I don't use onPrepared() and instead put mp.start() below mp.prepareAsync(), the feed starts playing in 5 seconds.. – vergil corleone Jul 13 '13 at 02:55
  • Sorry to hear that. I have no direct experience in dealing with media like this. I don't know if it would make a different but you could put the start() call in a AsyncTask of your own writing. I might not improve the speed of the load but it would keep the UI responsive – Corey Scott Jul 13 '13 at 02:58
  • I don't have a real answer for this but this will help your app to be less frustrating for the user (http://stackoverflow.com/questions/6582908/why-does-it-take-so-long-for-androids-mediaplayer-to-prepare-some-live-streams/42042218#42042218) – LiTTle Feb 04 '17 at 15:42

0 Answers0