简体   繁体   English

SoundJS 无法播放无扩展 MP3 的声音

[英]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.执行此操作时我对“HowlerJS”没有任何问题,似乎 SoundJS 只是拒绝加载我的 mp3 文件,除非它们有扩展名。

My code is really simple, an array full of file id's is passed to the register sound function.我的代码非常简单,一个充满文件 ID 的数组被传递给寄存器 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.如果我包含 extension.mp3,就会播放声音。 With the current code, it does not show any errors.使用当前代码,它不会显示任何错误。 It just flat out refuses to play sound on Chrome.它完全拒绝在 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.我通过更改我的逻辑工作方式并在加载时获取带有元数据 + 原始文件位置的 object 来修复它。

I couldn't find anywhere that at least with.mp3's this library supported extension less loading.我在任何地方都找不到至少与.mp3 这个库支持扩展较少的加载。 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.数据 object 充满了所述声音 ID 的查询 API 服务器和 API 服务器返回带有轨道元数据(如 soundcloud)+ 直接声音 URL 的 object。

 //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.然后我只需通过该方法加载它,我仍然可以获得我需要的所需逻辑,而无需 .mp3 扩展名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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