我有一个用HTML和PHP编写的页面,尝试使用Youtube IFrame API加载具有自定义ID的youtube播放器。在我的代码中,ID为player
的div应该包含youtube播放器。我的HTML:
<?php
include("server/session.php");
?>
<!doctype html>
<html>
<head>
<title>MuSync - Player</title>
<script type='text/javascript' src='http://www.youtube.com/iframe_api'></script>
<script type='text/javascript' src='javascript/jquery.js'></script>
<script type='text/javascript' src='javascript/getvideo.js'></script>
<link rel='stylesheet' type='text/css' href='player.css'></link>
</head>
<body>
<div align="center">
<h1> head </h1>
<div id='block'></div>
<div id="player"></div>
</div>
<script type='text/javascript'>
var ytp;
var owned = <?php echo $_SESSION['owned']; ?>;
if(owned==<?php echo $_GET['id']; ?>){
owned = true;
}
ytp = document.getElementById('player');
ytp.seekTo(10, true);
</script>
<!-- <input type="hidden" value="" id="videoId"/> -->
</body>
</html>
我的代码的另一部分位于getvideo.js
,它如下:
var vidId;
var time;
var video;
$(function(){
var id = getUrlParameter('id');
var jqxhr = $.ajax("server/getvideo.php?id=" + id)
.done(function(response){
var json = jQuery.parseJSON(response);
vidId = json['url'];
time = json['time'];
})
.fail(function(){
alert("Action Failed...");
});
});
function onYouTubeIframeAPIReady(){
video = new YT.Player('player', {
height: '390',
width: '640',
videoId: vidId,
playerVars: {'autoplay': 1, 'start': time}
});
}
尝试在我的主HTML页面中使用seekTo
功能时,youtube播放器只是无法加载任何视频并向我显示错误消息。我的最终目标是偶尔获得视频播放的当前时间,但我似乎无法运行API ......任何帮助都将非常感激。