本文介绍了Youtube API:查看当前正在播放的视频ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法显示/查看/返回当前播放的视频(那个,哪个videoID)?
Is there a way to display/see/return which video (so, which videoID) is playing at the moment?
这是Iframe的基本代码API:
This is the basic code of the Iframe API:
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'pJ18QeQy0e8',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange,
'onError': onError,
},
playerVars: {
'controls': 0,
'showinfo': 0,
'iv_load_policy': 3,
'wmode': "opaque",
},
});
}
此事件将被调用:
function onPlayerStateChange(event) {
if(event.data === 0) {
player.stopVideo();
player.loadVideoById(getId());
}
}
getId()函数将获得另一个视频玩... ..
The getId() function will get another videoId to play..
我想在DIV中显示,videoId当前正在播放
I want to display in a DIV, which videoId is currently playing
推荐答案
player.getVideoData()['video_id']
OR
var video_data = player.getVideoData()
video_data['video_id']
解决方案:
function onPlayerStateChange(event) {
if(event.data === 0) {
player.stopVideo();
player.loadVideoById(player.getVideoData()['video_id']);
}
}
这篇关于Youtube API:查看当前正在播放的视频ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!