I'm trying to put a YouTube video source into the HTML5 <video>
tag, but it doesn't seem to work. After some Googling, I found out that HTML5 doesn't support YouTube video URLs as a source.
Can you use HTML5 to embed YouTube videos? If not, is there any workaround?
With the new iframe tag embedded in your website, the code will automatically detect whether you are using a browser that supports HTML5 or not.
The iframe code for embedding YouTube videos is as follows, simply copy the Video ID and replace in the code below:
how about doing it the way hooktube does it? they don't actually use the video URL for the html5 element, but the google video redirector url that calls upon that video. check out here's how they present some despacito random video...
the code is for the following video page https://hooktube.com/watch?v=72UO0v5ESUo
youtube to mp3 on the other hand has turned into extremely monetized monster that returns now download.html on half of video download requests... annoying...
the 2 links in this answer are to my personal experiences with both resources. how hooktube is nice and fresh and actually helps avoid censorship and geo restrictions.. check it out, it's pretty cool. and youtubeinmp4 is a popup monster now known as ConvertInMp4...
This answer does not work anymore, but I'm looking for a solution.
As of . 2015 / 02 / 24 . there is a website (youtubeinmp4) that allows you to download youtube videos in
.mp4 format
, you can exploit this (with some JavaScript) to get away with embedding youtube videos in<video>
tags. Here is a demo of this in action.Pros
Cons
It obviously depends on the
youtubeinmp4.com
servers and their way of providing a downloading link (which can be passed as a<video>
source), so this answer may not be valid in the future.You can't choose the video quality.
JavaScript (after
load
)Usage (Full)
Standart video format.
Usage (Mini)
A little less common but quite smaller, using the
youtube.be
shortened url and thesrc
attribute directly in the<video>
tag.Hope it helps! :)
Steps to follow:
link
.HTML Code
)HTML
.The
<video>
tag is meant to load in a video of a supported format (which may differ by browser).YouTube embed links are not just videos, they are typically webpages that contain logic to detect what your user supports and how they can play the youtube video, using HTML5, or flash, or some other plugin based on what is available on the users PC. This is why you are having a difficult time using the video tag with youtube videos.
YouTube does offer a developer API to embed a youtube video into your page.
I made a JSFiddle as a live example: http://jsfiddle.net/zub16fgt/
And you can read more about the YouTube API here: https://developers.google.com/youtube/iframe_api_reference#Getting_Started
The Code can also be found below
In your HTML:
In your Javascript: