Exemplo n.º 1
0
 /// M: fix teardown when preparing issue @{
 public static void teardown() {
   if (mHTML5VideoView != null) {
     mHTML5VideoView.pause(); // also stop timer.
     mHTML5VideoView.release(); // release player
     mHTML5VideoView = null;
   }
 }
Exemplo n.º 2
0
 public static void exitFullScreenVideo(HTML5VideoViewProxy proxy, WebViewClassic webView) {
   if (!mHTML5VideoView.fullScreenExited() && mHTML5VideoView.isFullScreenMode()) {
     WebChromeClient client = webView.getWebChromeClient();
     if (client != null) {
       client.onHideCustomView();
     }
   }
 }
Exemplo n.º 3
0
 /// M: set volume /mute @{
 public static void setVolume(float volume) {
   if (mHTML5VideoView != null) {
     mHTML5VideoView.setVolume(volume);
   } else {
     Log.w(LOGTAG, "HTML5VideoView is null, skip setting volume");
   }
 }
Exemplo n.º 4
0
 public static int getCurrentPosition() {
   int currentPosMs = 0;
   if (mHTML5VideoView != null) {
     currentPosMs = mHTML5VideoView.getCurrentPosition();
   }
   return currentPosMs;
 }
Exemplo n.º 5
0
 // When a WebView is paused, we also want to pause the video in it.
 public static void pauseAndDispatch() {
   Xlog.d(XLOGTAG, "HTML5VideoViewProxy.pauseAndDispatch()");
   Xlog.d(XLOGTAG, "stack:" + Thread.currentThread().getStackTrace());
   if (mHTML5VideoView != null) {
     mHTML5VideoView.pauseAndDispatch(mCurrentProxy);
   }
 }
Exemplo n.º 6
0
 private static void setPlayerBuffering(boolean playerBuffering) {
   /// M: TEARDOWN message handled before BUFFERING_START message lead to mHTML5VideoView is
   // null. @ {
   if (mHTML5VideoView != null) {
     mHTML5VideoView.setPlayerBuffering(playerBuffering);
   } else {
     Xlog.w(LOGTAG, "HTML5VideoView is null, skip setPlayerBuffering");
   }
   /// @ }
 }
Exemplo n.º 7
0
 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);
 }
Exemplo n.º 8
0
 public static void end() {
   /// M: TEARDOWN message handled before ENDED message lead to mHTML5VideoView is null. @ {
   if (mHTML5VideoView != null) {
     mHTML5VideoView.showControllerInFullScreen();
   } else {
     Xlog.w(LOGTAG, "HTML5VideoView is null, skip showControllerInFullScreen");
   }
   /// @ }
   if (mCurrentProxy != null) {
     if (isVideoSelfEnded) mCurrentProxy.dispatchOnEnded();
     else mCurrentProxy.dispatchOnPaused();
   }
   isVideoSelfEnded = false;
 }
Exemplo n.º 9
0
    // 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);
          }
        }
      }
    }
Exemplo n.º 10
0
 public static void onPrepared() {
   if (!mHTML5VideoView.isFullScreenMode()) {
     mHTML5VideoView.start();
   }
 }
Exemplo n.º 11
0
 public static void pause(HTML5VideoViewProxy proxy) {
   if (mCurrentProxy == proxy && mHTML5VideoView != null) {
     mHTML5VideoView.pause();
   }
 }
Exemplo n.º 12
0
 public static void seek(int time, HTML5VideoViewProxy proxy) {
   if (mCurrentProxy == proxy && time >= 0 && mHTML5VideoView != null) {
     mHTML5VideoView.seekTo(time);
   }
 }
Exemplo n.º 13
0
 public static boolean isPlaying(HTML5VideoViewProxy proxy) {
   return (mCurrentProxy == proxy && mHTML5VideoView != null && mHTML5VideoView.isPlaying());
 }
Exemplo n.º 14
0
    // 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();
      }
    }