Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在查看页面中覆盖youtube Api视频_Android_Android Fragments_Youtube_Android Viewpager_Overlay - Fatal编程技术网

Android 在查看页面中覆盖youtube Api视频

Android 在查看页面中覆盖youtube Api视频,android,android-fragments,youtube,android-viewpager,overlay,Android,Android Fragments,Youtube,Android Viewpager,Overlay,我的多个youtube视频在viewPager中覆盖,youtubePlayer在录制一秒钟后停止。我的第一个视频工作正常,但每当我滑到另一个或回到上一个,并试图记录它,我会给出一个覆盖错误。我尝试将videoContainer设置为gone,释放youtube播放器,bringToFront()当前的videoContainer,hide/show分离/附加视频片段,问题仍然存在。分离/附加片段解决方案有效,但并非每次都有效 我的警告消息:YouTube视频播放已停止,因为未经授权的覆盖在播放

我的多个youtube视频在
viewPager
中覆盖,youtubePlayer在录制一秒钟后停止。我的第一个视频工作正常,但每当我滑到另一个或回到上一个,并试图记录它,我会给出一个覆盖错误。我尝试将videoContainer设置为
gone
,释放youtube播放器,
bringToFront()
当前的videoContainer,
hide
/
show
分离
/
附加
视频片段,问题仍然存在。分离/附加片段解决方案有效,但并非每次都有效

我的警告消息:
YouTube视频播放已停止,因为未经授权的覆盖在播放器顶部。YouTubePlayerView被android.widget.LinearLayout{54f27e3 V.E……..0,0-10801584#7f1000ec应用程序:id/globalViewLinearLayout}模糊了。右边缘YouTubePlayerView左边缘右侧50像素。

My FragmentViewPagerItemXML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:id="@+id/globalViewLinearLayout">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/backgroundContent">

        <com.app.CustomScrollView
        android:id="@+id/customScrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/scrollViewLinearLayout">


            <FrameLayout
                android:id="@+id/mediaContainer"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/transparent"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="220dp"
                    android:layout_marginBottom="80dp"
                    android:visibility="gone"
                    android:id="@+id/videoContainerLayout">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="200dp"
                        android:id="@+id/videoContainer"
                        android:orientation="vertical" />
                </LinearLayout>
        <RelativeLayout
            android:layout_marginTop="5dp"
            android:layout_width="match_parent"
            android:layout_height="@dimen/imageHeight"
            android:id="@+id/galleryContainer"
            android:layout_marginBottom="55dp">

            <ProgressBar
                android:id="@+id/progress"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_centerInParent="true" />

            <RelativeLayout
                android:id="@+id/photoWithButtonsContainer"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:background="@color/black">

               <ImageView

                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:id="@+id/themePhoto"
                   android:clickable="true"
                   android:adjustViewBounds="true"
                   android:padding="10dp"
                   android:background="@android:color/white"
                   android:layout_centerInParent="true"
                   android:visibility="gone" />
               <ImageButton
                   android:layout_alignRight="@+id/themePhoto"
                   android:layout_alignTop="@+id/themePhoto"
                   android:adjustViewBounds="true"
                   android:scaleType="fitCenter"
                   android:layout_margin="8dp"
                   android:layout_width="35dp"
                   android:layout_height="35dp"
                   android:background="@drawable/expand"
                   android:id="@+id/zoomMe"
                   android:visibility="gone" />

            </RelativeLayout>

        </RelativeLayout>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="25dp"
                    android:layout_gravity="bottom|right"
                    android:id="@+id/buttonLinearLayout">

                    <android.support.design.widget.FloatingActionButton
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        android:id="@+id/playButton"
                        android:src="@drawable/ic_play_arrow_black_48dp"
                        app:backgroundTint="@color/white"
                        android:layout_marginRight="15dp"
                        android:layout_marginEnd="15dp"
                        android:visibility="gone" />

                    <android.support.design.widget.FloatingActionButton
                        app:backgroundTint="@color/white"
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        android:id="@+id/videoButton"
                        android:layout_marginRight="15dp"
                        android:layout_marginEnd="15dp"
                        android:src="@drawable/ic_ondemand_video_black_48dp"
                        android:visibility="gone" />
                </LinearLayout>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_gravity="bottom|left"
                    android:layout_marginLeft="5dp"
                    android:layout_marginStart="5dp"
                    android:layout_height="85dp"
                    android:background="@drawable/ribbon"
                    android:id="@+id/artWorkCounter"
                    android:textColor="@color/white"
                    android:textSize="12sp"
                    android:textStyle="bold"
                    android:gravity="center"
                    android:paddingLeft="2dp"
                    android:paddingRight="2dp" />
            </FrameLayout>

编辑:我发现了问题所在:视频的覆盖层

你解决了吗?你解决了吗?
 public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {

    videoContainer = (LinearLayout) view.findViewById(R.id.videoContainerLayout);
   mYouTubePlayerFragment = YouTubePlayerSupportFragment.newInstance();
  return view;
  }


  viewHolder.videoButton = (FloatingActionButton) view.findViewById(R.id.videoButton);
            viewHolder.videoButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view1) {
                    if (view.findViewById(R.id.videoContainer).isShown()) {
                         animateFab(false);

        videoContainer.setVisibility(View.GONE);
                    } else {


                        if (context instanceof TestActivity)
                            ((TestActivity) context).setAutoOrientationEnabled(true);
                        youTubeVideoInit(artWork.getVideo_uri(), view);
                        animateFab(true);
                    }
                }
            });
@Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (viewHolder != null) {
            if (!isVisibleToUser ) {

                isVisible = false;
                if (videoContainer != null)
                    if (videoContainer.isShown()) {
                        viewHolder.videoButton.performClick();
                    }
                    if(mYouTubePlayerFragment!=null)
                    getChildFragmentManager().beginTransaction().detach(mYouTubePlayerFragment).commitAllowingStateLoss();
            } else {
                if(mYouTubePlayerFragment!=null)
                    getChildFragmentManager().beginTransaction().attach(mYouTubePlayerFragment).commitAllowingStateLoss();
                isVisible = true;
            }
        }
    }
   YouTubePlayer mPlayer;
    YouTubePlayerSupportFragment mYouTubePlayerFragment;
    String youtubeID;
    LinearLayout videoContainer;

    public void youTubeVideoInit(String youtubeUrl, final View view) {

        final String API_KEY = getString(R.string.develop_key);


        Uri uri = Uri.parse(youtubeUrl);
        try {
            youtubeID = URLDecoder.decode(uri.getQueryParameter("v"), "UTF-8");
        } catch (UnsupportedEncodingException exception) {
            exception.printStackTrace();
        }


        mYouTubePlayerFragment.initialize(API_KEY, new YouTubePlayer.OnInitializedListener() {
            @Override
            public void onInitializationSuccess(YouTubePlayer.Provider provider, final YouTubePlayer youTubePlayer, boolean isRejected) {
                if (!isRejected) {
                    mPlayer = youTubePlayer;
                    mPlayer.cueVideo(youtubeID);
                    mPlayer.setOnFullscreenListener(new YouTubePlayer.OnFullscreenListener() {
                        @Override
                        public void onFullscreen(boolean b) {
                            if (!b && context instanceof TestActivity){
                                ((TestActivity) context).setPortraitOrientation();
                                ((TestActivity) context).setAutoOrientationEnabled(true);
                            }
                        }
                    });
                }
            }

            @Override
            public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {

            }
        });

        getChildFragmentManager().beginTransaction().replace(R.id.videoContainer, mYouTubePlayerFragment, YouTubePlayerFragment.class.getSimpleName()).commit();
      videoContainer.setVisibility(View.VISIBLE);
}