【问题标题】:loadVideoById() in YouTube's regular player (not chromeless)YouTube 常规播放器中的 loadVideoById()(非无铬)
【发布时间】:2010-09-27 03:29:00
【问题描述】:

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

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

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

谢谢。

【问题讨论】:

  • 警告:有时 Google 会在 YouTube ID 的末尾附加一个 &ltr; 标记(例如在搜索结果页面中)。如果您不小心复制了它 - 当您尝试使用 loadVideoById() 时,这个不可见字符会给您“无效参数”错误。使用光标键确保任何视频 ID 的末尾没有不可见字符
  • 还要记住,在 iOS 上,如果不明确点击播放,就无法启动 youtube 视频(或任何 HTML5 视频)。如果你打电话给loadVideoById(),你必须先检查视频是否正在播放,否则它会进入黑匣子

标签: javascript api youtube


【解决方案1】:

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

除此之外,您可以轻松创建自己的函数来更改 Embbebed SWF,我的意思是,假设您使用 swfobject 作为“常规播放器”,然后使用 createSWF function 您将能够替换以前的动态的实际视频。

希望对您有所帮助。

【讨论】:

  • 现在“常规视频播放器”有 l​​oadVidoeById 和 loadVideoByUrl 选项
【解决方案2】:
【解决方案3】:

我发现使用 loadVideoByUrl() 作为 loadVideoByIdl() 的替代方法比使用 createSWF 更容易,您不必这样弄乱 swfobject,它是一个内置函数...只需使用视频用于创建 youtube swf url 的 ID,例如:url="http://www.youtube.com/e/" + VIDEO_ID + "?enablejsapi=1&version=3" 并使用 loadVideoByUrl() 函数提交,如下所示:播放器。 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."

【讨论】:

    【解决方案4】:

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

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

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

    【讨论】:

    • 这容易多了!为什么我一开始不考虑寻找一个 jQuery 插件?!谢谢!
    猜你喜欢
    • 2011-05-05
    • 2010-12-09
    • 1970-01-01
    • 2023-03-11
    • 2011-09-29
    • 1970-01-01
    • 2016-08-07
    • 2010-11-12
    • 1970-01-01
    相关资源
    最近更新 更多