6

我在网页中有一个 YouTube 播放器。我需要动态更改此播放器播放的视频。

使用 YouTube 的 chromeless 播放器,这(相对)容易。它有loadVideoById()完美的方法。问题是,无铬播放器没有任何控件(播放/暂停等)。常规的YouTube 播放器拥有所有这些,但它没有loadVideoById()方法。

有没有办法将普通播放器的控件包含到无铬播放器中,或者loadVideoById()在普通播放器中实现方法?

谢谢。

4

4 回答 4

5

您不能这样做,因为“常规 youtube 播放器”中的调用将 URL 中的 VideoID 作为参数:

取而代之的是,您可以轻松创建自己的函数来更改 Embbebed SWF,我的意思是说,您将swfobject用于“常规播放器”,然后使用createSWF 函数,您将能够动态替换以前的视频为实际视频.

希望这对您有所帮助。

于 2008-12-16T13:50:03.880 回答
3

你可以这样做...

http://code.google.com/apis/ajax/playground/#change_the_playing_video

于 2010-10-25T21:47:55.687 回答
2

仅供参考,还有一个 jQuery 插件可以为您完成,并为您提供大量控件!

http://tikku.com/jquery-youtube-tubeplayer-plugin

https://github.com/nirvanatikku/jQuery-TubePlayer-Plugin

于 2011-05-15T07:54:11.770 回答
1

我发现使用 loadVideoByUrl() 作为 loadVideoByIdl() 的替代品而不是使用 createSWF 更容易,您不必这样弄乱 swfobject,它是一个内置函数...只需使用视频 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):Void 加载并播放指定视频。

    * 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."
于 2011-02-27T01:07:40.953 回答