2013-07-26 82 views
0

我在我的HTML页面中使用了声音,并编写了JavaScript函数在特定时间播放。问题是,当我在PC中加载页面时,它运行良好,但在移动设备上,声音无法播放。哪里不对?声音不能在手机上播放

<audio id="buzzer" controls="controls"> 
<source src="assets/sound/buzzer.mp3" type="audio/mpeg" /> 
function PlaySound1() { 
    var audioElement = document.getElementById('buzzer'); 
    audioElement.setAttribute("preload", "auto"); 
    audioElement.autobuffer = true; 

    var source1 = document.createElement('source'); 
    source1.type= 'audio/mpeg'; 
    source1.src= 'buzzer.mp3'; 
    audioElement.appendChild(source1); 

    audioElement.load(); 
    audioElement.play(); 
}; 
+0

你是什么意思的手机? iPhone,Android,Blackberry等?哪个浏览器? –

+0

android和iphone –

+0

移动音频需要用户交互才能启动。什么叫PlaySound1? –

回答

0

您可以尝试UbaPlayer,它配备了闪光灯后备旧版本浏览器。 (从HTML5 Doctor: HTML5 Audio – The State of Play

Mobile Browser        Version   Codec Support 
Opera Mobile        11.0+   Device-dependent 
Android          2.3+   Device-dependent 
Mobile Safari (iPhone, iPad, iPod Touch) iOS 3.0+  MP3, AAC 
Blackberry         6.0+   MP3, AAC 
+0

有用的文章,因为我发现它取决于操作系统和浏览器,但无论如何要在所有这些文章上播放? –

+0

我会给UbaPlayer一个镜头。 – estrar

+0

我看到了链接,但不明白如何使用它,你能告诉我更多吗? –

0

支持表你检查出的浏览器支持http://www.w3schools.com/html/html5_audio.asp

+0

中查看演示,那么该怎么做?我如何在每个浏览器上播放它?可能吗? –

+0

看看这个问题[http://stackoverflow.com/questions/17791602/sound-notifications-in-opera/17798990#17798990](http://stackoverflow.com/questions/17791602/sound-notifications-in-opera/17798990#17798990) – DejanG

1

大多数手机浏览器需要直接,物理相互作用开始音频播放表。这意味着您无法在网页加载或任何异步功能(如setTimeout)中触发初始播放。