public static void enterFullScreenVideo( int layerId, String url, HTML5VideoViewProxy proxy, WebViewClassic webView) { // Save the inline video info and inherit it in the full screen int savePosition = 0; boolean canSkipPrepare = false; boolean forceStart = false; if (mHTML5VideoView != null) { // We don't allow enter full screen mode while the previous // full screen video hasn't finished yet. if (!mHTML5VideoView.fullScreenExited() && mHTML5VideoView.isFullScreenMode()) { Log.w(LOGTAG, "Try to reenter the full screen mode"); return; } int playerState = mHTML5VideoView.getCurrentState(); // If we are playing the same video, then it is better to // save the current position. if (layerId == mHTML5VideoView.getVideoLayerId()) { savePosition = mHTML5VideoView.getCurrentPosition(); canSkipPrepare = (playerState == HTML5VideoView.STATE_PREPARING || playerState == HTML5VideoView.STATE_PREPARED || playerState == HTML5VideoView.STATE_PLAYING) && !mHTML5VideoView.isFullScreenMode(); } if (!canSkipPrepare) { mHTML5VideoView.reset(); } else { forceStart = playerState == HTML5VideoView.STATE_PREPARING || playerState == HTML5VideoView.STATE_PLAYING; } } mHTML5VideoView = new HTML5VideoFullScreen(proxy.getContext(), layerId, savePosition, canSkipPrepare); mHTML5VideoView.setStartWhenPrepared(forceStart); mCurrentProxy = proxy; mHTML5VideoView.setVideoURI(url, mCurrentProxy); mHTML5VideoView.enterFullScreenVideoState(layerId, proxy, webView); }
// This is on the UI thread. // When native tell Java to play, we need to check whether or not it is // still the same video by using videoLayerId and treat it differently. public static void play( String url, int time, HTML5VideoViewProxy proxy, WebChromeClient client, int videoLayerId) { int currentVideoLayerId = -1; boolean backFromFullScreenMode = false; if (mHTML5VideoView != null) { currentVideoLayerId = mHTML5VideoView.getVideoLayerId(); backFromFullScreenMode = mHTML5VideoView.fullScreenExited(); // When playing video back to back in full screen mode, // javascript will switch the src and call play. // In this case, we can just reuse the same full screen view, // and play the video after prepared. if (mHTML5VideoView.isFullScreenMode() && !backFromFullScreenMode && currentVideoLayerId != videoLayerId && mCurrentProxy != proxy) { mCurrentProxy = proxy; mHTML5VideoView.setStartWhenPrepared(true); mHTML5VideoView.setVideoURI(url, proxy); mHTML5VideoView.reprepareData(proxy); return; } } boolean skipPrepare = false; boolean createInlineView = false; if (backFromFullScreenMode && currentVideoLayerId == videoLayerId && !mHTML5VideoView.isReleased()) { skipPrepare = true; createInlineView = true; } else if (backFromFullScreenMode || currentVideoLayerId != videoLayerId || HTML5VideoInline.surfaceTextureDeleted()) { // Here, we handle the case when switching to a new video, // either inside a WebView or across WebViews // For switching videos within a WebView or across the WebView, // we need to pause the old one and re-create a new media player // inside the HTML5VideoView. if (mHTML5VideoView != null) { if (!backFromFullScreenMode) { mHTML5VideoView.pauseAndDispatch(mCurrentProxy); } mHTML5VideoView.reset(); } createInlineView = true; } if (createInlineView) { Xlog.d(XLOGTAG, "creating video inline"); mCurrentProxy = proxy; mHTML5VideoView = new HTML5VideoInline(videoLayerId, time, skipPrepare); mHTML5VideoView.setVideoURI(url, mCurrentProxy); mHTML5VideoView.prepareDataAndDisplayMode(proxy); return; } if (mCurrentProxy == proxy) { // Here, we handle the case when we keep playing with one video if (!mHTML5VideoView.isPlaying()) { mHTML5VideoView.seekTo(time); mHTML5VideoView.start(); } } else if (mCurrentProxy != null) { // Some other video is already playing. Notify the caller that // its playback ended. proxy.dispatchOnEnded(); } }