Android 媒体播放器 OncompletionListener 播放下一首歌曲但不播放第二首歌曲
Android Media player OncompletionListener Play Next song but not the second song
我有一个带有音乐播放器的应用程序,我正在使用 @override 方法 OnCompletionListener 在音乐播放完毕并传递到下一首歌曲时收听,下面的代码有效,但在第二首歌曲中完成时 OncompletionListener 是没有再次呼叫,音乐结束时音乐停止,如何继续播放下一首歌曲?
OnCompletionListener
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
NextSong();
}
});
下一曲方法
public void NextSong (){
num = posicion++;
if (MainActivity.num <= MainActivity.listaArray.size() - 2) {
mediaPlayer.reset();
uri = Uri.parse(String.valueOf(archivosMp3[num + 1]));
mmr.setDataSource(String.valueOf(archivosMp3[num + 1]));
mediaPlayer = mediaPlayer.create(Servicio_Reproductor.this, MainActivity.uri);
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mediaPlayer.start();
}
});
试试这个,
public class MediaplayerActivity extends Activity implements OnCompletionListener
{
@Override
protected void onCreate(Bundle savedInstanceState) {
mMediaPlayer.setOnCompletionListener(this);
}
@Override
public void onCompletion(MediaPlayer mp) {
.
.
.
mediaPlayer = mediaPlayer.create(Servicio_Reproductor.this, MainActivity.uri);
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mMediaPlayer.setOnCompletionListener(this);
mediaPlayer.start();
}
});
}
}
我有一个带有音乐播放器的应用程序,我正在使用 @override 方法 OnCompletionListener 在音乐播放完毕并传递到下一首歌曲时收听,下面的代码有效,但在第二首歌曲中完成时 OncompletionListener 是没有再次呼叫,音乐结束时音乐停止,如何继续播放下一首歌曲?
OnCompletionListener
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
NextSong();
}
});
下一曲方法
public void NextSong (){
num = posicion++;
if (MainActivity.num <= MainActivity.listaArray.size() - 2) {
mediaPlayer.reset();
uri = Uri.parse(String.valueOf(archivosMp3[num + 1]));
mmr.setDataSource(String.valueOf(archivosMp3[num + 1]));
mediaPlayer = mediaPlayer.create(Servicio_Reproductor.this, MainActivity.uri);
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mediaPlayer.start();
}
});
试试这个,
public class MediaplayerActivity extends Activity implements OnCompletionListener
{
@Override
protected void onCreate(Bundle savedInstanceState) {
mMediaPlayer.setOnCompletionListener(this);
}
@Override
public void onCompletion(MediaPlayer mp) {
.
.
.
mediaPlayer = mediaPlayer.create(Servicio_Reproductor.this, MainActivity.uri);
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mMediaPlayer.setOnCompletionListener(this);
mediaPlayer.start();
}
});
}
}