gpt4 book ai didi

iphone - 您可以使用 list 或网络存储在 iOS 网络应用程序中缓存声音文件吗?

转载 作者:可可西里 更新时间:2023-11-01 03:31:57 25 4
gpt4 key购买 nike

当我将我的 beep-23.mp3 文件添加到缓存 list 时,音效不再在线或离线工作。这是一个错误,还是我做错了什么?

音频在 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();
});
});

<html manifest='index.manifest'>当列出 beep-23.mp3 时使音频停止工作...

更新:可能 Web Storage用来代替缓存 list 来存储音频??

最佳答案

iOS 6 更新:

This is all fixed in iOS 6. You can cache an audio file and play it via javascript without user input.
shaun5 Nov 7 '12 at 0:58


尽管它应该可以工作并且没有规范(W3C、Apple)表明它不应该,但我测试了一些场景,似乎 iOS 上的 Safari 只是拒绝缓存声音文件。

每次我重新加载页面时,Safari 都会加载音频文件(但不是 index.html),因此无论文件大小如何,缓存显然都无法正常工作。

经过一些研究:似乎无法缓存音频文件。因此,您可以在 Apples bugtracker 提交错误.

这是我的代码来证明我的结果:

index.html:

<!DOCTYPE HTML>
<html lang="en-US" manifest="audio.appcache">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<title>Cached audio</title>
</head>
<body>
<h1>Cached audio</h1>
<audio controls autobuffer>
<source src="sample.mp3" type="audio/mpeg" />
</audio>
</body>
</html>

audio.appcache:

CACHE MANIFEST
# 2012-02-23:v1

# explicitly cached
CACHE:
index.html
sample.mp3

.htaccess:

AddType text/cache-manifest .appcache
AddType audio/mpeg .mp3

编辑

我也尝试过使用数据 URI,但是 Safari 一直拒绝音频数据。所以我认为缓存音频是不可能的……

<?php
function data_uri( $file ) {
$contents = file_get_contents( $file );
$base64 = base64_encode( $contents );
return ( 'data:audio/mpeg;base64,'.$base64 );
}
?>
...
<audio controls autobuffer>
<source src="<?php echo data_uri('sample.mp3'); ?>" type="audio/mpeg" />
</audio>
...

编辑 2

好主意,但它看起来不工作...... OS X 的 Safari -> 好的;适用于 iOS 的 Safari -> 仍然是我们之前遇到的相同问题。

<?php
function base_64_string( $file ) {
$contents = file_get_contents( $file );
return base64_encode( $contents );
}
?>
...
<audio controls autobuffer>
<source id="sound-src" src="sample.mp3" type="audio/mpeg" />
</audio>
...
<script>
(function(){
var sound;
if ( localStorage.getItem('cachedSound')) {
sound = localStorage.getItem('cachedSound');
}
else {
sound = "<?php echo base_64_string('sample.mp3'); ?>";
localStorage.setItem('cachedSound',sound);
}
document.getElementById("sound-src").src='data:audio/mpeg;base64,' + sound;
})();
</script>

关于iphone - 您可以使用 list 或网络存储在 iOS 网络应用程序中缓存声音文件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9268023/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com