I try to play multiple videos in loop using MediaPlayer (Android ICS) and change the videos each time when oncompletion() called.
It works great but after a random time the application freeze and I get the error :
[SurfaceView] connect : already connected (cur=3, req=3) setVideoSurfaceTexture failed : -22
When this error happen, internally it call the reset player
ref : mediaplayer.cpp
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;
}
as per my code i get the notification for onprepared() and start playing.
Actually there is no playback due to this err.
So i try to reset the mediaplayer and call prepare() when this problem happened and mediaplayer is not playing, but i am not able to capture this bug ( mp.isPlaying()->true (bec'z called start() in onprepared()).
i try the logic like
onprepared() {
mp.start();
if (pbm : [SurfaceView] connect : already connected (cur=3, req=3)
setVideoSurfaceTexture failed : -22 ) {
reset the mediaplayer source and call prepare
}
}
how can i locate this bug to restart the mediaplayer again?
we can avoid this problem by the following way...
mediaPlayer.setDisplay(null);
mediaPlayer.reset();
after this set the surfaceholder again before start the mediaplayer
mediaPlayer.setDisplay(surfaceHolder1);
mediaPlayer.start(); in onprepared notification.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With