@Override
  public void onHideCustomView() {
    // This method should be manually called on video end in all cases because it's not always
    // called automatically.
    // This method must be manually called on back key press (from this class' onBackPressed()
    // method).

    if (isVideoFullscreen) {
      showActionBar();
      activityNonVideoView.setVideoPlaying(false);
      // Hide the video view, remove it, and show the non-video view
      ViewGroup activityVideoView =
          ((ViewGroup) MainActivity.webLayout.findViewById(R.id.webviewholder));
      activityVideoView.removeView(videoViewContainer);
      activityNonVideoView.setVisibility(View.VISIBLE);

      // Call back (only in API level <19, because in API level 19+ with chromium webview it
      // crashes)
      if (videoViewCallback != null
          && !videoViewCallback.getClass().getName().contains(".chromium.")) {
        videoViewCallback.onCustomViewHidden();
      }

      // Reset video related variables
      isVideoFullscreen = false;
      videoViewContainer = null;
      videoViewCallback = null;

      // Notify full-screen change
      if (toggledFullscreenCallback != null) {
        toggledFullscreenCallback.toggledFullscreen(false);
      }
    }
  }
 @Override
 public void onHideCustomView() {
   // This method must be manually (internally) called on video end in the case of VideoView
   // (typically API level <11)
   // This method must be manually (internally) called on video end in the case of
   // HTML5VideoFullScreen (typically API level 11+) because it's not always called automatically
   // This method must be manually (internally) called on back key press (from this class'
   // onBackPressed() method)
   if (isVideoFullscreen()) {
     // Hide the video view, remove it, and show the non-video view
     activityVideoView.setVisibility(View.GONE); // 播放视频的
     activityVideoView.removeView(videoViewContainer);
     activityNonVideoView.setVisibility(View.VISIBLE);
     ((Activity) activityNonVideoView.getContext())
         .setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // 强制当前页面在手机中竖屏
     // Call back
     if (videoViewCallback != null) videoViewCallback.onCustomViewHidden();
     // Reset video related variables
     isVideoFullscreen = false;
     videoViewContainer = null;
     videoViewCallback = null;
     // Notify full-screen change
     if (toggledFullscreenCallback != null) {
       toggledFullscreenCallback.toggledFullscreen(false);
     }
   }
 }
Exemplo n.º 3
0
 @Override
 public void onHideCustomView() {
   try {
     if (customView != null) {
       ViewParent viewparent = customView.getParent();
       if (viewparent != null) ((ViewGroup) viewparent).removeView(customView);
     }
     mCustomViewCallback.onCustomViewHidden();
   } catch (Exception e) {
     Log.e("WebViewActivity", "Can't remove custom view (video player)", e);
   }
 }
    @Override
    public void onShowCustomView(View view, CustomViewCallback callback) {

      // if a view already exists then immediately terminate the new one
      if (mCustomView != null) {
        callback.onCustomViewHidden();
        return;
      }
      mCustomView = view;
      webView.setVisibility(View.GONE);
      customViewContainer.setVisibility(View.VISIBLE);
      customViewContainer.addView(view);
      customViewCallback = callback;
    }
Exemplo n.º 5
0
    @Override
    public void onShowCustomView(View view, CustomViewCallback callback) {
      /*((Activity)getContext()).getWindow().addFlags(
      	WindowManager.LayoutParams.FLAG_FULLSCREEN
      );*/

      if (mCustomView != null) {
        callback.onCustomViewHidden();
      } else {
        mCustomView = view;
        mCustomViewCallback = callback;

        VideoView customVideoView =
            (mCustomView instanceof FrameLayout
                    && ((FrameLayout) mCustomView).getFocusedChild() instanceof VideoView)
                ? (VideoView) ((FrameLayout) mCustomView).getFocusedChild()
                : null;

        getDisplayController().showCustomView(mCustomView);

        if (customVideoView != null) {
          customVideoView.setOnCompletionListener(
              new OnCompletionListener() {
                public void onCompletion(MediaPlayer mp) {
                  mp.stop();
                  Log.d(LOGTAG, "onCompletion() fired");
                  onHideCustomView();
                }
              });
          customVideoView.setOnErrorListener(
              new OnErrorListener() {
                public boolean onError(MediaPlayer mp, int what, int extra) {
                  Log.e(LOGTAG, "Error in custom video, type " + what);
                  return true;
                }
              });
          // customVideoView.start();
        }
      }
    }
Exemplo n.º 6
0
  // Fullscreen playback
  @Override
  public void onShowCustomView(View view, CustomViewCallback callback) {
    if (mCustomView != null) {
      callback.onCustomViewHidden();
      return;
    }
    mCustomView = view;
    webView.loadUrl("javascript:(function() { document.body.style.overflowX = 'hidden'; })();");
    webView.loadUrl("javascript:(function() { window.scrollTo(0, 0); })();");
    drawerLayout.setVisibility(View.GONE);
    customViewContainer.setVisibility(View.VISIBLE);
    customViewContainer.addView(view);

    // Hide the status bar.
    decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      decorView.setSystemUiVisibility(
          View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
              | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_FULLSCREEN);
    }
  }
  @Override
  public void onShowCustomView(View view, CustomViewCallback callback) {
    Activity activity = mView.getActivity();

    if (mCustomView != null || activity == null) {
      callback.onCustomViewHidden();
      return;
    }

    mCustomView = view;
    mCustomViewCallback = callback;

    if ((activity.getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN)
        != 0) {
      mOriginalFullscreen = true;
    } else {
      mOriginalFullscreen = false;
    }

    // Set the activity to be fullscreen first.
    if (!mOriginalFullscreen) {
      activity
          .getWindow()
          .setFlags(
              WindowManager.LayoutParams.FLAG_FULLSCREEN,
              WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    // Add the video view to the activity's ContentView.
    activity
        .getWindow()
        .addContentView(
            view,
            new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT,
                Gravity.CENTER));
  }