public static void onPrepared() { if (!mHTML5VideoView.isFullScreenMode()) { mHTML5VideoView.start(); } }
// 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(); } }