Youtube controls (play / pause) do not work after restoring the player / activity resumes

I have activity with YouTubePlayerSupportFragment inside it to play youtube video.

The style of the YouTube player is set to CHROMELESS (video only, no control), and playback is controlled by my own play / pause button outside of the player. Each thing works as expected, until the moment when I leave the video activity for some reason, and then return to it.

When an action is exited, the video pauses - as expected, but after returning to it, the request to player player.play() does nothing. No errors and exceptions, he just does nothing. Play() will only work after loading a new video.

I am trying to use YouTubePlayerFragment instead, but the result is the same. However, when using the DEFAULT style, pressing the default play button will apparently reload the video (I see that the buffer is clearing) from the previous position and work as expected. This makes me believe that they are processing it somehow directly on their user interface control code, and not on the player’s API.

I can reproduce this problem on a sample of custom SDK controls by simply starting the video by pressing the recents key and returning to it, so I find it safe to assume that this is a mistake. Has anyone been able to work around this problem? is there any way to detect that the video needs to be reloaded before it is fixed?

Info: I am using the YouTube player API for Android v1.2.2 and the latest youtube v10.49.59 application

+6
source share
1 answer

After several hours, the only solution I found was to save the video position on the Pause event and reload the video (player.loadVideo) in the PostResume event (when YouTubeFragment resumes). But I do not know if this is the only / best solution.

0
source

All Articles