java 更改 currenttime_HTML5 audio ,在chrome中设置currentTime无效

打算用audio自己做个播放器,需要用audio标签的currentTime属性,来控制播放进度。但是这个属性在FireFox及ie11下都有效,但就是在chrome下面,设置了无效,不知道各位大神知道原因吗?

代码如下:

.directive('mediaPlayer',function(mediaPlayerConfig,$interval,$timeout){

return {

restrict:'EA',

templateUrl:'template/player.html',

scope:{

playList:'='

},

controller:function($scope){

var player=this;

var conf=mediaPlayerConfig;

var playList=$scope.playList||[];

var $audio,isPlaying=false;

var timer=null;

var index=0;

var audioLike={

currentTime:0,

duration:0,

volume:0

};

player.initialize=function(){

$scope.audioLike=audioLike;

audioLike.volume=$audio.volume;

player.play(index)

};

player.setAudio=function(element){

$audio=element[0];

player._bindEvents(element);

};

player.play=function(file){

var idx;

if(angular.isNumber(file)){

idx=file;

file=playList[idx];

}

if(file){

$audio.src=file[conf.fileUrlProp];

$scope.currentFile=file;

}

$interval.cancel(timer);

timer=$interval(function(){

audioLike.currentTime=$audio.currentTime.toFixed(0);

},1000);

$audio.play();

isPlaying=true;

};

player.pause=function(){

$audio.pause();

isPlaying=false;

$interval.cancel(timer);

};

//播放上一首,如果已经是第一首,则跳到最后一首

player.prev=function(){

index=index===0?

playList.length-1:

index-1;

player.play(index);

};

//播放下一首,如果已经是最后一首,则跳到第一首

player.next=function(){

index=index===(playList.length-1)?

0:

index+1;

player.play(index);

};

player.skipTo=function(sec){

$audio.currentTime=sec;

};

player.togglePlay=function(){

var method=isPlaying?'pause':'play';

player[method]();

};

player.isPlay=function(){

return isPlaying;

};

player.random=function(){

var min=0;

var max=playList.length-1;

var range=max-min;

var rand=Math.random();

rand=min + Math.round(rand * range);

player.play(rand);

};

player._bindEvents=function(element){

element

.on('canplay',function(e){

$scope.$apply(function(){

audioLike.duration=$audio.duration.toFixed(0);

});

})

.on('ended',function(){

//如果允许循环

if(conf.loop){

}

if(conf.random){

player.random();

return;

}

$scope.$apply(function(){

player.next();

});

})

.on('progress',function(e){

console.log(e);

});

};

player.volume=function(volume){

if(angular.isNumber(volume)){

$audio.volume=volume;

}else{

return $audio.volume;

}

};

},

link:function(scope,element,attr,mediaPlayerCtrl){

mediaPlayerCtrl.initialize();

scope.skipTo=function(){

mediaPlayerCtrl.skipTo(250);

};

}

}

})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值