viewPager
中我的多个YouTube视频覆盖了自己,youtubePlayer在一秒钟录制后停止播放。我的第一个视频工作正常,但每当我滑到另一个视频或回到上一个视频并尝试录制它时,我会给出一个重叠错误。我尝试将videoContainer设置为gone
,释放youtube播放器,bringToFront()
当前videoContainer,hide
/ show
detach
/ attach
videoFragment和问题仍然存在。分离/附加片段解决方案有效但不是每次都有效。
我的警告信息:YouTube video playback stopped due to unauthorized overlay on top of player. The YouTubePlayerView is obscured by android.widget.LinearLayout{54f27e3 V.E...... ........ 0,0-1080,1584 #7f1000ec app:id/globalViewLinearLayout}. Right edge 50 px right of YouTubePlayerView's left edge.
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);
}
编辑:我发现了问题所在:Zoom-out page transformer覆盖了视频。