iPhone上的SoundManager2 – 声音无法在jQuery Load上播放

我正在尝试使用SoundManager2作为iPhone Web App的一部分,在使用jQuery提交表单后播放声音。 播放的特定声音取决于结果,因此生成的页面设置一个变量,用于标识要播放的声音文件。

这一切都在桌面上顺利运行,但在iPhone上运行时,它会失败。

iPhone上的调试控制台显示它正在尝试…

1124: SMSound.play(): "ValidSound" is loading - attempting to play... 1124: SMSound.play(): "ValidSound" is starting to play 1124: setPosition(0): delaying, sound not ready 1124: HTML5::loadstart: ValidSound 1124: HTML5::suspend: ValidSound 

……但每次播放都没有声音。

关于可能导致此失败的原因的任何想法? 我已经包含了主页面的代码,以及使用jQuery返回的“响应”页面的示例:

主要

      soundManager.setup({ url: 'sm/swf/', useHTML5Audio: true, onready: function() { soundManager.createSound({ id: 'ValidSound', useHTML5Audio: true, preferFlash: false, url: 'http://www.example.com/example sound.mp3' }); } });    
Loading...
$('#loadingDiv') .hide() .ajaxStart(function() { $(this).show(); }) .ajaxStop(function() { $(this).hide(); }) ; $("#scanner").submit(function(event) { $("#loadingImage").show(); event.preventDefault(); var $form = $( this ), scanned_data = $form.find( 'input[name="scan"]' ).val(), url = $form.attr( 'action' ); $.post( url, { scanned_data: scanned_data }, function( data ) { var content = $( data ); $( "#data" ).empty().append( content ); $("#loadingImage").hide(); if (playSound) playSound(); soundManager.play(SoundToPlay); } ); });

响应

  function playSound() { SoundToPlay="ValidSound"; }  
Hello World

谢谢你的帮助!

J.

你知道iPhone Safari有声音限制吗? 基本上,如果没有用户以某种方式与页面交互(通过触摸屏),它将不会播放声音。 所以忘记通过“onLoad”或任何其他事件播放的自动声音。

有了SoundManager2和我的iPhone,我发现它有时候有点棘手……我很确定它在我的应用程序中手指点击至少一次后自动播放声音(甚至几个)(例如关闭初始html弹出窗口(基本上) ))

所以至少检查这个线索……

托马斯

资源:

http://buildingwebapps.blogspot.com/2012/04/state-of-html5-audio-in-mobile-safari.html

http://blog.logicking.com/2012/03/cross-platform-sounds-for-html5-games.html