html5 video使用autoplay属性时,声音混乱

html5 video使用autoplay属性时,声音混乱

页面代码

Index.html

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test</title> 
<meta charset='utf-8'/>
<script src="js/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="js/thml5.js" type="text/javascript"></script>
<script type="text/javascript">

window.onload=function(){
$('#channel1').click(function(){
setConfig("test1.mp4");
});

$('#channel2').click(function(){
setConfig("test2.mp4");
});

$('#channel3').click(function(){
setConfig("test3.mp4");
});
}


function setConfig(url){
var jo=$('#test1');
var cfg=HTML5MediaService.getDefaultConfig();
 cfg=$.extend(cfg, {url: url});
HTML5MediaService.create(jo,cfg);
}

</script>
</head>
<body>
<div id='test1' style="height:300px;width:500px;">

</div>
</br>
</br>
</br>
<div>
<span id='channel1'>频道1</span>
<span id='channel2'>频道2</span>
<span id='channel3'>频道3</span>
</div>
</body>
</html>

 

js代码
html5.js

var HTML5MediaService= {
    getDefaultConfig: function () {
        return $.extend({}, {width: "100%", height: "100%", controls: "controls", autoplay: "autoplay"});
    },
    create:function(jo,cfg){
         this.videoId = "videojs_" + new Date().getTime().toString();
        var videoJo = $('<video' +
            ' id="' + this.videoId + '"' +
            ' src=' + cfg.url +
            ' controls=' + cfg.controls +
            ' autoplay=' + cfg.autoplay +
            ' width=' + cfg.width +
            ' height=' + cfg.height +
            ' preload=none' +
            '></video>');
        videoJo.appendTo(jo.empty());
    }  
   }

 

我的解决方案:

取掉autoplay,可以使用play()函数来达到自动播放功能;

 

有不同解决方案的可以分享,谢谢!

 

posted @ 2016-12-09 14:45  土豆哥  阅读(1650)  评论(0编辑  收藏  举报