Calling another activity when mediaplayer get finished playing

a 夏天 提交于 2019-11-29 05:12:57
Kandha
mPlayer.setOnCompletionListener(new
    OnCompletionListener() {        
        @Override
        public void onCompletion(MediaPlayer arg0) {
        Intent stopplay= new Intent(MyRecording.this,Recorded_Message.class);
        startActivity(stopplay);                
    }
});
Mr. Cat

I'll try to explain what is wrong in your code.

onCreate calls only one time when an Activity creates. So, in your code you set a source for your mPlayer:

mPlayer.setDataSource(mFileName);

then prepare it:

mPlayer.prepare();

and then starts playing:

mPlayer.start();    

As you just started mPlayer, of cource if statment will be false and the code in if will never be performed:

if(mPlayer.getCurrentPosition()== mPlayer.getDuration())
{
    Intent stopplay=new Intent(MyRecording.this,Recorded_Message.class);
    startActivity(stopplay); 
}

I remind you that onCreate is called only once.

So, use event as described above.

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