检测YouTube视频何时播放完毕 [英] Detecting when a YouTube video has finished playing
问题描述
如何检查YouTube视频在YouTube YouTube官方官方应用中的播放时间?在LogCat中,我看到以下内容:VideoStage:MEDIA_PLAYING_VIDEO.有什么方法可以检测到何时完成?
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?
推荐答案
您可以使用 MediaPlayer
.它具有isPlaying
方法来检查当前是否正在播放音乐/视频.只需在播放时将Boolean
设置为true,然后针对该Boolean
检查isPlaying
方法以查看其是否从True
更改为False
.
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
.
否则,Youtube(或Google)可能会有一些特定的API
Otherwise Youtube (or google) may have some specific API's
我在这里查看了;似乎有一个针对youtube的API.
I looked into here; and it appears that there is an API for youtube.
您可以对YoutubePlayer
类使用方法PlayerStateChangeListener
来获取侦听器并实现方法OnVideoEnded
you can use the method PlayerStateChangeListener
for the YoutubePlayer
class to get the listener and implement the method OnVideoEnded
这篇关于检测YouTube视频何时播放完毕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!