检测YouTube视频何时播放完毕 [英] Detecting when a YouTube video has finished playing

查看:160
本文介绍了检测YouTube视频何时播放完毕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查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 YoutubePlayerclass to get the listener and implement the method OnVideoEnded

这篇关于检测YouTube视频何时播放完毕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆