Reputation: 81
I developed to play youtube video through iframe and it almost works. but there is also have videos that can't be played in django template(SSR). However above some videos can played in react(CSR).
For example as below
work youtube url: https://youtu.be/bPCYR5Wec-g
not work youtube url: https://www.youtube.com/watch?v=d7d-e4BHs0w
How to play this youtube videos?
Upvotes: 2
Views: 1226
Reputation: 109
Ok, so my goal was to embed a video on the landing page of a website. The video should run automatically, and in mute. I used iframe to achieve this but I was getting this error "Youtube refused to connect" . After surfing I got to know that for iframe you need to use embed links. Below, is my code snippet. Hope it helps.
<iframe src="https://www.youtube.com/embed/9bZkp7q19f0?autoplay=1&mute=1"></iframe>
Upvotes: 0
Reputation: 21
Had a similar issue when using iframes in Django, I could embed most of the videos but some popular music videos would not load and simply display: Video unavailable. To fix it had to manually set the Referer header by adding this line to settings.py:
SECURE_REFERRER_POLICY = "no-referrer-when-downgrade"
Turns out Django does not set Referer in request headers by default, and for some videos (e.g. popular music videos that are copyrighted) youtube checks if the Referer has a host name (e.g http://localhost:8000/ in dev or https://examplesite.com), if the Referer is not set or it is simply an IP (e.g. 192.168.1.1:8000) then the video won't play. The "no-referrer-when-downgrade" is 1 of the Django referrer policy settings that adds the referer header except when downgrading from https to http and worked for me.
Upvotes: 2
Reputation: 2431
After checking this answer, I embed the video https://www.youtube.com/watch?v=d7d-e4BHs0w using jsfiddle and I got the following text:
Video unavailable
This video has content from LatinAutor - UMPG, who blocked its playing on this website or in this application.
The reason is not shown if you copy/paste the embed link in your browser - i.e. https://www.youtube.com/embed/d7d-e4BHs0w
TL;DR: The video might be not available due to the owner disabled their videos for embedding or YouTube themselfs disables certain videos from being embed - due to copyright issues or any other obscure/non-disclosed reasons...
Upvotes: 2