javascript - Video.js changing source, but does not show new source -


sorry lack of knowledge on topic

i have script changes source of video player. , that. problem video.js player plays first source assigned it.

document.getelementbyid("vid-player_html5_api").innerhtml = "";  document.getelementbyid("vid-player_html5_api").innerhtml = "<source src='" + link + "' type='video/mp4'>"; document.getelementbyid("vid-player_html5_api").muted = false; 

so if there 2 buttons, , clicked button 1 change source of player , show correct video. lets clicked button 2 change source of player, but still show same video showed button 1

it proven changes source, checked chrome dev tools , surely enough changed source

how fix this?

you can try below,

function playvideo(videosource, type) {    var videoelm = document.getelementbyid('testvideo');    var videosourceelm = document.getelementbyid('testvideosource');      if (!videoelm.paused) {          videoelm.pause();       }           videosourceelm.src = videosource;     videosourceelm.type = type;          videoelm.load();      videoelm.play();    }
<video id="testvideo" width="400" controls>    <source id="testvideosource">  </video>  <br/>  <input type="button" value="play video 1" onclick="playvideo('http://www.w3schools.com/html/mov_bbb.mp4', 'video/mp4')" />  <input type="button" value="play video 2" onclick="playvideo('http://www.w3schools.com/html/mov_bbb.ogg', 'video/ogg')" />


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -