嵌入式YouTube视频在本地服务器上不起作用
我在StackOverflow上看到了许多这样的问题,但是没有一个有有效的答案.我的问题是我无法嵌入YouTube视频,因为此视频不可用".出现:
I saw many questions like this asked on StackOverflow, but none of them had a working answer. My problem is that I can't embed a YouTube video, because a "This video is not available." comes up:
这是到目前为止我所知道并尝试过的:
Here's what I know and have tried so far:
- 并非所有视频都出现此错误.据我所知,它通常无法在流行音乐视频中使用.
- 嵌入这些YouTube视频无法在本地HTML文件(
file:///C:/path/to/file.html
)中运行,也不能在嵌入式视频位于我的本地Django服务器(12.345.67.89:8080/page
)上时起作用. - 它既不适用于Youtube的
- 我尝试使用
/embed/
和/watch?v=
作为URL. - 使用iframe时,将
https://
更改为http://
或//
无效.删除www.
部分也不起作用. - 有趣的是,当我将代码放在 JSFiddle 中时,它确实起作用.
- 它不适用于Chrome和Firefox.
- 控制台中没有错误.
- 通过电话(不通过WiFi连接)或Web代理访问网站也不起作用.
- This error doesn't come up on all videos. From what I've noticed, it's mostly not working on popular music videos.
- Embedding these YouTube videos doesn't work in a local HTML file (
file:///C:/path/to/file.html
) nor when the embedded video is on my local Django server (12.345.67.89:8080/page
). - It doesn't work both with Youtube's
- I tried both
/embed/
and/watch?v=
as the URL. - When using the iframe, changing
https://
tohttp://
or//
doesn't work. Taking thewww.
part out doesn't work either. - Interestingly, it does work when I put the code in JSFiddle.
- It doesn't work on both Chrome and Firefox.
- There are no errors in the console.
- Accessing the website from my phone (not connecting from my WiFi) or a web proxy doesn't work either.
Sergiy Shcherbina的答案帮助我解决了这个问题.我当时从虚拟机运行Web服务器,并通过本地IP地址访问它.
Sergiy Shcherbina's answer helped me solve this issue. I was running my web server from a vm and accessing it through my local IP address.
似乎您需要通过主机名而不是IP地址访问包含嵌入式youtube播放器的页面.
It seems that you need to access your page that contains the embedded youtube player through a host name and NOT an IP address.
我如何为我的开发环境解决此问题
在进行更改之前,我正在这样访问我的网页:http://192.168.x.x:3000/video
,对于许多可验证为可嵌入"的视频,我会收到视频不可用"错误.
Before the change, I was accessing my web-page like this: http://192.168.x.x:3000/video
and i would get 'video unavailable' errors for many videos that were verifiably 'embeddable'.
一句话:我在我的主机文件中为我的VM设置了一个主机名,并将我的IP地址别名为dev-vm
. 如何编辑主机文件
A Hacky word-around: I set a hostname for my VM in my hosts file and aliased my IP address to dev-vm
. How to edit your host file
现在,我访问具有以下嵌入式播放器的页面:http://dev-vm:3000/video
,现在正在播放以前给我视频不可用"错误的视频.
Now i access the page which has my embedded player like this: http://dev-vm:3000/video
and now videos that previously gave me a 'video unavailable' error are now playing.
真是个奇怪的问题.希望这对遇到类似问题的人有所帮助.
What a bizarre issue. I hope this helps some people who are having a similar issue.