在将画中画模式应用于 YouTube 播放器视图并运行应用程序时,当我进入画中画模式时,YouTube 播放器中的视频播放暂停并且由于画中画自己的布局而无法单击播放按钮。当我从同一时间进入画中画模式时,如何继续播放视频?
这是我的代码:-
`public class Video extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {
YouTubePlayerView playerView;
YouTubePlayer.OnInitializedListener onInitializedListener;
Button pip_button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
pip_button = findViewById(R.id.pip_button);
pip_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (android.os.Build.VERSION.SDK_INT >= 26) {
//Trigger PiP mode
try {
Rational rational = new Rational(playerView.getWidth(), playerView.getHeight());
PictureInPictureParams mParams =
new PictureInPictureParams.Builder()
.setAspectRatio(rational)
.build();
enterPictureInPictureMode(mParams);
} catch (IllegalStateException e) {
e.printStackTrace();
}
} else {
Toast.makeText(Video.this, "API 26 needed to perform PiP", Toast.LENGTH_SHORT).show();
}
}
});
playerView = findViewById(R.id.playerview);
playerView.initialize("api_key", this);
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
youTubePlayer.cueVideo(videoID);
youTubePlayer.play();
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
Toast.makeText(this, "Something Went Wrong! Please Try Again!", Toast.LENGTH_LONG).show();
}
@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
onInitializedListener = new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
youTubePlayer.cueVideo(videoID);
youTubePlayer.pause();
youTubePlayer.play();
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
}
};
}