@Override public void onSurfacesCreated(AWindow vout) { Log.d(TAG, "mWindow's onSurfacesCreated"); boolean play = false; boolean enableVideo = false; synchronized (MediaPlayer.this) { if (!mPlaying && mPlayRequested) play = true; else if (mVoutCount == 0) enableVideo = true; } if (play) play(); else if (enableVideo) setVideoTrackEnabled(true); }
@Override public void onSurfacesDestroyed(AWindow vout) { boolean disableVideo = false; synchronized (MediaPlayer.this) { if (mVoutCount > 0) disableVideo = true; } if (disableVideo) setVideoTrackEnabled(false); synchronized (MediaPlayer.this) { /* Wait for Vout destruction (mVoutCount = 0) in order to be sure that the surface is not * used after leaving this callback. This shouldn't be needed when using MediaCodec or * AndroidWindow (i.e. after Android 2.3) since the surface is ref-counted */ while (mVoutCount > 0) { try { MediaPlayer.this.wait(); } catch (InterruptedException ignored) { } } } }