Playing YouTube videos from embedded player

ε祈祈猫儿з 提交于 2020-02-02 16:22:23

问题


I am trying to play YouTube videos from a chrome extension and I get error code 150 frequently, specifically from videos that are from outside my country. I use Youtube Data API v3 to retrieve videos with the following parameters:

part=id&type=video&order=relevance&safeSearch=strict&videoSyndicated=true&maxResults=1&videoEmbeddable=true

However, I often get videos that throw error code 150 when played from my embedded player. One example is the following video:

Turn down for what

when played from an embedded player, it throws error 150, and the error message shown in the iframe is

the video contains content from SME. It is restricted from playback on certain sites.

I try the same video with the same embedded iframe player in youtube Player demo website hosted on developers.google.com, and it plays without the error code.

Therefore, I suspect the above error happens because I am trying to play the video from chrome extension, not because I am playing it from an embedded player. When I play it from the webpage hosted on my local machine (ex: file:///home/testing.page.html), I get the same error message.

To resolve the issue, I attempted to make YouTube think that I was a normal webpage instead of a chrome extension. By using chrome.webRequest, I added a referer information to the request header.

{ name: 'Referer', value: "https://www.youtube.com" }

Even after the requestHeader was fixed, the error remained. I assume it's because there's origin property attached to youtube iframe player that specifies where the embedded player is from, regardless of the requestHeader.

My objective is either to find videos that are absolutely playable, or play videos that are only playable from a webpage (can't be played from chrome extension).

I would appreciate any help. Thank you.

Extra information

My iframe is initialized like below:

<iframe id="myframe" src="https://www.youtube.com/embed/?
enablejsapi=1&origin=chrome-extension:\\<my_extension_id>" frameborder="0" allowFullScreen></iframe>

来源:https://stackoverflow.com/questions/22854231/playing-youtube-videos-from-embedded-player

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!