2017-03-07 97 views
0

看着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: Failed to load because no supported source was found

有無論如何解決這個問題嗎?

+0

請看第一:https://www.google.nl/search?q=DOMException%3A+Failed+to+load +因爲+沒有+支持+源+ + +找到 – mplungjan

+0

找不到任何答案,這就是爲什麼我在這裏問它。 – Sandra

回答

0

我有同樣的錯誤與音頻文件類型,並用它

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.'); 
     }); 
} 
相關問題