setNextMediaPlayer not working

你。 提交于 2019-12-06 22:26:43

Got it to work.

mp1.setDataSource(song1);

        mp1.prepareAsync();

        mp1.setOnPreparedListener(new OnPreparedListener() {

            @Override
            public void onPrepared(MediaPlayer mp) {
                mp1.start();
            }
        });
        //mp1.start();
        //mp1.seekTo(1000*100);

        mp2.setDataSource(song2);
        mp2.prepare();

        mp1.setNextMediaPlayer(mp2);

The only problem is that the second mediaplayer cannot be called as async (i.e. mp2.prepareAsync()). I do not know why, but if you try it like that it does not start, which is a bad thing :/.

MediaPlayer setNextMediaPlayer gives a lot of problem what i do is this: in the onCompletion() reset() the mediaplayer, setDataSource() and prepareAsync().

Something like this

        mp1.setDataSource("http://song1.MP3");
        mp1.prepareAsync();
        mp1.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                mp1.start();
            }
        });
        mp1.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                mp1.reset();
                //ADD FLAG FOR STOP
                try {
                    mp1.setDataSource("http://song2.mp3");
                } catch (IOException e) {
                    e.printStackTrace();
                }
                mp1.prepareAsync();
            }
        });

Then in the onCompletion you need some flag to check if the last song was played to stop, because the code as i posted will loop in the last song.

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