gpt4 book ai didi

java - 一首接一首播放歌曲导致 MP3Extractor 错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:08:23 25 4
gpt4 key购买 nike

@Override
public void onCreate(Bundle savedInstanceState) {
...
mMediaPlayer = new MediaPlayer();

mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mediaPlayer) {
playAudio(getNextAudioFile());
}
});
..
}

@Override
protected void onDestroy() {
super.onDestroy();
if(mMediaPlayer != null) {
mMediaPlayer.release();
mMediaPlayer = null;
}
}
private boolean playAudio(String file) {
if(file.isEmpty()) {
return true;
}

if(mMediaPlayer.isPlaying()) {
mMediaPlayer.stop();
}
mMediaPlayer.reset();

mAudioFile = new File(mBaseAudioDir, file);
if(mAudioFile.canRead()) {
try {
mMediaPlayer.setDataSource(mAudioFile.getPath());
mMediaPlayer.prepare();
} catch (IllegalArgumentException e) {
return false;
} catch (IllegalStateException e) {
return false;
} catch (IOException e) {
return false;
}
mMediaPlayer.start();
return true;
} else {
return false;
}
}

它可以工作,但是在歌曲结束后我在日志中有这个错误信息:

03-13 12:52:05.101: ERROR/MP3Extractor(34): Unable to resync. Signalling end of stream. 03-13 13:16:59.585: INFO/StagefrightPlayer(34): setDataSource('/mnt/sdcard/Audio/sound.mp3')

最佳答案

你真的不应该只有空的 catch block ,您可能会得到对该错误的解释,但您只是忽略了它试试这个:

     try {
mMediaPlayer.setDataSource(mAudioFile.getPath());
mMediaPlayer.prepare();
} catch (IllegalArgumentException e) {
Log.e(TAG, "mMediaPlayer IllegalArgumentException " ,e);
return false;
} catch (IOException e) {
Log.e(TAG, "mMediaPlayer IOException" ,e);
return false;
}

关于java - 一首接一首播放歌曲导致 MP3Extractor 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5296769/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com