首页 > 解决方案 > 使用javascript单击按钮后如何更改视频源

问题描述

我想在单击按钮后执行更改视频源的功能。但是,我使用了很多方法,但是点击后,视频播放器仍然没有更改源。这是我的代码:(我省略了一些不必要的代码)HTML:

<video id="my-player">
    <source id='source' src='' type="application/dash+xml"></source>
    <p class="vjs-no-js">
</video>
<button id='dashsample' onclick='dashSample(); return false'>Dash Sample</button>

Javascript:

function dashSample(){
    var video = document.getElementById('my-player');
    var source = document.getElementById('source');
    var newsource = 'http://dai-ce14453a15d70c42.elb.eu-central-1.amazonaws.com/awt/media/dash/cosmo/cosmo1/manifest.mpd';
    source.setAttribute('src',newsource);  
    video.load();
    //play when ready
    video.play();    
}

太感谢了!

标签: javascripthtmlvideo

解决方案


推荐阅读