我尝试使用 MediaPlayer (Android ICS) 循环播放 2 个视频并每次交换它们。
它工作得很好,但在随机时间后应用程序冻结并且我收到错误:
[SurfaceView] connect : already connected (cur=3, req=3)
setVideoSurfaceTexture failed : -22
这是我的代码:
public void onCreate(Bundle savedInstanceState) {
...
mMediaPlayer = new MediaPlayer();
try {
mMediaPlayer.setDataSource( currentPath );
mMediaPlayer.setDisplay(mPreview.getHolder());
mMediaPlayer.setOnBufferingUpdateListener(this);
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setOnVideoSizeChangedListener(this);
mMediaPlayer.setOnErrorListener(this);
mMediaPlayer.prepare();
} catch (Exception e) {
}
public void onPrepared(MediaPlayer mp) {
mp.start();
}
public void onCompletion(MediaPlayer mp) {
try {
mMediaPlayer.reset();
if (mCurrentPath == mPath1)
mCurrentPath = mPath2;
else
mCurrentPath = mPath1;
mMediaPlayer.setDataSource( mCurrentPath );
mMediaPlayer.prepare();
} catch (Exception e) {
}
}
有任何想法吗 ?