我只是盯着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

最佳答案

这里的问题不是特别使用jquery,而是将Soundmanager2的配置绑定到DOM-ready事件的事实。 Soundmanager2本身也将其加载例程绑定到此事件,因此,如果在此事件发生之前不执行您的配置代码,则可能已经为时已晚,具体取决于浏览器在其中调用这些事件处理程序的顺序。

我不是SM2专家(从未使用过),但是我偶然发现了管理器的“延迟加载”功能,这可能会有所帮助,因为它应该允许您推迟Soundmanager2的加载过程并在您完成后显式加载配置代码被称为:
http://www.schillmania.com/projects/soundmanager2/doc/getstarted/#lazy-loading

10-07 18:43