如何在触摸向下拖动时添加画中画模式

How to Add Picture-In-Picture mode onTouch Drag Down

我正在使用 this Github project 让我的应用程序使用 Youtube API 播放你的电子管视频。我的 onInitializationSuccess 方法中有以下代码..

 @Override
public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored) {
    this.player = player;
    player.setPlayerStateChangeListener(playerStateChangeListener);
    player.setPlaybackEventListener(playbackEventListener);

    if (!wasRestored) {
        player.cueVideo("I0D-fkypQQw");
    }
}

我将此 YouTubePlayerView 编码为以下列方式在 PIP 模式下播放:

enter_pip.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //  Intent i = new Intent(getBaseContext(), PipActivity.class);
            //  startActivity(i);
            if (android.os.Build.VERSION.SDK_INT >= 26) {
                //Trigger PiP mode
                try {
                    Rational rational = new Rational(youTubeView.getWidth(), youTubeView.getHeight());

                    PictureInPictureParams mParams =
                            new PictureInPictureParams.Builder()
                                    .setAspectRatio(rational)
                                    .build();

                    enterPictureInPictureMode(mParams);
                } catch (IllegalStateException e) {
                    e.printStackTrace();
                }
            } else {
                Toast.makeText(MainActivity.this, "API 26 needed to perform PiP", Toast.LENGTH_SHORT).show();
            }
        }

    });
}

视频成功进入画中画模式,但问题是进入画中画模式后视频停止,我希望它从不处于画中画模式时的位置继续..

请指导我添加画中画模式,其中画中画模式应该继续播放而不是停止。我正在寻找像 PIP 这样的 youtube,其中视频在底部播放 Play/Pause按钮和右侧的关闭按钮..
I am looking for a PIP as in this image

浏览 this GitHub Link 完全符合您的 DragDown 视频标准...

总结 github 项目... 使用goMin()方法代码..在YouTuDraggingView class中,如下所示:

    public void goMin(final boolean isDismissToMin) {
    nowStateScale = MIN_RATIO_HEIGHT;
    final float fullTop = Math.abs(mBackgroundViewWrapper.getMarginTop() - mRangeScrollY);
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(mBackgroundViewWrapper.getMarginTop(), mRangeScrollY);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float value = (float) animation.getAnimatedValue();
            mBackgroundView.setAlpha(isDismissToMin ? (value / fullTop) : 1);
            updateVideoView((int) value);
            if (value == mRangeScrollY) {
                ViewGroup.LayoutParams p = getLayoutParams();
                p.width = -2;
                p.height = -2;
                setLayoutParams(p);
                mCallback.status(STATUS_MIN);
            }
        }
    });
    valueAnimator.setDuration((long) (Math.abs((1 - mBackgroundViewWrapper.getMarginTop() / mRangeScrollY)) * rangeDuration)).start();
  }

和 goMax() 反转...

    public void goMax() {
    if (nowStateScale == MIN_RATIO_HEIGHT) {
        ViewGroup.LayoutParams params = getLayoutParams();
        params.width = -1;
        params.height = -1;
        setLayoutParams(params);
    }


    ValueAnimator valueAnimator = ValueAnimator.ofFloat(mBackgroundViewWrapper.getMarginTop(), 0);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float value = (float) animation.getAnimatedValue();

            updateVideoView((int) value);
            if (value == 0) {
                if (isLandscape()) {
                    goFullScreen();
                }
                mCallback.status(STATUS_MAX);
            }
        }
    });
    valueAnimator.setDuration((long) (mBackgroundViewWrapper.getMarginTop() / mRangeScrollY * rangeDuration)).start();

    nowStateScale = 1.0f;
  }

希望这对您有所帮助...