0

启用 AdBlock Plus 后,以下测试无法与 Firefox 22.0 一起使用。当我禁用广告拦截时,在 Chrome + 上工作得很好。当我使用脚本标签而不是 requirejs 加载脚本时,它也可以工作。

./index.html:

<!DOCTYPE html>
<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">

<link rel="stylesheet" type="text/css" href="css/main.css"/>
<!--<link rel="icon" type="image/png" href="img/icon.png"/>-->

<!--<script  src="js/lib/jquery.js"></script>-->

<script data-main="js/main" src ="require.js"></script>
<!--
<script src="js/lib/soundmanager2.js"></script>
<script src="js/test.js"></script>
-->

<title></title>
</head>


<body>

<div id="stop" style="cursor:pointer;"> stop</div>

</body>


</html>

./js/main.js:

require.config({
    paths:{
        jquery:"lib/jquery",
        underscore:"lib/underscore",
        soundmanager2:"lib/soundmanager2"
        /*backbone:"lib/backbone",
        detectmobilebrowser:"lib/detectmobilebrowser"*/
    },
    shim: {
        'underscore': {
            exports: '_'
        },
        'soundmanager2':{
            exports:"soundManager"
        }
    }
});


define(['jquery','underscore',"soundmanager2"],
function($,_,soundManager){    
alert("hep");
    window.soundManager=soundManager;
    soundManager.setup({
        url: 'swf',
        useHTML5Audio:true,
        preferFlash: false, // prefer 100% HTML5 mode, where both supported
        onready: function() {

            alert('SM2 ready!');
            /*
            soundManager.createSound({
                id: 'mySound',
                url: './test/test.mp3',
                autoLoad: true,
                autoPlay: false,
                onload: function() {
                    soundManager.play('mySound');
                },
                volume: 50
            });
            */


        },
        ontimeout: function() {
            alert('SM2 init failed!');
        },
        defaultOptions: {
            // set global default volume for all sound objects
            volume: 100
        }
    });

    $("#stop").on("click",function(){
        alert("stop");
        soundManager.stop("mySound");
    });

    return soundManager;
});

控制台中没有错误或任何内容,在最初的“hep!”之后没有警报 一。

4

2 回答 2

0

使用 RequireJS 的 require() 方法来加载一个模块。在回调中写下你需要的代码。请注意,函数的参数是一个数组,其中包含加载依赖项的路径

require.config({
paths:{
    jquery:"lib/jquery",
    underscore:"lib/underscore",
    soundmanager2:"lib/soundmanager2"
    /*backbone:"lib/backbone",
    detectmobilebrowser:"lib/detectmobilebrowser"*/
},
shim: {
    'underscore': {
        exports: '_'
    },
    'soundmanager2':{
        exports:"soundManager"
    }
}
});


require(['jquery','underscore',"soundmanager2"],function($,_,soundManager){    
    alert("hep");
    window.soundManager=soundManager;
    soundManager.setup({
        url: 'swf',
        useHTML5Audio:true,
    preferFlash: false, // prefer 100% HTML5 mode, where both supported
    onready: function() {

        alert('SM2 ready!');
        /*
        soundManager.createSound({
            id: 'mySound',
            url: './test/test.mp3',
            autoLoad: true,
            autoPlay: false,
            onload: function() {
                soundManager.play('mySound');
            },
            volume: 50
        });
        */


    },
    ontimeout: function() {
        alert('SM2 init failed!');
    },
    defaultOptions: {
        // set global default volume for all sound objects
        volume: 100
    }
    });

    $("#stop").on("click",function(){
        alert("stop");
        soundManager.stop("mySound");
    });


});
于 2013-07-30T15:47:46.010 回答
0

经典模式,为一些问题奋斗了几个小时,放弃并寻求帮助,发布后立即找到解决方案。

添加

soundManager.beginDelayedInit();

在 soundManager.setup() 之后,它现在可以工作了。

于 2013-07-28T14:05:36.423 回答