Wete_Pilliams Wete_Pilliams - 4 months ago 7
HTML Question

Loading a file path from a text file and inputting it as the source for a video

I have been trying my hardest to not have to ask this here. But, alas... I cannot get the thing to work. I am a python programmer but have the briefest of requirements to output something in HTML. So I dont have time to dig into JQuery properly and understand the syntax, I have been trying to "bodge" it... but alas... no joy!

I have written a maltego transform in python that creates a concatonated path (source + entity name) and outputs that as a text file. I then pass that entity to a web browser which redirects the user to the video display page. I then need to import that text file using JQuery, slot the path from that text file into a variable and then drop that variable into the src for a video.

Basic HTML, its sole purpose is to enable the user to click full screen on the video at the end of a series of transforms which finds videos associated with the entity name. Nothing fancy.

The file that contains the path is called "path.txt".

<HTML>
<HEAD>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>

<body>

<video id="video1" width="520" height="440" src="" type="video/mp4" controls>
<source src="" type="video/mp4">
</video>

<script>

$('#video1').load("path.txt", function(response) {
var path = response;

$("#video1").attr("src", path);

alert(path);
});

</script>

</body>

</body>
</HTML>


This is probably something that I am going to want to kick myself in the shin over... but if someone could clear this up for me (and explain!) it would be greatly appreciated.

Answer

As pointed out, your js syntax is incorrect. You have other errors in your html that should be noted however. The center tag is deprecated: use margin (auto) instead. Also, i don't think the source requires an id. I made a fiddle (or you can run the snippet). Obviously you will have to create a path.txt and load it in order for the function to work

function load_file() {

  $("#logList").load("path.txt", function(response) {
    var path = response;

    $("#video1").attr("src", path);
    alert("test " + path);


  });
}
video {
  margin-right: auto;
  margin-left: auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<body>

  <input type="button" value="Load" onclick="load_file()" />


  <video id="video1" width="520" height="440" src="" type="video/mp4" controls>
    <source src="" type="video/mp4">
  </video>


</body>

Comments