Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript - Adding Video Element features to embedded Youtube content

let me start with what I already have: HTML5:

<video id= "video" preload=auto autoplay controls>
<source src = "http://www.w3schools.com/html/mov_bbb.mp4">
</video>

JS:

<script>
video.addEventListener("loadedmetadata", start);
var track;
var data;
var currentX, currentY;
function start(){
    data = video.getBoundingClientRect();
    track = video.addTextTrack("captions", "English", "en");
    video.addEventListener("mousemove", movement);         

}
function movement(e){
    currentX = e.clientX, currentY = e.clientY;

}
</script>

So as you can see, I have basic HTML5 video element, to which I add events and manipluate later on in various ways. One of the things I do with these events is adding dynamic captions(addTextTrack) to my HTML5 video via ajax call to a Node server. It all works fine, but here is the actual problem:

I want to be able to do all of these things with the youtube API:

 <iframe width="560" height="315" src="https://www.youtube.com/embed/QtXby3twMmI" frameborder="0" allowfullscreen></iframe>

but can't do many of the things listed above because youtube provides an Iframe to work with.

Now last thing, I'd appreciate solutions without using jQuery or big libraries because at the end, I suggest an API myself to clients, and I do not want to force big libraries on them. Thank you.

like image 313
RunningFromShia Avatar asked Jun 30 '26 07:06

RunningFromShia


2 Answers

You can use this awesome Plyr package and install it via: npm, bower, Ember or use a CDN

  • It's semantic ( <video> tag )
  • Responsive
  • For Youtube and Vimeo
  • Written in "vanilla" JavaScript ( No libraries dependencies )

and the total weight is less than 60 Kb totally acceptable.

By now i think this is the best choice :) hope help you.

like image 82
Héctor León Avatar answered Jul 02 '26 21:07

Héctor León


You can use the option that youtube provides, which are available here or if those are to limiting you can download the video with youtube-dl and host it on your server. Then you can use it like an other html5 video.

Warning: Using youtube-dl may not be legal (it violates Google's TOS). Consult a lawyer first.

like image 33
michaelmesser Avatar answered Jul 02 '26 20:07

michaelmesser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!