铬视频src更改不起作用 [英] chrome video src change not working

查看:105
本文介绍了铬视频src更改不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码在视频结束后更改视频 src 属性。

视频我将src更改为链接到第二个视频。



IE Firefox 中, >但在Chome 27.XX中 video元素
在更改 src
后似乎已经死亡。



奇怪的是...如果我使用断点来遍历 .ended 函数中的代码,工作正常!

HTML



 < video id =vid1 preload =autowidth =640height =480src =/ Trans / video / sleigh60.mp4controls> 
< / video>

< div style =display:none>
< video id =vid2src =/ Trans / video / sleighRest.mp4preload =auto>
< / video>
< / div>



JavaScript



 < script type =text / javascript> 
var vid2Source ='/Trans/video/sleighRest.mp4';
var video = document.getElementById('vid1');

video.addEventListener(ended,function(){
video.src = vid2Source;
video.load();
video.play();
});
< / script>

THX获得任何帮助。

解决方案

我在Chrome中遇到了与以下代码相同的问题。



我以前的HTML:

 < video preload =autocontrols controlsList =nodownloadwidth =900> 
< source id =vidSrctype =video / mp4/>
< / video>

我以前的javascript是:

  jQuery的( '#vidSrc').attr( 'SRC',的 'http://techslides.com/demos/sample-videos/small.mp4'); 

我正在更新src属性,但未加载视频。所以我已经从视频中删除了源元素,并且正在追加源代码,并且它运行良好。



已更新的Html

 < video id =vidSrcpreload =autocontrols controlsList =nodownloadwidth =900> 
< / video>

更新了js:

  jQuery('#vidSrc')。html('< source src =http://techslides.com/demos/sample-videos/small.mp4type =video / mp4/> gt ;'); 


I use the following code to change a videos src attribute after video ended.

I preload the second video I change the src to link to the second video.

In IE and Firefox this works perfectly but in Chome 27.X.X the video element seems dead after changing the src.

Strange thing is... if I use a breakpoint to step through the code in my .ended function it works fine!

HTML

<video id="vid1" preload="auto" width="640" height="480" src="/Trans/video/sleigh60.mp4" controls>
</video>

<div style="display:none">
    <video id="vid2" src="/Trans/video/sleighRest.mp4" preload="auto">
    </video>
</div>

JavaScript

<script type="text/javascript">
    var vid2Source = '/Trans/video/sleighRest.mp4';
    var video = document.getElementById('vid1');

    video.addEventListener("ended", function() {
        video.src = vid2Source;
        video.load();
        video.play();
    });
</script>

THX for any help.

解决方案

I have faced the same issue in Chrome with the following code.

My previous HTML:

<video  preload="auto" controls controlsList="nodownload" width="900">
    <source id="vidSrc"  type="video/mp4" />
</video>

My previous javascript was:

jQuery('#vidSrc').attr('src','http://techslides.com/demos/sample-videos/small.mp4');

I was updating the src attribute but video was not being loaded. So I have removed source element from video and source is being appended and it is working well.

Updated Html

<video id="vidSrc"  preload="auto" controls controlsList="nodownload" width="900">
</video>

Updated js:

jQuery('#vidSrc').html('<source src="http://techslides.com/demos/sample-videos/small.mp4" type="video/mp4" />');

这篇关于铬视频src更改不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆