我正在为 youtube 视频进行直播。通过进入画中画模式,播放器会使用错误UNAUTHORIZED_OVERLAY暂停视频。
视频布局.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"/>
活动.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)
{
}
}
}
我在 oninitializedsuccess 上加载视频并在 onLoaded 中播放视频。我已经尝试了所有可能的解决方案,因此 youtube 播放器视图顶部没有视图,但它总是给我同样的错误。