我正在尝试实时更改youtube视频,但我无处可去; 在我的代码中,当我第一次点击“li”元素时,视频正确加载,但如果我再次尝试再次点击,则视频不会更新; 这是我的代码:
function loadv(v)
{
var params = {
allowScriptAccess: "always"
};
var atts = {
id: "ytplayer1"
};
swfobject.embedSWF("http://www.youtube.com/v/"+v+"?rel=0&enablejsapi=1&playerapiid=ytplayer1",
"play", "480", "295", "9", null, null, params, atts);
}
$('#playlist li').click(function()
{
var video = $(this).attr('id');
loadv( video );
console.log(video); //shows the correct id
});
和html:
<div id="play">You need Flash and JavaScript in order to view the video.</div>
<div id="videoStatus">status</div>
</br>
<ul id="playlist">
<li id="C0DPdy98e4c">1</li>
<li id="zM0k99OpiXM">2</li>
<li id="0ScsDReUTxw">3</li>
<li id="crgB4TyzyXM">4</li>
</ul>
答案 0 :(得分:0)
创建对象时无法更改参数。但您可以使用 Youtube Javascript Player API 。看看https://developers.google.com/youtube/js_api_reference
您想要的功能参考(更改生成的播放器中的视频)位于:https://developers.google.com/youtube/js_api_reference#loadVideoById