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

2024-04-22

我正在尝试使用 SoundManager2 作为 iPhone Web 应用程序的一部分,以便在使用 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 返回的“响应”页面的示例:

Main

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="sm/script/soundmanager2.js"></script>
<script> 
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'
    });

  }

});
</script>

</head>

<body onload="window.top.scrollTo(0,1);">

<div class="scannerform">
  <form id="scanner" name="scanner" method="post" action="ok.php">
    <input type="text" name="scan" id="scan" />
    <input type="submit" name="button" id="button" value="Submit" />
  </form>
</div>

<div class="loadingDiv" id="loadingDiv">Loading...</div>
<div class="wrapper" id="wrapper"><div name="data" id="data"></div></div>

<script>
$('#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);
      }
    );
  });
  </script>
</body>
</html>

Response

<script>
function playSound()
{
  SoundToPlay="ValidSound";
}
</script>

<div id="example">Hello World</div>

感谢您的帮助!

J.


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

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

所以至少检查一下这条线索......

Tomasz

资源:

http://buildingwebapps.blogspot.com/2012/04/state-of-html5-audio-in-mobile-safari.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 http://blog.logicking.com/2012/03/cross-platform-sounds-for-html5-games.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

iPhone 上的 SoundManager2 - 声音无法在 jQuery Load 上播放 的相关文章

随机推荐