I want to pass javascript variable as src to html5 video so that the video changes dynamically based on the js variable value. However I am not able to achieve it
<script type="text/javascript"> var path = "/api/Videos/mp4/"; var filename = '@ViewBag.filename'; var fullPath = path.concat(filename); document.getElementById('fullPath1').src = fullPath.toString(); </script>
<p><script type="text/javascript">document.write(fullPath)</script></p> <video width="480" height="320" controls="controls" autoplay="autoplay"> <source src="fullPath1" type="video/mp4"> </video>
Please help me to get this working. Thanks!
you are looking for an element by id
document.getElementById('fullPath1').src = fullPath.toString();
but you haven't yet define any id:
<source src="fullPath1" type="video/mp4">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.