2

I'm using Android 2.3, so according to this post: Streaming Audio from A URL in Android using MediaPlayer? streaming should work. I'm using a proven mp3 stream from kexp.org.

05-19 13:29:17.141: INFO/StagefrightPlayer(68): setDataSource('http://kexp-mp3-1.cac.washington.edu:8000')
05-19 13:29:17.141: INFO/AwesomePlayer(68): prepare was cancelled before doing anything


    try {
            mp = new MediaPlayer();
            mp.reset();
            mp.setOnPreparedListener(new OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mp) {
                    mp.start();

                }
            });
            mp.setDataSource("http://kexp-mp3-1.cac.washington.edu:8000");
            mp.prepareAsync();
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            if(mp!=null) {
                mp.release();
                mp =null;
            }
        } 
Community
  • 1
  • 1
hunterp
  • 15,716
  • 18
  • 63
  • 115

1 Answers1

1

Try this:

MediaPlayer.setDataSource() and prepare() not working - android

Community
  • 1
  • 1
Doug Stephen
  • 7,181
  • 1
  • 38
  • 46
  • I only accept for solutions. And your answer is something I've tried dozens of times, and this time, I get a failure. 05-19 13:48:02.921: 05-19 13:48:02.931: INFO/NuHTTPDataSource(68): connect to kexp-mp3-1.cac.washington.edu:8000/ @0 05-19 13:48:03.760: WARN/NuHTTPDataSource(68): Server did not give us the content length! 05-19 13:48:36.401: WARN/TimedEventQueue(68): Event 3 was not found in the queue, already cancelled? 05-19 13:48:42.150: WARN/libutils.threads(68): Thread (this=0x12560): don't call waitForExit() from this Thread object's thread. It's a guaranteed deadlock! – hunterp May 19 '11 at 17:49
  • Interesting. It was just an idea. I do know for a fact that Android tends to dislike ports in its URL's. Try it without the port. All the Android streaming I've done has been with the wrappers around MediaPlayer so Im no expert on this particular topic. – Doug Stephen May 19 '11 at 17:53
  • 1
    @hunterp did you ever try this without a port number in your URL string? – Doug Stephen May 22 '11 at 18:25
  • it was the finally block that caused the problem. – hunterp May 27 '11 at 00:14