我在网页上放了个YouTube的播放器。我需要动态改变这个播放器播放的视频。
使用YouTube的无铬播放器,这(相对)容易。它有loadVideoById()方法,可以完美地工作。问题是,无色调的播放器没有任何控件(播放/暂停等)。regular YouTube player拥有所有这些功能,但是它没有loadVideoById()方法。
有没有办法将普通播放器的控件包含到无铬播放器中,或者在普通播放器中实现loadVideoById()方法?
谢谢。
发布于 2008-12-16 13:50:04
你不能这样做,因为在“常规youtube播放器”中的调用将URL中的VideoID作为参数:
相反,你可以很容易地创建自己的函数来改变Embbebed SWF,我的意思是,假设你正在使用swfobject作为“常规播放器”,然后使用createSWF function,你将能够动态地用实际的视频替换之前的视频。
希望这能对你有所帮助。
发布于 2010-10-26 05:47:56
你能做到的..。
http://code.google.com/apis/ajax/playground/#change_the_playing_video
发布于 2011-02-27 09:07:41
我发现使用loadVideoByUrl()代替loadVideoByIdl()比使用createSWF更容易,你不必以这种方式处理swf对象,它是一个内置的function...just使用视频ID创建一个youtube swf url,比如: url="http://www.youtube.com/e/“+ VIDEO_ID + "?enablejsapi=1&version=3”,然后使用loadVideoByUrl()函数提交,如下所示: player.loadVideoByUrl(url)
这样你就不用弄乱swfobject了,它的拼写如下:
http://code.google.com/apis/youtube/js_api_reference.html#loadVideoById
"player.loadVideoByUrl(mediaContentUrl:String,startSeconds:Number):空加载并播放指定的视频。
* The mediaContentUrl must be a fully qualified YouTube player URL in the format http://www.youtube.com/e/VIDEO_ID. In YouTube Data API video feeds, the url attribute of the <media:content> tag contains a fully qualified player URL when the tag's format attribute has a value of 5.
* startSeconds accepts a float/integer and specifies the time from which the video should start playing. If startSeconds (number can be a float) is specified, the video will start from the closest keyframe to the specified time."https://stackoverflow.com/questions/371320
复制相似问题