Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedded YouTube video doesn't work on local server

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:

Running on local server

Here's what I know and have tried so far:

  • 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 IFrame API and simply an <iframe> copy-pasted from YouTube: enter image description here
  • I tried both /embed/ and /watch?v= as the URL.
  • When using the iframe, changing https:// to http:// or // doesn't work. Taking the www. 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.
like image 707
Marked as Duplicate Avatar asked Aug 22 '18 14:08

Marked as Duplicate


People also ask

Why is my YouTube video not embedding?

If you receive the error message, "Embedding disabled on request” ,you have probably accidentally disabled embedding via YouTube. To grant permission again, follow these steps: Go to “Video Manager.” Select the appropriate video and click “Edit”.

Why is YouTube embed not working HTML?

Apparently YouTube forbids embedding some videos in a localhost environment without a public domain, but your video can be embedded with no issue whatsoever through a public domain/subdomain: Replace the src value in the JSFiddle from @PStarczewski's answer with your video link and it will work properly.


Video Answer


4 Answers

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.

It seems that you need to access your page that contains the embedded youtube player through a host name and NOT an IP address.

How I solved This for my dev environment

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'.

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

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.

like image 175
Brett K. Avatar answered Oct 21 '22 02:10

Brett K.


It works on sites with domain and does not work on sites reached by IP adress. Works when using on "localhost" and causes "The video is unavailable" when using "127.0.0.1". This is really strange...

like image 43
Sergiy Shcherbina Avatar answered Oct 21 '22 01:10

Sergiy Shcherbina


For some god-forsaken reason, known only to YouTube's engineers, some videos require an HTTP server to play.

If you're familiar with npm and Node.js, you can follow the instructions here so you can set up an HTTP server and try it out for yourself.

But please, if you do have the time and willingness, send a bug report about this issue by following the instructions here. This sort of issue should definitely not be happening.

Best of luck!

like image 5
TKD21 Avatar answered Oct 21 '22 00:10

TKD21


This is not Youtube APIs fault. Tried running this on my localhost using "python -m SimpleHTTPServer 8080" and got it running easily. So, I'm concluding that you don't have a proper local web server. Also, "file:///C:/path/to/file.html" will never work because to use any of Google APIs, you need to have access to the internet.

enter image description here

like image 4
ReyAnthonyRenacia Avatar answered Oct 21 '22 01:10

ReyAnthonyRenacia