Set prepareListener before calling prepare.

This commit is contained in:
Bryce Curtis 2010-10-14 09:58:37 -05:00
parent be16eebf55
commit 6d605c1cbf

View File

@ -182,6 +182,8 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
if (this.isStreaming(file)) { if (this.isStreaming(file)) {
this.mPlayer.setDataSource(file); this.mPlayer.setDataSource(file);
this.mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); this.mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
this.setState(MEDIA_STARTING);
this.mPlayer.setOnPreparedListener(this);
this.mPlayer.prepareAsync(); this.mPlayer.prepareAsync();
} }
@ -195,13 +197,13 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
else { else {
this.mPlayer.setDataSource("/sdcard/" + file); this.mPlayer.setDataSource("/sdcard/" + file);
} }
this.setState(MEDIA_STARTING);
this.mPlayer.setOnPreparedListener(this);
this.mPlayer.prepare(); this.mPlayer.prepare();
// Get duration // Get duration
this.duration = this.mPlayer.getDuration(); this.duration = this.mPlayer.getDuration();
} }
this.mPlayer.setOnPreparedListener(this);
this.setState(MEDIA_STARTING);
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();