繁体   English   中英

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

[英]SoundJS wont play sound from an extension-less MP3

我正准备把这个该死的图书馆扔进垃圾箱。 执行此操作时我对“HowlerJS”没有任何问题,似乎 SoundJS 只是拒绝加载我的 mp3 文件,除非它们有扩展名。

我的代码非常简单,一个充满文件 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 );
        }

而已。 如果我包含 extension.mp3,就会播放声音。 使用当前代码,它不会显示任何错误。 它完全拒绝在 Chrome 上播放声音。 无论如何围绕这个? 或者我将不得不从字面上使用原始位置。

我通过更改我的逻辑工作方式并在加载时获取带有元数据 + 原始文件位置的 object 来修复它。

我在任何地方都找不到至少与.mp3 这个库支持扩展较少的加载。 所以我的逻辑有点像这样。 数据 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);
        });
    }

然后我只需通过该方法加载它,我仍然可以获得我需要的所需逻辑,而无需 .mp3 扩展名。

暂无
暂无

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

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