0

我正在为我的应用程序使用这个 Github 项目来使用 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 模式,但问题是视频在进入 PIP 模式后停止,我希望它从不处于 PIP 模式时的位置继续播放..

请指导我添加画中画模式,其中画中画模式应继续播放而不是停止。我正在寻找像 PIP 这样的 youtube,其中视频在底部播放,播放/暂停按钮和关闭按钮打开它是正确的..
我正在寻找一个 PIP,就像这张图片一样

4

1 回答 1

1

浏览这个完全符合您的 DragDown 视频标准的 GitHub 链接...

总结一下 github 项目...使用goMin()YouTuDraggingView 类中的方法代码..如下:

    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;
  }

希望对你有帮助...

于 2019-01-23T17:02:02.237 回答