我想使用youtube播放器api创建一个网络播放器。我想创建自动播放视频。
为此,我使用了以下脚本:
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
var isPlaying = false;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '420',
width: '640',
playerVars: { 'autoplay': 1, 'controls': 0, 'showinfo': 0 },
events: {
// 'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event) {
event.target.playVideo();
}
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !done) {
setTimeout(stopVideo, 6000);
done = true;
}
}
function stopPlayerVideo() {
player.stopVideo();
return false;
}
function playPlayerVideo() {
player.playVideo();
return false;
}
function pausePlayerVideo() {
player.pauseVideo();
return false;
}
function ShowModalPopup() {
var url = $get("<%=hfURL.ClientID %>").value;
if (url != "") {
var fn = function () {
if(player != null)
$('#txtCnt').val(cnt + " : " + isPlaying + " :u " + url);
player.cueVideoById(url, 0, "hd1440");
player.playVideo();
$('#msg').hide();
$('#img_msg').hide();
isPlaying = true;
pendingDate = new Date();
pendingSec = 0;
}
setTimeout(fn, 1000);
$get("<%=hfDuration.ClientID %>").value = "";
$find("mpe").show();
}
return false;
}
function GetPlayTimeDuration() {
player.stopVideo();
player.clearVideo();
$get("<%=hfDuration.ClientID %>").value = $('#time').val();
//$find("mpe").hide();
if ($get("<%=hfDuration.ClientID %>").value == "") {
$get("<%=hfDuration.ClientID %>").value = "0";
}
isPlaying = false;
$('#time').val("");
$get("<%=hfURL.ClientID %>").value = "";
var UpdatePanel1 = '<%=upSubmit.ClientID%>';
if (UpdatePanel1 != null) {
__doPostBack('<%= btnClose.ClientID %>', '');
}
}
var cnt = 0;
setInterval(function () {
if (player != null) {
if (isPlaying) {
player.setPlaybackQuality('hd1440');
var tmptime = player.getCurrentTime();
tmptime = tmptime - ($('#<%= hfTimeFrame.ClientID %>').val() * tmptime);
$('#time').val(tmptime);
if (parseFloat($('#<%= hfCutoff.ClientID %>').val()) < parseFloat($('#time').val()))
GetPlayTimeDuration();
}
else if (!isPlaying) {
if ($get("<%=hfURL.ClientID %>").value != "") {
ShowModalPopup();
}
}
cnt++;
}
else {
player = new YT.Player('player', {
height: '420',
width: '640',
playerVars: { 'autoplay': 1, 'controls': 0, 'showinfo': 0 },
events: {
// 'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
}, 10);
我的问题是有一段时间错误:
未捕获的TypeError:undefined不是函数player.cueVideoById
答案 0 :(得分:0)
cueVideoById
不是您可以设置为c1 = new NewCookie("session_id", uuid, "/", null, null, COOKIE_MAX_AGE, false);
return Response.status(200).cookie(c1).build();
的播放质量的有效值之一。根据{{3}},可能的值为:
- 小
- 介质
- 大
- HD720
- HD1080
- HIGHRES
- 默认
此外,截至今年,YouTube JavaScript播放器API已被弃用,因此我不希望它以您认为的方式运行。