Jump to content

Use JS to Call HTML5 Video URL


AndrewPVI

Recommended Posts

Hello, 

I'm trying to use a simple Javascript to call a function of the local IP address of a host for a video player that auto-updates its IP address whenever the user modifies the IP of the Host. 

 

I've been using the Built-in HTML 5 player to play an Apple HLS video that streams from the host and it works but I want to dynamically update the video src using the javascript. 

I hope this makes sense. 

 

The code has ive been trying to piece together looks like this: 

 

function myFunction() {
  var hostip = location.host;
  document.getElementById("videohls").innerHTML = hostip ;

this gets the host IP: 192.168.0.1 example. 

 

I need to take this IP and combine it with http:// + hostip + /1.m3u8 

That output needs to be the HTML5 players src 

 

How can I make this possible? I feel like its really simple but I'm not a javascript expert at all. 

 

 

Link to comment
Share on other sites

  • 3 months later...
function myFunction() {
  var hostip = location.host;
  document.getElementById("videohls").innerHTML = hostip ;
var url = " http:// "+ hostip + /"1.m3u8 ";
$("#id-of-video-tag> source").attr("src", url);}

I think this will work.

Hope this will help you.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...