Listener (or handler) for video finish

旧巷老猫 提交于 2019-11-27 21:48:17

Seems you are looking for

setOnCompletionListener(MediaPlayer.OnCompletionListener l)

More in depth explanation can be found here

EDIT

This shows a solution where playback is called after completion using VideoView, MediaController and setOnCompletionListener().

Imon

here is my working chunk of code:

mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() 
        {           
            public void onCompletion(MediaPlayer mp) 
            {
                // Do whatever u need to do here

            }           
        });   
        vidView=(VideoView)findViewById(R.id.vidView);
    vidView.setMediaController(null);
    vidView.setVideoPath( "/mnt/external_sd/somerandommovie.3gp" );
    vidView.start();

    vidView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

        @Override
        public void onCompletion(MediaPlayer mp) {
                        vidView.start();
        }
    });

I found that the listener was firing, the issue was mp.start() didn't seem to do anything, so calling start again on the original object seems to be working fine.

in your onCompletion listener, try using videoView.start(); instead of mp.start();

Make sure you are using the player on the main thread, it seems the callback only works on the main thread.

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