Issue with audio playback using setNextMediaPlayer

牧云@^-^@ 提交于 2019-12-23 12:45:38

问题


I need to play an audio without gaps between lopping, the audio needs to be looped forever without gaps. Using setNextMediaPlayer only merge two audio tracks without gaps, after that it automatically stops playing the audio, it is not looping for ever. Thanks in advance.

    mp1 = MediaPlayer.create(getApplicationContext(), R.raw.loop);
    mp2 = MediaPlayer.create(getApplicationContext(), R.raw.loop);

protected void play() {
    // TODO Auto-generated method stub

    mp1.start();
    mp1.setNextMediaPlayer(mp2);
    // mp2.setNextMediaPlayer(mp1);

}

回答1:


I tried to help a guy do that just a few days ago. See this question.

I'm not sure if he was able to achieve what he wanted, but I believe your problem is that the MediaPlayer is not in the prepared state after the 2nd track finishes. You will need to use the onCompletion listener to return it to the prepared state by calling stop() and prepareAsync(). If it doesn't need to be in the prepared state (I'm honestly not sure), it would be faster to call seekTo(0) from the onCompletion listener.

You will definitely need to uncomment the mp2.setNextMediaPlayer(mp1); line.



来源:https://stackoverflow.com/questions/20034519/issue-with-audio-playback-using-setnextmediaplayer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!