中調用,每當我開始我的流,我得到兩個MediaPlayer錯誤。Mediaplayer錯誤:開始在狀態4
01-03 12:04:35.738: D/PlayerActivity(10164): play
01-03 12:04:35.742: D/PlayerService(10164): setAudiotStreamType
01-03 12:04:35.742: D/PlayerService(10164): setDataSource
01-03 12:04:35.742: D/PlayerService(10164): prepareAsync
01-03 12:04:35.742: E/MediaPlayer(10164): start called in state 4
01-03 12:04:35.742: E/MediaPlayer(10164): error (-38, 0)
01-03 12:04:35.742: D/PlayerService(10164): onPrepared
01-03 12:04:35.742: D/PlayerService(10164): onCreate Service
01-03 12:04:35.750: E/MediaPlayer(10164): Error (-38,0)
01-03 12:04:38.261: D/PlayerService(10164): onPrepared
在調試標籤「播放」中,我點擊了播放按鈕。 比調用MediaPlayer服務中的「onCreate」,它執行「setAudioStreamTpe」,「setDataSource」,「prepareAsync」,然後onPrepared(myMediaPlayer)。 OnPrepared僅執行mp.start()。之後記錄「onPrepared」。然後,在我的服務的「onCreate」結尾,記錄「onCreate Service」。
爲什麼有2準備好了?用mp.prepare()我沒有錯誤。
驗證碼:
@Override
public void onCreate() {
mp = new MediaPlayer();
mp.setOnPreparedListener(this);
prepareMediaPlayer();
onPrepared(mp);
Log.d(TAG, "onCreate Service");
}
public void prepareMediaPlayer()
{
try {
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
Log.d(TAG, "setAudiotStreamType");
mp.setDataSource(PlayerActivity.soundUrl);
Log.d(TAG, "setDataSource");
mp.prepareAsync();
Log.d(TAG, "prepareAsync");
}
catch (IOException e) {}
catch (IllegalArgumentException e) {}
catch (IllegalStateException e) {}
}
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
if (PlayerService.mp.isPlaying() == true){
notification();
PlayerActivity.mpState = PlayerActivity.PLAYING;
}
Log.d(TAG, "onPrepared");
}
請提供代碼本身。 – MByD 2012-01-03 11:18:57
已添加代碼。希望能幫助到你! – Leandros 2012-01-03 11:25:32