使用javascript更改视频src

时间:2016-08-22 14:03:12

标签: javascript

我有两个版本视频的HTML代码,我正在尝试使用视频1的src自动更改视频2的src 视频1代码:

<div id="TopPane5VideoPlayer_TopPlayer">
     <div id="TopPane5VideoPlayer_divInternalT">
           <object type="application/x-shockwave-flash" data="../player.swf?url=Root/Videos/3/17-08-2016/742393_ocean.mp4&amp;volume=90&amp;autoPlay=true&amp;previewImageUrl=../Root/Videos/3/17-08-2016/1920X955742393_ocean.jpg" width="1920" height="955" wmode="opaque" id="video_overlay">
            </object>
       </div>

视频2:

<div class="sl-video">
<video autoplay>
        <source src="video/trailer.mp4" type="video/mp4; codecs="avc1.42E01E, mp4a.40.2"">
        <source src="video/trailer.webm" type="video/webm; codecs="vp8, vorbis"" />
            Video not supported.
</video>

1 个答案:

答案 0 :(得分:0)

试试这个:

Array.from(document.querySelectorAll('source')).map(x => x.remove())
document.querySelector('video').src = 
  document.querySelector('object').getAttribute('data').match(/url=([^&]+)&/)[1]