vime-js / vime

Customizable, extensible, accessible and framework agnostic media player. Modern alternative to Video.js and Plyr. Supports HTML5, HLS, Dash, YouTube, Vimeo, Dailymotion...
https://vimejs.com
MIT License
2.75k stars 154 forks source link

how to dynamically add source track with js? #258

Open ralyodio opened 2 years ago

ralyodio commented 2 years ago

i'm using vanilla html/js and want to dynamically add the mp4 file to play with javascript.

I have a player object with window.player = document.querySelector('vm-player');

ralyodio commented 2 years ago

I'm using vime.js and trying to dynamically change the video player source video with javascript (not using any frameworks):

  1 (async () => {
  2   const movie = document.querySelector("a[href$='.mp4']").href;
  3   window.player = document.querySelector('vm-player');
  4 
  5   console.log('movie: ',movie);
  6 
  7   if (movie) {
  8     console.log(window.player);
  9     window.player.src = movie;
 10   }
 11 })();