android監聽視訊播放結束
阿新 • • 發佈:2019-01-02
android監聽視訊是否播放結束,今天做的專案是在一個主介面中插入一個播放器,所以不是單純的視訊app,以前用的方法是:
mvideoview.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
//your code
}
});
但今天一直報錯:
Caused by: java.lang.ClassCastException: com.example.vitamio_test.MainActivity cannot be cast to io.vov.vitamio.MediaPlayer$OnCompletionListener
The method setOnCompletionListener(MediaPlayer.OnCompletionListener) in the type VideoView is not applicable for the arguments (new MediaPlayer.OnCompletionListener(){})
不知道是更新了還是怎麼了,這個MediaPlayer一定要有,不然會報型別轉換錯誤,完整的如下:
mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mp.seekTo(0);//迴圈播放 mp.start(); } });