问题
I am doing live streaming for the youtube videos. By entering into the picture in picture mode the player pause the video with the Error UNAUTHORIZED_OVERLAY .
VideoLayout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linear_youtube_rootlayout"
android:orientation="vertical"
android:background="@color/black"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/youtube_player"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
ACtivity.cs
[Activity(Label = "", ResizeableActivity = true, Theme = "@style/Theme.MyAppTheme", TaskAffinity = "com.m", MainLauncher =true,AllowTaskReparenting = true, AutoRemoveFromRecents = true, ExcludeFromRecents = true, LaunchMode = Android.Content.PM.LaunchMode.SingleTask, SupportsPictureInPicture = true/*, ConfigurationChanges = Android.Content.PM.ConfigChanges.ScreenSize | Android.Content.PM.ConfigChanges.SmallestScreenSize | Android.Content.PM.ConfigChanges.ScreenLayout | Android.Content.PM.ConfigChanges.Orientation*/)]
public class YoutubeActivity: YouTubeBaseActivity,IYouTubePlayerOnInitializedListener,View.IOnClickListener,IYouTubePlayerPlayerStateChangeListener,IYouTubePlayerPlaybackEventListener,IYouTubePlayerOnFullscreenListener
{
private YouTubePlayerView mYoutubePlayer;
private PictureInPictureParams.Builder pictureInPictureParamsBuilder =
new PictureInPictureParams.Builder();
private LinearLayout linear_rootlayout;
private TextView txtMinimizevideo,txtCloseVideo;
private IYouTubePlayer youtubevideo;
private bool isbackbuttonpress = false;
private RelativeLayout relative_youtubecontrols;
public void OnInitializationFailure(IYouTubePlayerProvider p0, YouTubeInitializationResult p1)
{
}
public void OnInitializationSuccess(IYouTubePlayerProvider provider, IYouTubePlayer player, bool p2)
{
this.youtubevideo = player;
// youtubevideo.SetPlayerStyle(YouTubePlayerPlayerStyle.Minimal);
youtubevideo.SetOnFullscreenListener(this);
youtubevideo.SetPlayerStateChangeListener(this);
youtubevideo.SetPlaybackEventListener(this);
youtubevideo.FullscreenControlFlags = YouTubePlayer.FullscreenFlagCustomLayout;
youtubevideo.LoadVideo("VideoKey");
}
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.youtube_player_layout);
mYoutubePlayer = FindViewById<YouTubePlayerView>(Resource.Id.youtube_player);
linear_rootlayout = FindViewById<LinearLayout>(Resource.Id.linear_youtube_rootlayout);
relative_youtubecontrols = FindViewById<RelativeLayout>(Resource.Id.rel_youtube_control);
mYoutubePlayer.Initialize("SerialKey", this);
}
public override void OnPictureInPictureModeChanged(bool isInPictureInPictureMode, Configuration newConfig)
{
base.OnPictureInPictureModeChanged(isInPictureInPictureMode, newConfig);
if (IsInPictureInPictureMode)
{
youtubevideo.Release();
Window.AddFlags(WindowManagerFlags.Fullscreen);
}
}
public override void OnBackPressed()
{
pictureInPictureMode();
}
protected override void OnUserLeaveHint()
{
base.OnUserLeaveHint();
if (!IsInPictureInPictureMode)
{
pictureInPictureMode();
}
}
private void pictureInPictureMode()
{
isbackbuttonpress = true;
Rational aspectRatio = new Rational(200, 110);
pictureInPictureParamsBuilder.SetAspectRatio(aspectRatio).Build();
EnterPictureInPictureMode(pictureInPictureParamsBuilder.Build());
}
public void OnBuffering(bool p0)
{
}
public void OnPaused()
{
}
public void OnPlaying()
{
}
public void OnSeekTo(int p0)
{
}
public void OnStopped()
{
// youtubevideo.Play();
}
public void OnAdStarted()
{
}
public void OnError(YouTubePlayerErrorReason p0)
{
}
public void OnLoaded(string p0)
{
youtubevideo.Play();
}
public void OnLoading()
{
}
public void OnVideoEnded()
{
}
public void OnVideoStarted()
{
}
public void OnFullscreen(bool p0)
{
}
}
}
I am loading the video on the oninitializedsuccess and play the video in the on Loaded. I have tried all the possible solutions so that no view is on the top of the youtube player view but it always gives me same error.
回答1:
I think the issue is with your OnPictureInPictureModeChanged
method..
public override void OnPictureInPictureModeChanged(bool isInPictureInPictureMode, Configuration newConfig)
{
base.OnPictureInPictureModeChanged(isInPictureInPictureMode, newConfig);
if (IsInPictureInPictureMode)
{
youtubevideo.Release();
Window.AddFlags(WindowManagerFlags.Fullscreen);
}
}
The reason I see here why the error UNAUTHORIZED_OVERLAY
pops up is your AddFlags Call when in PIP Mode..
Modify your code as below and check to see if the error persists..
@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
if (isInPictureInPictureMode) {
// Hide the controls in picture-in-picture mode.
...
} else {
// Restore the playback UI based on the playback status.
...
}
}
With regards to your addflags call, try the following code:
@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode);
if (!isInPictureInPictureMode) {
getApplication().startActivity(new Intent(this, getClass())
.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT));
}
}
来源:https://stackoverflow.com/questions/60808488/unauthorized-overlay-error-on-entering-picture-in-picture-mode-youtubeplayer-vie