一段音乐播放代码,我想让它自动播放,不知道改哪儿,请高手帮忙看下,代码如下 10
varplaybox=(function(){//author:eric_wuvar_playbox=function(){varthat=this;that.box=n...
var playbox = (function(){
//author:eric_wu
var _playbox = function(){
var that = this;
that.box = null;
that.player = null;
that.src = null;
that.on = true;
//
that.autoPlayFix = {
on: false,
evtName: ("ontouchstart" in window)?"touchend":"click"
}
}
_playbox.prototype = {
init: function(box_ele){
this.box = "string" === typeof(box_ele)?document.getElementById(box_ele):box_ele;
this.player = this.box.querySelectorAll("audio")[0];
this.src = this.player.src;
this.init = function(){return this;}
this.autoPlayEvt(false);
return this;
},
play: function(){
if(this.autoPlayFix.on){
this.autoPlayFix.on = true;
this.autoPlayEvt(false);
}
this.on = !this.on;
if(true == this.on){
this.player.src = this.src;
this.player.play();
}else{
this.player.pause();
this.player.src = null;
}
if("function" == typeof(this.play_fn)){
this.play_fn.call(this);
}
},
handleEvent: function(evt){
this.play();
},
autoPlayEvt: function(important){
if(important || this.autoPlayFix.on){
document.body.addEventListener(this.autoPlayFix.evtName, this, false);
}else{
document.body.removeEventListener(this.autoPlayFix.evtName, this, false);
}
}
}
//
return new _playbox();
})();
playbox.play_fn = function(){
this.box.className = this.on?"btn_music on":"btn_music";
} 展开
//author:eric_wu
var _playbox = function(){
var that = this;
that.box = null;
that.player = null;
that.src = null;
that.on = true;
//
that.autoPlayFix = {
on: false,
evtName: ("ontouchstart" in window)?"touchend":"click"
}
}
_playbox.prototype = {
init: function(box_ele){
this.box = "string" === typeof(box_ele)?document.getElementById(box_ele):box_ele;
this.player = this.box.querySelectorAll("audio")[0];
this.src = this.player.src;
this.init = function(){return this;}
this.autoPlayEvt(false);
return this;
},
play: function(){
if(this.autoPlayFix.on){
this.autoPlayFix.on = true;
this.autoPlayEvt(false);
}
this.on = !this.on;
if(true == this.on){
this.player.src = this.src;
this.player.play();
}else{
this.player.pause();
this.player.src = null;
}
if("function" == typeof(this.play_fn)){
this.play_fn.call(this);
}
},
handleEvent: function(evt){
this.play();
},
autoPlayEvt: function(important){
if(important || this.autoPlayFix.on){
document.body.addEventListener(this.autoPlayFix.evtName, this, false);
}else{
document.body.removeEventListener(this.autoPlayFix.evtName, this, false);
}
}
}
//
return new _playbox();
})();
playbox.play_fn = function(){
this.box.className = this.on?"btn_music on":"btn_music";
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询