【问题标题】:How to Add Picture-In-Picture mode onTouch Drag Down如何在触摸下拉下添加画中画模式
【发布时间】:2019-06-08 04:22:36
【问题描述】:

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

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

【问题讨论】:

    标签: android android-youtube-api android-picture-in-picture


    【解决方案1】:

    浏览this GitHub 链接,它完全符合您的 DragDown 视频标准...

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

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

    希望对你有所帮助...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-16
      • 2018-01-16
      • 1970-01-01
      • 1970-01-01
      • 2020-09-26
      • 1970-01-01
      • 2019-09-21
      • 2018-11-09
      相关资源
      最近更新 更多