Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting when a YouTube video has finished playing

How to do I check when a YouTube video has finished playing in the official YouTube Android app? In the LogCat I see things such as: VideoStage: MEDIA_PLAYING_VIDEO. Is there any way to detect when this finishes?

like image 777
user2420837 Avatar asked May 15 '14 19:05

user2420837


1 Answers

You could use MediaPlayer. It has an isPlaying method to check if music/videos are currently playing. Just set a Boolean to true while it's playing and check the isPlaying method against that Boolean to see if it changed from True to False.

Otherwise Youtube (or google) may have some specific API's

EDIT:

I looked into here; and it appears that there is an API for youtube.

you can use the method PlayerStateChangeListener for the YoutubePlayerclass to get the listener and implement the method OnVideoEnded

like image 155
Timothy Frisch Avatar answered Sep 21 '22 00:09

Timothy Frisch