Reputation:
I have issue with youtube player view in android.
its show bellow error when its play some time it's play then suddenly its stop. And show bellow error.
YouTube video playback stopped because the player's view is not visible.
The view com.android.internal.policy.impl.PhoneWindow$DecorView
{36d050c2 I.E..... R.....ID 0,0-540,960} has visibility "INVISIBLE".
Tell me what can i do for this error.??
My Activity code is here.
youTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtube_player);
youTubePlayerView.initialize(GOOGLE_API_KEY, this);
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider,
YouTubePlayer youTubePlayer, boolean wasRestored) {
myYouTubePlayer = youTubePlayer;
// Change play style
youTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT);
youTubePlayer
.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_SYSTEM_UI);
youTubePlayer.setPlayerStateChangeListener(this);
youTubePlayer.setPlaybackEventListener(this);
youTubePlayer.loadVideo("wKJ9KzGQq0w");
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider,
YouTubeInitializationResult errorReason) {
if (errorReason.isUserRecoverableError()) {
errorReason.getErrorDialog(this, RECOVERY_DIALOG_REQUEST).show();
} else {
String errorMessage = String.format(
"There was an error initializing the YouTubePlayer (%1$s)",
errorReason.toString());
Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
}
}
My XML file code is here.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rl_FullScreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000" >
<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/youtube_player"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/rl_CurrentVideoDetails"
android:layout_below="@+id/rl_Heading"
android:layout_toStartOf="@+id/rl_ChannelChange"
android:background="#000" />
<RelativeLayout
android:id="@+id/rl_Heading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
<ImageView
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="12dp"
android:contentDescription="@null"
android:padding="8dp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_ChannelChange"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:background="@color/transparent_background_black"
android:gravity="center_horizontal" >
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_above="@+id/ll_ChNo"
android:layout_marginBottom="16dp"
android:contentDescription="@null"
android:padding="8dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@null"
android:gravity="center"
android:padding="4dp"
android:text="Ch."
android:textSize="16sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@null"
android:gravity="center"
android:padding="4dp"
android:text="123"
android:textSize="16sp" />
</LinearLayout>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_below="@+id/ll_ChNo"
android:layout_marginTop="16dp"
android:contentDescription="@null"
android:padding="8dp"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_CurrentVideoDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true"
android:background="@color/transparent_background_black"
android:paddingStart="12dp" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="6dp"
android:singleLine="true"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_CurrentVideoName"
android:orientation="horizontal"
android:padding="6dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:textAllCaps="true"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="| Ch. "
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="4dp"
android:singleLine="true"
android:textAllCaps="true" />
</LinearLayout>
<ImageView
android:id="@+id/iv_NormalScreen"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:contentDescription="@null"
android:padding="10dp" />
</RelativeLayout>
Upvotes: 1
Views: 1884
Reputation: 578
Can you check if your Youtube App has been update last September or later? It seems there is a bug in Youtube App, that causes this estrange error when using Youtube API:
https://code.google.com/p/gdata-issues/issues/detail?id=7586
You can check if this error is caused by Youtube App easily, removing Youtube App updates and testing your app. You can remove an this app updates going to Settings > General > Apps > Youtube and click in Uninstall Updates button.
For me, this was the reason my app youtube videos not working well. When I uninstall updates my app works, when I reinstall updates my app crash again. So, I think the only solution is wait for new update :(
Hopefully this helps!
Upvotes: 1
Reputation: 13548
YouTube video playback stopped because the player's view is not visible.
Nothing should overlap the YouTubePlayerView
(as required by Google's policy). This means that you need to consider the z-index and/or overlapping of all the views in your hierarchy.
In your case, the order of the elements in the XML files determines the z-index and there's a match_parent layout which overlaps the YouTubePlayerView
: you need to bring the YouTubePlayerView
to front, just move it as last item in your layout:
<RelativeLayout
android:id="@+id/rl_Heading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
<ImageView
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="12dp"
android:contentDescription="@null"
android:padding="8dp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_ChannelChange"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:background="@color/transparent_background_black"
android:gravity="center_horizontal" >
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_above="@+id/ll_ChNo"
android:layout_marginBottom="16dp"
android:contentDescription="@null"
android:padding="8dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@null"
android:gravity="center"
android:padding="4dp"
android:text="Ch."
android:textSize="16sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@null"
android:gravity="center"
android:padding="4dp"
android:text="123"
android:textSize="16sp" />
</LinearLayout>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_below="@+id/ll_ChNo"
android:layout_marginTop="16dp"
android:contentDescription="@null"
android:padding="8dp"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_CurrentVideoDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true"
android:background="@color/transparent_background_black"
android:paddingStart="12dp" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="6dp"
android:singleLine="true"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_CurrentVideoName"
android:orientation="horizontal"
android:padding="6dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:textAllCaps="true"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="| Ch. "
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="4dp"
android:singleLine="true"
android:textAllCaps="true" />
</LinearLayout>
<ImageView
android:id="@+id/iv_NormalScreen"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:contentDescription="@null"
android:padding="10dp" />
</RelativeLayout>
<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/youtube_player"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/rl_CurrentVideoDetails"
android:layout_below="@+id/rl_Heading"
android:layout_toStartOf="@+id/rl_ChannelChange"
android:background="#000" />
Upvotes: 0
Reputation: 299
I was having the same issue on my app last night and eventually found a solution (for me at least). It appears there was always an issue in my app, I was accidentally launching the same intent to my YoutubePlayerActivity multiple times.
Previously, this went un-noticed by myself - however the recent Youtube update must have increased the restriction or changed the way it works as I then got this error.
I went through my code and found that when I add fragments, it was re-calling onCreateView of every fragment. Meaning for all three fragments added, I eventually called the intent three times.
Hopefully this helps.
Upvotes: 2