使用Ajax设置html5媒体源

使用Ajax设置html5媒体源,第1张

使用Ajax设置html5媒体源
if (this.mAudioPlayer.canPlayType("audio/mpeg")) {    this.mExtension = '.mp3';}else if (this.mAudioPlayer.canPlayType("audio/ogg")) {    this.mExtension = '.ogg';} else if (this.mAudioPlayer.canPlayType("audio/mp4")) {    this.mExtension = '.m4a'; }this.CreateAudioData = function() {//downloading audio for use in data:uri$.ajax({    url: aAudioSource + this.mExtension + '.txt',    type: 'GET',    context: this,    async: false,    beforeSend: function(xhr) {xhr.setRequestHeader('Authorization', window.userId);},    success: this.EnpreAudioData,    error: function(xhr, aStatus, aError) { HandleError('Audio Error: ' + aStatus); }  });};this.EnpreAudioData = function(aData) {  //this.mAudioData = base64_enpre(aData);  this.mAudioData = aData;  if (this.mExtension == '.m4a') {    Debug("playing m4a");    this.mAudioSrc = "data:audio/mp4;base64," + this.mAudioData;  } else if (this.mExtension == '.ogg') {    Debug("playing ogg");    this.mAudioSrc = "data:audio/ogg;base64," + this.mAudioData;  } else if (this.mExtension == '.mp3') {    Debug("playing mp3");    this.mAudioSrc = "data:audio/mp3;base64," + this.mAudioData;  }};this.play = function() {   if (this.mAudioPlayer.src != this.mAudioSrc) {       this.mAudioPlayer.src = this.mAudioSrc;   }    this.mAudioPlayer.load();    this.mAudioPlayer.play();};

不得不执行asynch:false,否则我会得到一小部分音频,而不是全部音频。尽管删除了异步,最终使调试变得更加容易。



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5016472.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-14
下一篇 2022-11-15

发表评论

登录后才能评论

评论列表(0条)

保存