This is an internal problem in the YouTube player and will be resolved in the next release, you can track this problem here:
https://issuetracker.google.com/issues/35172585
This exception occurred if YoutubePlayer was released.
According to the Youtube SDK Documentation Bugs:
public static final YouTubePlayer.ErrorReason UNEXPECTED_SERVICE_DISCONNECTION
Playback was canceled and the player was released due to an unexpected disconnection from the YouTube API service. Any additional calls to this player instance will lead to errors; a new player instance must be created to enable playback again.
So, to avoid this exception, you put your calls (e.g. youtubePlayer.loadVideo (), cueVideo (), getCurrentTimeMillis (), etc.) into a catch try block and caught an IllegalStateException exception.
To create a new instance of YoutubePlayer, simply call the initialize () method in the catch block.
Example:
if (youtubePlayer != null) { try { youtubePlayer.loadVideo(videoId); } catch (IllegalStateException e) { initialize(API_KEY, this); } }
This works well for me
source share