在画中画模式 YoutubePlayer View Android 中输入图片时出现未授权叠加错误? [英] UnAuthorized Overlay Error on entering Picture in Picture mode YoutubePlayer View Android?

查看:27
本文介绍了在画中画模式 YoutubePlayer View Android 中输入图片时出现未授权叠加错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 youtube 视频进行直播.通过进入画中画模式,播放器暂停视频并显示错误 UNAUTHORIZED_OVERLAY .

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)
    {

    }
}

}

我正在 oninitializedsuccess 上加载视频并在 on Loaded 中播放视频.我已经尝试了所有可能的解决方案,因此 youtube 播放器视图顶部没有视图,但它总是给我同样的错误.

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.

推荐答案

我认为问题在于您的 OnPictureInPictureModeChanged 方法..

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);

    }

    }

我在这里看到错误 UNAUTHORIZED_OVERLAY 弹出的原因是您在 PIP 模式下的 AddFlags 调用..

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.
    ...
}
}

关于您的 addflags 调用,请尝试以下代码:

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));
}
}

这篇关于在画中画模式 YoutubePlayer View Android 中输入图片时出现未授权叠加错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆