1

I am trying to get sources of videos through javascript. The code below is working fine. However it only works for one video only, if I was to add the same code for multiple videos, none of the videos work. I am using video.js as the main player for videos.

html:

<source id="01" src="" type='video/mp4'/>

JavaScript:

document.getElementById("01").src="link";
11
  • 1
    IDs are supposed to be unique within a DOM. Commented May 12, 2015 at 4:51
  • @millhouse i have the id's as example like vd1, vd2 and so on Commented May 12, 2015 at 4:54
  • what kind of error occurs? Commented May 12, 2015 at 4:56
  • Can you post your multiple videos html? Commented May 12, 2015 at 4:56
  • the error i get is src not found when using video js but if i was to add just one line of code document.getElementById("vid1").src="link"; it works fine. All videos are on different pages but i'm trying to use javascript to get the sources since the sources changes very often. Commented May 12, 2015 at 4:59

2 Answers 2

1

You absolutely need to reload the video after changing the Source. I give you an exemple with jQuery

var video = document.getElementById("01");
$(video).attr('src', "newlink.mp4");
video.load();

But you can achieve it without jquery

var video = document.getElementById("01");
video.src= "newlink.mp4";
video.load();
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for helping i'm trying to use custom flash player it's seems like it's the flash player issue i tried the locally on html page within html5 it works fine but when using it on external javascript it doesn't do anything thanks for helping again.
1

You have to use the videojs API to change the source:

videojs('YOUR_PLAYER_ID').src("/path/to/newlink.mp4")

This will work for flash and HTML5

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.