I have an image displayed in a web page as well as several icons with other images. I am using the vodeo.js library from the following:
<link href="https://vjs.zencdn.net/7.2.3/video-js.css" rel="stylesheet" />
<script src="https://vjs.zencdn.net/7.2.3/video.js"></script>
When clicking on any image icon, the javascript replaces the image. So far, so good.
I have enhanced that to start by displaying that with a video. That works great, with the following code:
<div id='toppicture' class='design-big-image'><center><video id='gunvideo' class='video-js vjs-default-skin' controls autoplay muted preload='auto' width='750'>
<source type='application/x-mpegURL' src='http://localhost/gb2/template_videos/133/output.m3u8')>
</video>
<script>videojs('gunvideo')</script>
My links to replace the video with an image using the following Javascript code to replace the HTML work as well:
function toggleImage(smallImage) {
newhtml = "<Center><img maxwidth=750 src=gb2/template_photos/template_photo_133_1.png id='big-image' alt='main gun image' /></Center>n"
document.getElementById("toppicture").innerHTML = newhtml;
}
On to the problem. My link to replace the “” tag with video updates the HTML, but the web page displays a small video player with no content. When I remove the “control” option from the tag, nothing is seen. If I uncomment the line replacing the tag with an tag, the page updates as expected.
The Javascript code:
function toggleVideo(vidurl) {
newhtml = "<center><video controls width=750 id='gunvideo' class='video-js vjs-default-skin'><source type='application/x-mpegURL' src='" + vidurl + "')></center></video><script>videojs('gunvideo').load()/script>n";
document.getElementById("toppicture").innerHTML = newhtml;
// document.getElementById("toppicture").innerHTML = "<h2>New HTML</h2>";
}
Looking at the HTML code after the replacement, I see the following (which is what I would expect and matches the HTML code on the initial page load that works) :
<div id='toppicture' class='design-big-image'><center><video id='gunvideo' class='video-js vjs-default-skin' controls autoplay muted preload='auto' width='750'>
<source type='application/x-mpegURL' src='http://localhost/gb2/template_videos/133/output.m3u8')>
</video>
<script>videojs('gunvideo')</script>
It looks like the update to the html source happens as expected, but I am not seeing the expected video output.