// Every time webView setBaseLayer, this will be called. // When we found the Video layer, then we set the Surface Texture to it. // Otherwise, we may want to delete the Surface Texture to save memory. public static void setBaseLayer(int layer) { // Don't do this for full screen mode. if (mHTML5VideoView != null && !mHTML5VideoView.isFullScreenMode() && !mHTML5VideoView.isReleased()) { int currentVideoLayerId = mHTML5VideoView.getVideoLayerId(); SurfaceTexture surfTexture = HTML5VideoInline.getSurfaceTexture(currentVideoLayerId); int textureName = mHTML5VideoView.getTextureName(); if (layer != 0 && surfTexture != null && currentVideoLayerId != -1) { int playerState = mHTML5VideoView.getCurrentState(); if (mHTML5VideoView.getPlayerBuffering()) playerState = HTML5VideoView.STATE_PREPARING; boolean foundInTree = nativeSendSurfaceTexture( surfTexture, layer, currentVideoLayerId, textureName, playerState); if (playerState >= HTML5VideoView.STATE_PREPARED && !foundInTree) { mHTML5VideoView.pauseAndDispatch(mCurrentProxy); } } } }
// 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(); } }