Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Youtube API Player on Android Automatically pauses every 2 seconds

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.

like image 876
Takeshi Avatar asked Aug 26 '15 23:08

Takeshi


1 Answers

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.

like image 154
Pierfrancesco Soffritti Avatar answered Nov 16 '22 01:11

Pierfrancesco Soffritti