【问题标题】:Failed to load because no supported source was found加载失败,因为找不到支持的源
【发布时间】:2017-07-27 17:20:52
【问题描述】:

看着previous answer我萌生了重试播放声音的想法:

soundBG.pause();
soundBG.currentTime = 0;
var soundPromise = soundBG.play();

if (soundPromise !== undefined) {
    soundPromise.then(function() {
        console.log('Sound!');
    }).catch(function(error) {
        console.error('Failed to start your sound, retrying.');
        setTimeout(function(){
            soundEffects();
        }, 2000);
    });
}

但它仍然不工作,当声音不工作时,我不断收到错误:

DOMException: 加载失败,因为找不到支持的源

有办法解决吗?

【问题讨论】:

  • 找不到任何答案,这就是我在这里问的原因。
  • 郑重声明,chrome 和 firefox 似乎不支持 .m4a 文件。

标签: javascript html audio


【解决方案1】:

我在使用音频类型文件时遇到了同样的错误

var url = document.querySelector('audio').src;
var audio = new Audio();
audio.src = url;
var playPromise = audio.play();
if (playPromise !== undefined) {
      playPromise.then(function() {
         audio.addEventListener('timeupdate',function() {
            console.log(audio.currentTime, audio.duration);
         }, true);
      }).catch(function(error) {
            console.error('Failed to start your sound, retrying.');
      });
}

【讨论】:

    猜你喜欢
    • 2016-10-07
    • 1970-01-01
    • 2020-12-30
    • 2017-04-06
    • 2017-10-02
    • 1970-01-01
    • 2018-06-25
    • 2016-09-10
    • 1970-01-01
    相关资源
    最近更新 更多