简体   繁体   English

HTML5移动网络应用上的音频延迟

[英]Audio delay on HTML5 mobile web app

I'm developing a mobile web app using HTML5 & Javascript. 我正在使用HTML5和Javascript开发移动Web应用程序。 The goal is to have a page with buttons that play sound after touch events, using the HTML5 audio tag. 目的是要创建一个带有按钮的页面,该按钮使用HTML5音频标签在触摸事件后播放声音。 But I'm noticing a significant delay between the touch event and the sound being played, even after the audio file has been cached. 但我注意到,即使在缓存了音频文件之后,触摸事件和正在播放的声音之间也会有很大的延迟。 I think this may be due to the way iOS Safari handles sound but I'm not sure. 我认为这可能是由于iOS Safari处理声音的方式引起的,但我不确定。 Are there any solutions or creative workarounds to this issue? 是否有解决此问题的方法或创造性的解决方法? How can I minimize the delay between the touch event and playback? 如何最小化触摸事件和播放之间的延迟?

The audio delay may be because of buffering issues in iOS that are there due to cellular data charges. 音频延迟可能是由于蜂窝数据收费导致的iOS中的缓冲问题所致。 The user has to explicitly trigger the event in order for the content to start being downloaded. 用户必须明确触发事件,才能开始下载内容。

In Safari on iOS (for all devices, including iPad), where the user may be on a cellular network and be charged per data unit, preload and autoplay are disabled. 在iOS上的Safari(适用于包括iPad在内的所有设备)上的Safari中,用户可能位于蜂窝网络上,并按数据单元收费,因此禁用了预加载和自动播放功能。 No data is loaded until the user initiates it. 在用户启动数据之前,不会加载任何数据。 This means the JavaScript play() and load() methods are also inactive until the user initiates playback, unless the play() or load() method is triggered by user action. 这意味着除非用户操作触发了play()或load()方法,否则JavaScript play()和load()方法在用户启动播放之前也处于无效状态。 In other words, a user-initiated Play button works, but an onLoad="play()" event does not. 换句话说,用户启动的“播放”按钮有效,但onLoad =“ play()”事件无效。

- https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html#//apple_ref/doc/uid/TP40009523-CH5-SW1 -https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html#//apple_ref/doc/uid/TP40009523-CH5-SW1

=== EDIT === ===编辑===

One potential improvement is to use lower bitrate/ higher compressed audio for mobile products. 一种潜在的改进是为移动产品使用较低的比特率/较高的压缩音频。 The quality will, however, be significantly reduced. 但是,质量将大大降低。 Use only if it is acceptable in your application. 仅在您的应用程序可接受的情况下使用。

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

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