我正在为youtube视频进行直播。通过以图片模式进入图片,播放器会以错误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.meetappeventgo", 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)
{
}
}
}
我正在oninitializedsuccess上加载视频,并在on Loaded上播放视频。我已经尝试了所有可能的解决方案,因此youtube播放器视图的顶部没有视图,但是它总是给我同样的错误。
我认为问题出在您的OnPictureInPictureModeChanged
方法上。.>
public override void OnPictureInPictureModeChanged(bool isInPictureInPictureMode, Configuration newConfig) { base.OnPictureInPictureModeChanged(isInPictureInPictureMode, newConfig); if (IsInPictureInPictureMode) { youtubevideo.Release(); Window.AddFlags(WindowManagerFlags.Fullscreen); } }
我在这里看到为什么弹出错误
UNAUTHORIZED_OVERLAY
的原因是在PIP模式下您的AddFlags呼叫。
如下修改您的代码,并检查错误是否仍然存在。
@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. ... } }
关于您的addflags调用,请尝试以下代码:
@Override public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) { super.onPictureInPictureModeChanged(isInPictureInPictureMode); if (!isInPictureInPictureMode) { getApplication().startActivity(new Intent(this, getClass()) .addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)); } }
而且我也没有从您发布的代码块中获得
youtubevideo.Release();
行的含义?