網頁上的音頻被截斷 (Audio cuts out on webpages)


問題描述

網頁上的音頻被截斷 (Audio cuts out on webpages)

我正在開發一個網站,讓用戶可以選擇讓他們大聲朗讀頁面。

我正在使用 SoundJS (https://www.createjs.com/soundjs) 加載 OGG、MP3 和 WAV 版本的旁白文件,然後在完成後立即播放加載。以下是代碼:

var narration = {
    path: '../assets/sounds/',
        manifest: [
            {
                id: 'narration',
                src: {
                    mp3: 'narration.mp3',
                    ogg: 'narration.ogg',
                    wav: 'narration.wav'
                }
            }
        ]
    };

createjs.Sound.alternateExtensions = ['mp3', 'wav'];
createjs.Sound.registerSounds(narration);
createjs.Sound.addEventListener('fileload', function(){
    createjs.Sound.play('narration');
});

在 iPhone X 和 iPad 上,在 Safari 和 Chrome 中,音頻文件開始播放,但在播放結束之前就中斷了。網站上的音頻文件從 7 秒到 30 多秒不等,而且音頻總是在結束前幾秒鐘被切斷。例如,在 Chrome 中,10 秒的剪輯在 8 秒後停止播放,31 秒的剪輯在 29 秒後停止播放。在 Safari 中,相同的 10 秒剪輯在 7 秒後停止,


參考解法

方法 1:

As long as there is no solution found for this issue, we're considering it a bug with iOS mobile devices, and not something we can control.

As a workaround, we've implemented a button on each page that the user must click before the audio plays. The button runs createjs.Sound.play('narration'), rather than it being triggered through the fileload event listener. For some reason, registering a click on each page before attempting to play audio allows it to play all the way through, reliably.

方法 2:

Have you tried using the HTML5 audio element? Simply add it as an element that appears over the Canvas. I added an audio element, "", and it seems to work well in my iPad

(by SpyderScriptSpyderScriptLuci )

參考文件

  1. Audio cuts out on webpages (CC BY‑SA 2.5/3.0/4.0)

#safari #google-chrome #iOS #soundjs






相關問題

如何讓 <asp:menu> 在 Safari 中工作? (How can I get <asp:menu> working in Safari?)

jQuery 航點在 Safari 中不起作用 (jQuery waypoints not working in Safari)

iOS WebApp 不顯示啟動圖像 (iOS WebApp not showing startup image)

Jquery、Javascript 點擊菜單在 IE 和 Safari 上不起作用 (Jquery, Javascript click menu doesnt work on IE and Safari)

如果我沒有 Mac 和 Safari,我將如何重現 Javascript 錯誤? (How am I going to reproduce Javascript bugs if I don't have a Mac & Safari?)

Webkit 中的全局 Javascript 變量 (Global Javascript variables in Webkit)

Safari IndexOutOfRangeException (safari IndexOutOfRangeException)

Safari 2.0 中修改鍵的鍵盤事件 (Keyboard Events for Modifier Keys in Safari 2.0)

通過 HTML 在 Mobile Safari 上實現 UIPickerview (Implement UIPickerview on Mobile Safari via HTML)

Safari 的 jQuery 問題 (jQuery problem with Safari)

網頁上的音頻被截斷 (Audio cuts out on webpages)

當選項卡不活動時,保持 JS/jQuery 代碼在 Safari 中工作 (Keep the JS/jQuery code working in Safari when the tab is not active)







留言討論