gpt4 book ai didi

javascript - YouTube API : See which video id is currently playing

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:50:26 25 4
gpt4 key购买 nike

有没有办法显示/查看/返回当前正在播放的视频(即哪个视频 ID)?

这是 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() 函数将获取另一个要播放的 videoId..

我想在一个DIV中显示,当前正在播放的是哪个videoId

最佳答案

player.getVideoData()['video_id']

var video_data = player.getVideoData()
video_data['video_id']

解决方法:

function onPlayerStateChange(event) {
if(event.data === 0) {
player.stopVideo();
player.loadVideoById(player.getVideoData()['video_id']);
}
}

关于javascript - YouTube API : See which video id is currently playing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20276823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com