第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

HTML5 audio ,在chrome中設(shè)置currentTime無(wú)效

HTML5 audio ,在chrome中設(shè)置currentTime無(wú)效

慕村225694 2019-04-10 20:49:12
打算用audio自己做個(gè)播放器,需要用audio標(biāo)簽的currentTime屬性,來(lái)控制播放進(jìn)度。但是這個(gè)屬性在FireFox及ie11下都有效,但就是在chrome下面,設(shè)置了無(wú)效,不知道各位大神知道原因嗎?代碼如下:.directive('mediaPlayer',function(mediaPlayerConfig,$interval,$timeout){return{restrict:'EA',templateUrl:'template/player.html',scope:{playList:'='},controller:function($scope){varplayer=this;varconf=mediaPlayerConfig;varplayList=$scope.playList||[];var$audio,isPlaying=false;vartimer=null;varindex=0;varaudioLike={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){varidx;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);};//播放上一首,如果已經(jīng)是第一首,則跳到最后一首player.prev=function(){index=index===0?playList.length-1:index-1;player.play(index);};//播放下一首,如果已經(jīng)是最后一首,則跳到第一首player.next=function(){index=index===(playList.length-1)?0:index+1;player.play(index);};player.skipTo=function(sec){$audio.currentTime=sec;};player.togglePlay=function(){varmethod=isPlaying?'pause':'play';player[method]();};player.isPlay=function(){returnisPlaying;};player.random=function(){varmin=0;varmax=playList.length-1;varrange=max-min;varrand=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(){//如果允許循環(huán)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);};}}})
查看完整描述

2 回答

?
HUH函數(shù)

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超4個(gè)贊

剛正好遇到這個(gè)問(wèn)題,錯(cuò)誤發(fā)生在idea自帶server在播放本地音頻,soundmanagersetPosition時(shí)自動(dòng)歸零。
經(jīng)驗(yàn)證是和responseheader有關(guān)的。我通過(guò)對(duì)MP3資源set不同的responseheader來(lái)驗(yàn)證,結(jié)果如下(貌似segmentfault不支持markdown的表格,所以下面排版有點(diǎn)亂。):ieContent-Type必須,當(dāng)我設(shè)為audio/mpeg時(shí)才能播放,設(shè)為application/octet-stream不能。Content-Length必須。和Accept-Ranges無(wú)關(guān)。
chromeContent-Type無(wú)關(guān),設(shè)為application/octet-stream可以播放。Content-Length,Accept-Ranges必須都有才可更改currentTime。
也就是說(shuō)ie需要responseheader有正確的Content-Type,Content-Length。chrome需要頭部有Content-Length和Accept-Ranges。(Firefox沒(méi)測(cè))
還有,MDN上的ConfiguringserversforOggmedia中有更詳細(xì)的描述:
HandleHTTP1.1byterangerequestscorrectly
Inordertosupportseekingandplayingbackregionsofthemediathataren'tyetdownloaded,GeckousesHTTP1.1byte-rangerequeststoretrievethemediafromtheseektargetposition.Inaddition,Geckousesbyte-rangerequeststoseektotheendofthemedia(assumingyouservetheContent-Lengthheader)inordertodeterminethedurationofthemedia.
YourservershouldaccepttheAccept-Ranges:bytesHTTPheaderifitcanacceptbyte-rangerequests.Itmustreturn206:Partialcontenttoallbyterangerequests;otherwise,browserscan'tbesureyouactuallysupportbyterangerequests.
Yourservermustalsoreturn"206:PartialContent"fortherequest"Range:bytes=0-"aswell....
以上,第一次在segmentfault回答問(wèn)題,如有錯(cuò)漏,歡迎指正。
                            
查看完整回答
反對(duì) 回復(fù) 2019-04-10
  • 2 回答
  • 0 關(guān)注
  • 561 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)