Reputation: 101
I'm making an app that uses the YouTube API to play YouTube videos. When I go into full screen mode, I switch the player style to CHROMELESS because I want to create my own set of media controls.
I have developed a set of gestures that map to changing volume, brightness, and seeking. When these changes occur, a progress bar pops up over the video showing the user their changes in real time. I have placed all my Views in a single FrameLayout in order to get the progress bars to show up on screen when the player is fullscreen.
The problem is that (before I added volume control functionality) the video would automatically pause as soon as I entered fullscreen mode. I am handling orientation and screenSize changes myself. I noticed that it would pause roughly 2 seconds after my personally made seekbar would pop up.
So for testing, I altered my code by NOT changing the player style to CHROMELESS, that is, I left it as DEFAULT. I removed my seekbar as well and now the video worked fine; I could change brightness and play the video with no problem. During another test, I removed all instances of youtubePlayer.pause() from my code, left the seekbar in, and changed back to CHROMELESS. But the problem returned--so it must be something to do with the seekbar.
Now, however, I have added volume control functionality and when I run it (even when I'm not fullscreen) the player pauses almost immediately after I press play and it doesn't work at all afterwards.
Can anyone help me out? I'll add some of my code when I get back to my computer. I really appreciate your help.
Upvotes: 10
Views: 7739
Reputation: 1849
Remove paddings and margins in your Youtube Viewlayout
The problem is only with the layout, the YouTube Player doesn't permit any view staying over it, neither invisible nor transparent.
In order to make this visible in your device, enable layout bounds in developer option. (warning with paddings and margins)
OR
Use below code. I hope it's working
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Upvotes: 0
Reputation: 2380
For my case, I have the status bar in the player activity. Just set the acitivity with full screen style to fix the issue
Upvotes: 0
Reputation: 1738
I think your problem is due to your controls overlaying the player. Take a look at your logcat to verify.
As mentioned in the YouTubePlayerView JavaDoc, "it is not permitted to overlay the [player] view with other views while a video is playing".
Take a look at this question: Views overlayed above YouTubePlayerFragment or YouTubePlayerView in the layout hierarchy cause playback to pause immediately
This problem can be easily solved using a library that I've build: Android-YouTube-Player. Other than being more stable than the official API this library gives you more freedom, eg. you can overlay whatever you want to your player.
Upvotes: 2
Reputation: 1529
If you want that youtube android player controls do not show after every two seconds. you have to true focusable in your layout.
<com.google.android.youtube.player.YouTubePlayerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/youtube_view"
android:focusable="true"
android:layout_height="match_parent"
android:layout_width="match_parent" />
Upvotes: 2
Reputation: 3608
Please check the logcat to identify your issue.
When i had the issue, it was because of UNAUTHORIZED_OVERLAY.
<RelativeLayout
android:id="@+id/parent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/scImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<FrameLayout
andriod:id"@+id/youtube_parent
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
The imageview was below the framelayout which had the youtube player. I moved it to the top (The final, fixed layout is the example above) and it started to work.(I tried setting the Zindex it didnt help).
Upvotes: 0
Reputation: 202
You can not Cover anyView on YoutubePlayView that should be clean. try the following
<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/player_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Upvotes: 2
Reputation: 1812
Following reasons are among the most common ones:
UNAUTHORIZED_OVERLAY - Other views overlapping with youtube view
PLAYER_VIEW_TOO_SMALL - Youtube view too small
USER_DECLINED_RESTRICTED_CONTENT - Trying to play restricted content
BLOCKED_FOR_APP - Certain videos are blocked for app.
You can read about these and other problems in detail at link
Upvotes: 13