的MediaPlayer播放音频在后台播放下一个 [英] MediaPlayer play audio in background and play next one

查看:131
本文介绍了的MediaPlayer播放音频在后台播放下一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用低于code在后台播放音频:

I use below code to play audio in background:

String[] Path = new String[] {path1, path2, ...};
mMediaPlayer.setDataSource(Path[i]);
mMediaPlayer.prepare();
mMediaPlayer.start();
mMediaPlayer.seekTo(0);

虽然我在后台打第一个路径[0]。 我想让它自动播放下一个路径[1]路径后,[0]玩说完,如何到达呢?

While I play the first one Path[0] in background. I want to make it auto play next one Path[1] after Path[0] play finish, how to arrive it?

推荐答案

您应该重写onCompletionListener这样,

You should override onCompletionListener like this,

mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {           
    public void onCompletion(MediaPlayer mp) {          
        Log.i("Completion Listener","Song Complete");
        mp.stop();
        mp.reset();
        mp.setDataSource([nextElement]);
        mp.prepare();
        mp.start();
    }
});

如果您在MediaPlayer的使用上preparedListener那么CAL也使用prepareAsync命令,而忽略了。开始()。

If you use a onPreparedListener in your MediaPlayer then you cal also use the prepareAsync command and ignore the .start().

这篇关于的MediaPlayer播放音频在后台播放下一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆