Android setVideoSurfaceTexture失败:在mediaplayer中为-22
我尝试使用MediaPlayer(Android ICS)在循环中播放多个视频,并在每次调用oncompletion()时更改视频 它工作得很好,但在一段随机时间后,应用程序冻结,我得到了错误: [SurfaceView]连接:已连接(cur=3,req=3) setVideoSurfaceTexture失败:-22 当这个错误发生时,它会在内部调用重置播放器 参考:mediaplayer.cppAndroid setVideoSurfaceTexture失败:在mediaplayer中为-22,android,media-player,surfaceview,Android,Media Player,Surfaceview,我尝试使用MediaPlayer(Android ICS)在循环中播放多个视频,并在每次调用oncompletion()时更改视频 它工作得很好,但在一段随机时间后,应用程序冻结,我得到了错误: [SurfaceView]连接:已连接(cur=3,req=3) setVideoSurfaceTexture失败:-22 当这个错误发生时,它会在内部调用重置播放器 参考:mediaplayer.cpp if (err != OK) { LOGE("setVideoSurfaceTexture
if (err != OK) {
LOGE("setVideoSurfaceTexture failed: %d", err);
// Note that we must do the reset before disconnecting from the ANW.
// Otherwise queue/dequeue calls could be made on the disconnected
// ANW, which may result in errors.
reset();
disconnectNativeWindow();
return err;
}
根据我的代码,我收到onprepared()的通知并开始播放
由于这个错误,实际上没有播放
因此,当出现此问题且mediaplayer未播放时,我尝试重置mediaplayer并调用prepare(),但我无法捕获此错误(mp.isplay()->true(在onprepared()中bec'z调用start())
我尝试这样的逻辑
onprepared() {
mp.start();
if (pbm : [SurfaceView] connect : already connected (cur=3, req=3)
setVideoSurfaceTexture failed : -22 ) {
reset the mediaplayer source and call prepare
}
}
如何找到此错误以重新启动mediaplayer?我们可以通过以下方法避免此问题
mediaPlayer.setDisplay(null);
mediaPlayer.reset();
在此之后,在启动mediaplayer之前再次设置surfaceholder
mediaPlayer.setDisplay(surfaceHolder1);
mediaPlayer.start(); in onprepared notification.