簡體   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