Detecting when a YouTube video has finished playing

假装没事ソ 提交于 2019-12-12 10:47:03

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/23686745/detecting-when-a-youtube-video-has-finished-playing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!