MediaPlayer에 대한 활동이 있고 그 활동에서 다른 활동 (예 : Chromecast 컨트롤러 활동 또는 ShareActionProvider 사용)을 시작하고 MediaPlayer로 활동으로 돌아올 때마다 다음 IllegalStateException이 발생합니다. :MediaPlayer가 포함 된 활동으로 돌아 오는 경우 IllegalStateException이 발생합니다.
11-13 15:48:33.083 22342-22342/com.iosharp.android.ssplayer E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException
at android.media.MediaPlayer._setVideoSurface(Native Method)
at android.media.MediaPlayer.setDisplay(MediaPlayer.java:733)
at com.iosharp.android.ssplayer.videoplayer.VideoActivity.surfaceCreated(VideoActivity.java:126)
at android.view.SurfaceView.updateWindow(SurfaceView.java:610)
at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:239)
at android.view.View.dispatchWindowVisibilityChanged(View.java:8170)
설명서를 읽으면 setDisplay()를 모든 상태에서 호출 할 수 있습니다. 아래
내 관련 코드 :
public class VideoActivity extends ActionBarActivity implements SurfaceHolder.Callback, MediaPlayer.OnPreparedListener,
VideoControllerView.MediaPlayerControl, MediaPlayer.OnErrorListener {
private SurfaceView mSurfaceView;
private MediaPlayer mPlayer;
private VideoControllerView mController;
private String mURL;
private SurfaceHolder mSurfaceHolder;
private VideoCastManager mCastManager;
private MediaInfo mSelectedMedia;
private IVideoCastConsumer mVideoCastConsumer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mCastManager = CastApplication.getCastManager(this);
setContentView(R.layout.activity_video);
mSurfaceView = (SurfaceView) findViewById(R.id.videoSurface);
setupActionBar();
setupCastListeners();
Bundle b = getIntent().getExtras();
if (b != null) {
mSelectedMedia = Utils.toMediaInfo(getIntent().getBundleExtra("media"));
mURL = mSelectedMedia.getContentId();
mSurfaceHolder = mSurfaceView.getHolder();
mSurfaceHolder.addCallback(this);
mPlayer = new MediaPlayer();
mController = new VideoControllerView(this, false);
}
}
@Override
protected void onResume() {
super.onResume();
setupLocalPlayback();
if (mCastManager != null) {
mCastManager.incrementUiCounter();
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
mController.show();
showActionBar();
return false;
}
@Override
public void onBackPressed() {
super.onBackPressed();
// Hide to prevent illegal state exception of getCurrentPosition
mController.hide();
if (mPlayer != null) {
mPlayer.reset();
}
}
@Override
protected void onPause() {
super.onPause();
mController.hide();
mPlayer.release();
if (mCastManager != null) {
mCastManager.decrementUiCounter();
}
}
를 초기화 것 확인하기 위해 같은 확인)합니다 (bundle.getExtras 위
를 넣어 Player) 대신에'onPause()'의'mPlayer.release()'를'mPlayer.reset()'으로 대체했습니다. – aaearon