SoundManager2 iPhone上 - 声音不玩jQuery的负载 [英] SoundManager2 on iPhone - Sound not playing on jQuery Load
问题描述
我试图用SoundManager2作为iPhone Web应用程序的一部分的形式已被使用jQuery提交后播放声音。被播放的特定声音取决于结果,因此所得到的页设置标识要播放的声音文件的变量。
I'm trying to use SoundManager2 as part of an iPhone Web App to play a sound after a form has been submitted using jQuery. The particular sound that is played is dependant on the result, and so the resulting page sets a variable that identifies which sound file to play.
这所有的作品,而不在桌面上顺利,但在iPhone上运行时,它失败。
This all works without a hitch on the desktop, but when running on the iPhone, it fails.
在iPhone上调试控制台显示它尝试...
The Debugging Console on the iPhone shows it trying...
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
......但每一个戏剧没有声音。
...but no sound every plays.
这是什么可能导致此失败有什么想法?我已经包含了code为主要页面,而响应页面,则使用jQuery退换的例子:
Any thoughts on what might be causing this to fail? I've included the code for the main page, and an example of the 'responding' page that is returned using jQuery:
主要
<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>
响应
<script>
function playSound()
{
SoundToPlay="ValidSound";
}
</script>
<div id="example">Hello World</div>
感谢您的帮助!
学家
推荐答案
您知道iPhone Safari浏览器已申请健全限制?基本上,它不会在未得到用户(通过触摸屏)与页面交互莫名其妙地播放声音。
所以,不要担心自动声被通过的onLoad或任何其他事件的播放。
You do know iPhone Safari has sound limitations applied? Basically it will not play sound without user interacting with a page somehow (via touching screen). So forget about automatic sound being played via "onLoad" or any other event.
使用SoundManager2和我的iPhone,虽然,我觉得有点棘手,有时...我pretty确保它播放声音(甚至数)后自动手指我点击我的应用程序至少1时间(例如关闭初始HTML弹出窗口(基本上))
With SoundManager2 and my iPhone though, I find it a bit tricky sometimes.. I'm pretty sure it plays sound (even several) automatically after I finger-click at least 1 time in my app (for example closing initial html popup ( basically))
因此,检查此导线至少...
So check this lead at least...
托马斯
资源:
<一个href=\"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
<一个href=\"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
这篇关于SoundManager2 iPhone上 - 声音不玩jQuery的负载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!