简体   繁体   中英

Loading soundmanager2 with requirejs amd shim, logs undefined

So here's my main.js file (stripped out all my other scripts for clarity):

require.config({
    paths: {
        'soundmanager2': '../libs/soundmanager2/soundmanager2',
    },
    shim: {
        'soundmanager2': {
            'exports': 'soundManager'
        }
    }
});

Then i'm loading the library like so:

define(['jquery', 'underscore', 'backbone', 'utilities/events', 'utilities/helpers', 'soundmanager2'],

    function($, _, Backbone, events, h, soundManager){

        var TrackModel = Backbone.Model.extend({

            initialize: function() {

                console.log(soundManager);
            }
        });

        return TrackModel;
    }
);

The script is being downloaded - but when I log soundManager, I get undefined, no other errors.

Any ideas? Fear i'm missing something obvious..

I found the usage with requirejs in source code comment, but documentation no description. Here is the example.

define(['soundManager2'], function(SoundManager) {
    var sound = SoundManager.getInstance();
    sound.setup({
      useHTML5Audio: true,
      idPrefix: '',
      onready: function() {},
      ontimeout: function() {}
    });
    sound.beginDelayedInit();
})

在此处输入图片说明

This was an issue with the version of soundmanager2 - it has AMD baked in but I can't get it to export for some reason. I reverted to an earlier version, used the shim, and that fixed it!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM