简体   繁体   English

网页上的音频剪辑

[英]Audio cuts out on webpages

I am working on a website which gives users the option to have the pages read aloud to them.我正在开发一个网站,该网站为用户提供了让他们大声朗读页面的选项。

I am using SoundJS ( https://www.createjs.com/soundjs ) to load in an OGG, MP3, and WAV version of a narration file, and then play it as soon as it finishes loading.我正在使用 SoundJS ( https://www.createjs.com/soundjs ) 加载 OGG、MP3 和 WAV 版本的旁白文件,然后在加载完成后立即播放。 Here is the code:这是代码:

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');
});

On the iPhone X and iPad, in Safari and Chrome, the audio file starts playing, but then cuts out before it finishes.在 iPhone X 和 iPad 上,在 Safari 和 Chrome 中,音频文件开始播放,但在播放结束之前就被切断了。 The audio files on the site range from 7 to over 30 seconds, and the audio always cuts out a few seconds before the end.网站上的音频文件从7秒到30多秒不等,而且音频总是在结束前几秒中断。 For instance, in Chrome, a 10 second clip stops playing after 8 seconds, and a 31 second clip stops playing after 29. In Safari, the same 10 second clip stops after 7 seconds, and the same 31 second clip stops after 22.例如,在 Chrome 中,10 秒剪辑在 8 秒后停止播放,31 秒剪辑在 29 秒后停止播放。在 Safari 中,相同的 10 秒剪辑在 7 秒后停止,相同的 31 秒剪辑在 22 秒后停止。

On all non-iOS devices we've tested, in many different browsers, this issue has never occurred.在我们测试过的所有非 iOS 设备上,在许多不同的浏览器中,这个问题从未发生过。

What is the reason behind this, and what can I do to ensure the audio plays all the way through?这背后的原因是什么,我该怎么做才能确保音频一直播放?

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.只要没有找到针对此问题的解决方案,我们就会将其视为 iOS 移动设备的错误,而不是我们可以控制的。

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.该按钮运行createjs.Sound.play('narration') ,而不是通过文件fileload事件侦听器触发。 For some reason, registering a click on each page before attempting to play audio allows it to play all the way through, reliably.出于某种原因,尝试播放音频之前在每个页面上注册一次点击允许它可靠地一直播放。

Have you tried using the HTML5 audio element?您是否尝试过使用 HTML5 音频元素? 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我添加了一个音频元素“”,它似乎在我的 iPad 中运行良好

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

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