您可以使用清单或 Web 存储在 iOS Web 应用程序中缓存声音文件吗?
当我将 beep-23.mp3 文件添加到缓存清单时,声音效果不再在线或离线工作。这是一个错误,还是我做错了什么?
音频位于 html 文件中,如下所示:
function playBEEP() { if (navigator.platform == "iPad" || navigator.platform == "iPhone" || navigator.platform == "iPod") { Beep.play(); } }
if (navigator.platform == "iPad" || navigator.platform == "iPhone" || navigator.platform == "iPod") {
var Beep = document.createElement('audio');
Beep.setAttribute('src', 'beep-23.mp3');
}
通过以下方式访问:
$("#mybutton,#anotherbutton").each(function() {
$(this).bind("touchstart",function(e){
playBEEP();
});
});
使音频在列出 beep-23.mp3 时停止工作...
更新:可以使用网络存储代替缓存清单来存储音频吗?
When I add my beep-23.mp3 file to the cache manifest, the sound effect no longer works on or offline. Is this a bug, or am I doing something wrong?
The audio is within an html file as:
function playBEEP() { if (navigator.platform == "iPad" || navigator.platform == "iPhone" || navigator.platform == "iPod") { Beep.play(); } }
if (navigator.platform == "iPad" || navigator.platform == "iPhone" || navigator.platform == "iPod") {
var Beep = document.createElement('audio');
Beep.setAttribute('src', 'beep-23.mp3');
}
Accessed via:
$("#mybutton,#anotherbutton").each(function() {
$(this).bind("touchstart",function(e){
playBEEP();
});
});
<html manifest='index.manifest'>
makes the audio stop working when beep-23.mp3 is listed...
UPDATE: Could Web Storage be used instead of the cache manifest to store the audio??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
iOS 6 更新:
尽管它应该可以工作,并且没有规范(W3C、Apple)表明它应该工作' t,我测试了一些场景,iOS 上的 Safari 似乎只是拒绝缓存声音文件。
每次我重新加载页面时,Safari 都会加载音频文件(但不是index.html),因此无论文件大小如何,缓存显然都无法正常工作。
经过一些研究:看起来不可能缓存音频文件。因此,您可以在 Apple bugtracker 上提交错误。
这是我的代码来证明我的结果:
index.html:
audio.appcache:
.htaccess:
编辑
我也尝试使用数据 URI,但是 Safari 一直拒绝音频数据。所以我认为不可能缓存音频...
编辑 2
好主意,但看起来它不起作用... Safari for OS X ->好的; iOS 版 Safari ->还是和我们之前遇到的问题一样。
UPDATE for iOS 6:
Even though it should work and there are no specifications (W3C, Apple) which say it shouldn't, I tested some scenarios and it seems like Safari on iOS is just refusing to cache the sound files.
Safari is loading the audio file (but not the index.html) every time I reload the page, so caching is apparently not working correct regardlessly of file size.
After some research: It looks like it's not possible to cache audio files. So you may file a bug at Apples bugtracker.
Here's my code to prove my results:
index.html:
audio.appcache:
.htaccess:
EDIT
I also tried using data URIs but, that Safari keeps refusing the audio data. So I think it's not possible to cache audio …
EDIT 2
Great idea, but it looks like it's not working … Safari for OS X -> ok; Safari for iOS -> still the same problem as we had before.
如果您还没有这样做,则必须确保 URL 路径是绝对路径或相对于 .manifest 而不是实际网页。
您当前尝试缓存的实际组件的大小也有限制,为 4MB。
总缓存限制为 5MB。
我也很确定你不能缓存音频和视频文件。
If you haven't already you have to make sure that URL paths are absolute or relative to the .manifest and not the actual webpage.
There is also a limit to the size of the actual component that you are trying to cache currently at 4MB.
The total cache limit is 5MB.
I'm also pretty sure you can not cache audio and video files.
Apple 不支持通过 safari 播放音频,这是有意防止人们使用在线域来存储您的音乐而不付费并使用您的 iPod/iPhone 来播放它们。这是苹果试图让你为音乐付费的方式。对不起各位。
Apple do not support playing audio via safari, this is intentional to prevent people using online domains to store you music without paying for them and using you iPod/iPhone to play them. It's apples way of trying to make you pay for music. Sorry guys.