简体   繁体   中英

SoundJS wont play sound from an extension-less MP3

I'm about ready to chuck this god damn library in the bin. I had no issues with "HowlerJS" when doing this and it seems that SoundJS just refuses to load my mp3 files unless they have an extension.

My code is really simple, an array full of file id's is passed to the register sound function.

   createjs.Sound.on("fileload", Audiocover._, this);
        createjs.Sound.alternateExtensions = ["mp3"];

        for(let i = 0; i < MusicPixels.length; i++)
        {

            debugLog("registered sound: " + "sound-" + i + " (" + resources.sounds[i]  + ")" );

            var sound = {
                path: "/",
                manifest:[
                    {id: "sound-" + i, src: {mp3: "file?id=" + resources.sounds[i]}}
                ]
            }

            createjs.Sound.registerSounds( sound );
        }

That's it. If I include the extension.mp3, sound will play. With the current code, it does not show any errors. It just flat out refuses to play sound on Chrome. Anyway around this? Or will I have to literally use the raw locations.

I fixed it by instead changing how my logic works and grabbing an object with the metadata + raw file locations on load.

I couldn't find anywhere that at least with.mp3's this library supported extension less loading. So my logic kinda goes like this. Data object full of said Sound id's queries API server and API server returns a object with track metadata (like soundcloud) + direct sound URL.

 //returns with an object with the latest .mp3 locations of each of the file ids
 function getResourceLocations(resources, callback)
    {

        $.post( getApiLink("resources"), {
            apikey: Options.apikey,
            resources
        }, function (data) {

            if(data.errors.length!==0)
                throw data.errors[0];

            callback(data);
        });
    }

then i just load it through the method and I can still get the desired logic I require with out a.mp3 extension.

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