我正在为我的应用使用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
答案 0 :(得分:0)
浏览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;
}
希望这对您有帮助...