2

我在开发 Google Chrome 扩展程序时遇到了巨大的障碍。任何被货币化(例如有广告)的 YouTube 歌曲都不会播放。

这记录在这里: https ://developers.google.com/youtube/flash_api_reference_as2#Events

以及这里:https ://stackoverflow.com/questions/4852490/some-videos-not-playing-through-youtube-api

以前,我一直在使用 YouTube 的 Flash API。在我尝试部署我的扩展之前,这很有效。那时我遇到了巨大的安全问题,由于权限不足而锁定了应用程序。因此,我重写了播放器以使用 iFrame API 而不是 Flash API。

iFrame API 使我能够成功部署而没有任何 Flash 安全问题,但现在我无法播放任何带有广告的歌曲。

有谁知道解决这个问题?

编辑:

我的扩展可以在这里下载:http ://www.meomixes.com/

扩展的来源可以在这里看到:http: //github.com/MeoMix/YouPod

例如,这首歌对我来说非常适合:http ://www.youtube.com/watch?v=QXtPoNfOYSo

但是,这首歌在播放时会出错:http ://www.youtube.com/watch?v=_dfVAAWbLUY

请注意,第二首歌曲已被货币化。

4

1 回答 1

3

First, I initialised the player and loaded the video:

player = new YT.Player(getFrameID('MusicHolder'));player.loadVideoById('_dfVAAWbLUY')

As you can see, the player refused to embed the video, because the player is too small. So, I changed the size of the player, and tried again:

$('iframe').width(640).height(390);player.loadVideoById('_dfVAAWbLUY');

The video started playing. I've tested the same code in an extension, and the problem also disappeared.

So, create the dummy frame as follows:

<iframe
    width="640"
    height="390"
    src="http://www.youtube.com/embed/dummy?enablejsapi=1"
></iframe>

Some more debugging information:

  • In the previous screenshots, http://localhost:8000/ is the root directory of the chrome extension. I used python -m SimpleHTTPServer to create the server.
  • I intercepted the messages between the frame and the page, and found that error code 150 was thrown. According to the documentation, this "is the same as 101", and "the 101 error code is broadcast when the video requested does not allow playback in the embedded players."

player = new YT.Player(getFrameID('MusicHolder'));onmessage=console.log.bind(console);player.loadVideoById('_dfVAAWbLUY')

于 2012-06-04T15:26:06.933 回答