Hi everyone,

I'm working on writing a small app that will stream mp3 files. I'm using the 
NPR code, but having a strange problem with mediaPlayer.prepareAsync().

I'm using a trimmed down version of the 
PlaybackService<https://code.google.com/p/npr-android-app/source/browse/trunk/Npr/src/org/npr/android/news/PlaybackService.java>from
 the NPR 
app <https://code.google.com/p/npr-android-app/>, which is getting started 
correctly. I am getting a reference to the service inside an OnClick handler 
inside an Activity, and calling listen() with the URL to the MP3 stream. The 
following code is from my PlaybackService:

public void listen(String url) throws IllegalArgumentException, 
IllegalStateException, IOException { 
    if (mediaPlayer == null) { 
        mediaPlayer = new MediaPlayer(); 
    } 
    mediaPlayer.setOnBufferingUpdateListener(this); 
    mediaPlayer.setOnCompletionListener(this); 
    mediaPlayer.setOnErrorListener(this); 
    mediaPlayer.setOnInfoListener(this); 
    mediaPlayer.setOnPreparedListener(this); 
    synchronized (this) {
        mediaPlayer.setDataSource(url);
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mediaPlayer.prepareAsync();
    }
}

// ... lots of other code

@Override
public void onPrepared(MediaPlayer mp) { 
    Log.d(LOG_TAG, "Prepared"); 
    play();
}


I have the other callbacks defined as well. I can see from LogCat that the 
MediaPlayer is loading the stream and buffering, as I see the following 
messages:

AwesomePlayer  I  calling prefetcher->prepare()

AwesomePlayer  I  prefetcher is done preparing

But my onPrepared method never gets called. If I add a timer and try to call 
play() on the MediaPlayer at some point after I see the above log messages, 
the media players plays, so it is indeed entering into the Prepared state.

If I replace the call to prepareAsync() with prepare(), the player just 
works. This is all on 2.2, which I have been reading seems to have some 
issues, but the problem I'm having don't seem related, as the stream works 
fine when prepare() is used.

I did notice that the Content-Length on the the stream is quite large 
(450MB), but since I can call play on the Media Player without getting an 
exception, it appears to be handlings this OK.

The only other change is that in the NPR app, the service is being bound to 
and the playback started from inside a View object (while in my app, this 
happens inside an Activity).

Any thoughts on what I could be doing wrong?

Thanks!

Jim    

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to