TypeError: player.currentTime is not a function error in videojs
TypeError: player.currentTime is not a function error in videojs
我在 videojs 中有一个工作播放器,我正在尝试获取进度条的当前位置,在 videojs 提供的文档中,他们使用 myPlayer.currentTime() 来获取和设置时间(以秒为单位)但它对我不起作用。
我的代码:
var tag = document.createElement("script");
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName("script")[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player("player", {
host: "https://www.youtube.com",
/* no need to specify player
size here since it is handled
by the player-size div */
videoId: video_id,
playerVars: {
enablejsapi: 1,
playsinline: 1,
start: 0,
disablekb: 0
},
events: {
onReady: onPlayerReady,
onStateChange: onPlayerStateChange
}
});
}
function onPlayerStateChange(event) {
console.log("player state: " + player.getPlayerState());
if (player.getPlayerState() == 2){
console.log("STOPED AT:" + player.currentTime()); // This is where i want to log the current time of the playing video
}
}
function updateVideoId(video_id) {
player.loadVideoById(video_id, -1);
}
function stopVideo() {
player.stopVideo();
}
function onPlayerReady(event) {
document.getElementById("play").addEventListener("click", function() {
player.playVideo();
});
}
我做错了什么?
上面的代码是 YouTube 的 API,而不是 Video.js。
如果您想在 Video.js 中播放 YouTube 视频并使用 Video.js 的 API,您需要使用 YouTube tech for Video.js
我在 videojs 中有一个工作播放器,我正在尝试获取进度条的当前位置,在 videojs 提供的文档中,他们使用 myPlayer.currentTime() 来获取和设置时间(以秒为单位)但它对我不起作用。
我的代码:
var tag = document.createElement("script");
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName("script")[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player("player", {
host: "https://www.youtube.com",
/* no need to specify player
size here since it is handled
by the player-size div */
videoId: video_id,
playerVars: {
enablejsapi: 1,
playsinline: 1,
start: 0,
disablekb: 0
},
events: {
onReady: onPlayerReady,
onStateChange: onPlayerStateChange
}
});
}
function onPlayerStateChange(event) {
console.log("player state: " + player.getPlayerState());
if (player.getPlayerState() == 2){
console.log("STOPED AT:" + player.currentTime()); // This is where i want to log the current time of the playing video
}
}
function updateVideoId(video_id) {
player.loadVideoById(video_id, -1);
}
function stopVideo() {
player.stopVideo();
}
function onPlayerReady(event) {
document.getElementById("play").addEventListener("click", function() {
player.playVideo();
});
}
我做错了什么?
上面的代码是 YouTube 的 API,而不是 Video.js。
如果您想在 Video.js 中播放 YouTube 视频并使用 Video.js 的 API,您需要使用 YouTube tech for Video.js