YouTube 常规播放器中的 loadVideoById() (非 chromeless)
-
21-08-2019 - |
题
我的网页中有一个 YouTube 播放器。我需要动态更改该播放器播放的视频。
使用 YouTube 的 chromeless 播放器可以(相对)轻松地实现这一点。它有方法 loadVideoById()
效果很好。问题是,chromeless 播放器没有任何控件(播放/暂停等)。这 普通 YouTube 播放器 拥有这一切,但它没有 loadVideoById()
方法。
有没有办法将常规播放器的控件包含到 chromeless 播放器中,或者实现 loadVideoById()
普通播放器中的方法?
谢谢。
解决方案
您不能这样做,因为“常规 YouTube 播放器”中的调用将 URL 中的 VideoID 作为参数:
- 常规视频: http://www.youtube.com/v/VIDEO_ID&enablejsapi=1&playerapiid=ytplayer
- 无铬: http://www.youtube.com/apiplayer?enablejsapi=1
相反,您可以轻松创建自己的函数来更改嵌入的 SWF,我的意思是,假设您正在使用 swf对象 对于“普通玩家”,然后使用 创建SWF函数 您将能够动态地将上一个视频替换为实际视频。
希望这对您有帮助。
其他提示
FYI也有一个jQuery插件,可以为你做它,并为您提供一吨的控制!
我发现它更容易使用loadVideoByUrl()作为替代loadVideoByIdl()而不是使用createSWF,你不必乱用SWFObject的这种方式,它是一个内置的功能...只需使用视频ID创建YouTube瑞士法郎URL,例如: “enablejsapi = 1&版本= 3” 的url = “http://www.youtube.com/e/” + VIDEO_ID +和使用这样的loadVideoByUrl()函数提交:播放器。 loadVideoByUrl(URL)
您不必乱用SWFObject的这种方式,它的拼写出在这里:
http://code.google.com/apis/youtube/js_api_reference。 HTML#loadVideoById
“player.loadVideoByUrl(mediaContentUrl:字符串,startSeconds:编号):无效 加载并播放指定的视频。
* 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."