JQuery和SoundManger玩得不好
我只是盯着使用JQuery和SoundManger2,我注意到在使用JQuery的某些情况下SoundManager存在问题。它还取决于是否使用Firefox(3.6.13)或IE(8.0.7600)。
我试图测试的只是天气,我可以播放声音。在每个示例中,我将首先显示代码,在代码之后,我将识别IE和FireFox是成功还是失败。
<html>
<head>
<title></title>
<script type="text/javascript" src="/Project/PublicWebSite/Scripts/soundmanager2.js"></script>
<script type="text/javascript" src="/Project/PublicWebSite/Scripts/jquery-1.5.js"></script>
<script type="text/javascript">
soundManager.debugMode = true;
soundManager.defaultOptions.volume = 50
soundManager.debugFlash = true; // enable flash debug output for this page
soundManager.url = '/Project/PublicWebSite/Scripts/swf/soundmanager2.swf';
soundManager.flashVersion = 8; // optional: shiny features (default = 8)
soundManager.useFlashBlock = false; // optionally, enable when you're ready to dive in
//enable HTML5 audio support, if you're feeling adventurous. iPad/iPhone will always get this.
//soundManager.useHTML5Audio = true;
soundManager.onready(function () {
soundManager.createSound('helloWorld', '/Project/PublicWebSite/Content/Sounds/Chime.mp3');
soundManager.play('helloWorld');
});
</script>
</head>
<body>
</body>
</html>
IE:成功; FireFox:成功
在下面的代码中,除了我在JQuery文档加载中添加SoundManager的配置外,一切都是相同的。
<html>
<head>
<title></title>
<script type="text/javascript" src="/Project/PublicWebSite/Scripts/soundmanager2.js"></script>
<script type="text/javascript" src="/Project/PublicWebSite/Scripts/jquery-1.5.js"></script>
<script type="text/javascript">
$(function () {
soundManager.debugMode = true;
soundManager.defaultOptions.volume = 50
soundManager.debugFlash = true; // enable flash debug output for this page
soundManager.url = '/Project/PublicWebSite/Scripts/swf/soundmanager2.swf';
soundManager.flashVersion = 8; // optional: shiny features (default = 8)
soundManager.useFlashBlock = false; // optionally, enable when you're ready to dive in
//enable HTML5 audio support, if you're feeling adventurous. iPad/iPhone will always get this.
//soundManager.useHTML5Audio = true;
soundManager.onready(function () {
soundManager.createSound('helloWorld', '/Project/PublicWebSite/Content/Sounds/Chime.mp3');
soundManager.play('helloWorld');
});
});
</script>
</head>
<body>
</body>
</html>
IE:成功; FireFox:失败
更改了JQuery和SoundManger脚本引用的顺序
<html>
<head>
<title></title>
<script type="text/javascript" src="/Project/PublicWebSite/Scripts/jquery-1.5.js"></script>
<script type="text/javascript" src="/Project/PublicWebSite/Scripts/soundmanager2.js"></script>
<script type="text/javascript">
$(function () {
soundManager.debugMode = true;
soundManager.defaultOptions.volume = 50
soundManager.debugFlash = true; // enable flash debug output for this page
soundManager.url = '/Project/PublicWebSite/Scripts/swf/soundmanager2.swf';
soundManager.flashVersion = 8; // optional: shiny features (default = 8)
soundManager.useFlashBlock = false; // optionally, enable when you're ready to dive in
//enable HTML5 audio support, if you're feeling adventurous. iPad/iPhone will always get this.
//soundManager.useHTML5Audio = true;
soundManager.onready(function () {
soundManager.createSound('helloWorld', '/Project/PublicWebSite/Content/Sounds/Chime.mp3');
soundManager.play('helloWorld');
});
});
</script>
</head>
<body>
</body>
</html>
IE:失败; FireFox:成功
如果我所做的只是制作静态网页,这不会是一个问题。我正在使用图层等在asp.net MVC中创建代码,并且加载内容的顺序非常重要。这就是我偶然发现这个问题的方法。
因为我是JQuery和SoundManger的菜鸟,所以我做错了很可能。如果有人对如何做得更好有任何意见,我会批评任何答案。我把头撞到我的键盘上一段时间,在我想出来之前,希望这会帮助别人。
更新
当声音无法播放时,我从SoundManager2获取以下信息
- SoundManager 2无法加载(安全/加载错误) -
soundManager.disable():关闭
soundManager:初始化失败。
soundManager:验证/Project/PublicWebSite/Scripts/swf/soundmanager2.swf是否为有效路径。
soundManager:在预期时间内没有Flash响应。可能的原因:加载soundmanager2_debug.swf可能已经失败(和/或Flash 8+不存在?),Flash被阻止或JS-Flash安全性错误。有关更多调试信息,请参阅SWF输出。
soundManager:不耐烦,还在等待Flash ...
soundManager :: initMovie():等待来自Flash的ExternalInterface调用..
soundManager :: initMovie():获得EMBED元素(通过JS创建)
soundManager :: createMovie():尝试加载./soundmanager2_debug.swf
- SoundManager 2 V2.97a.20110123(AS2 / Flash 8),正常轮询 -
我在Firebug和Fiddler中注意到,当我收到此错误时,SoundManger试图找到
soundmanager2_debug.swf @ / project / PublicWebSite / static /。问题是我的swf文件不在那里。这是我的HTML文件所在的位置。
更新
西蒙,指出了我正确的方向。我没有在http://www.schillmania.com/projects/soundmanager2/doc/getstarted/#lazy-loading中提到的soundmanger2.js文件中更改任何内容。
我只是删除了对SoundManger脚本的引用,并使用JQuery ajax调用动态加载脚本。
<html>
<head>
<title></title>
<script type="text/javascript" src="/Project/PublicWebSite/Scripts/jquery-1.5.js"></script>
<script type="text/javascript">
$(function () {
$.ajax({
url: '/Project/PublicWebSite/Scripts/soundmanager2.js',
dataType: 'script',
success:
{
soundManager.debugMode = true;
soundManager.defaultOptions.volume = 50
soundManager.debugFlash = true; // enable flash debug output for this page
soundManager.url = '/Project/PublicWebSite/Scripts/swf/soundmanager2.swf';
soundManager.flashVersion = 8; // optional: shiny features (default = 8)
soundManager.useFlashBlock = false; // optionally, enable when you're ready to dive in
//enable HTML5 audio support, if you're feeling adventurous. iPad/iPhone will always get this.
//soundManager.useHTML5Audio = true;
soundManager.onready(function () {
soundManager.createSound('helloWorld', '/Project/PublicWebSite/Content/Sounds/Chime.mp3');
soundManager.play('helloWorld');
});
}
});
});
</script>
</head>
<body>
</body>
</html>
IE:成功; FireFox:成功
BarDev
没有找到相关结果
已邀请:
2 个回复
黎喊病
扑北爱