【发布时间】:2016-06-20 23:17:34
【问题描述】:
我有一个带有音频元素的 Web 应用程序,当从 gunicorn 或开发服务器提供服务时,它可以在所有浏览器和平台上正常运行。
当使用 Nginx 提供服务时,WAV 文件将无法在 IOS 或 Safari/OS X 上播放。如果我在音频元素上启用“控件”,我会得到“正在加载”并且没有任何反应。没有错误,没有声音,什么都没有。
相关 HTML/Javascript:
<audio id='audio' controls>
<source id='audioSource' src='' type='audio/wav'>
Your browser does not support this audio tag.
</audio>
<button type='button' onclick='previewSound()'><i class='fa fa-volume-up fa-lg'></i></button>
function previewSound() {
// Get the id of the message box
// which is also the id of the record
// and the name of the wav file. :)
var messageId = $('#messageSel').val();
if(messageId=='') return;
// Set up the audio element.
var myAudio = document.getElementById("audio");
var mySource = document.getElementById("audioSource");
mySource.src = '/dynamic/Message/' + messageId + '.wav';
// Play the sound
myAudio.load();
myAudio.play();
}
相关的/etc/nginx/sites-enabled/*:
server {
...
location /dynamic {
try_files $uri $uri/ =404;
}
...
}
相关的/etc/nginx/mime.types:
audio/wav wav; /* also tried audio/x-wav wav; */
相关文件:
root@b827ebd0459d:/var/www/product/dynamic/Message# ls -al
total 1316
drwxrwxrwx 2 www-data www-data 4096 Jun 20 23:09 .
drwxrwxrwx 3 www-data www-data 4096 May 30 14:20 ..
-rw-rw-rw- 1 www-data www-data 229420 Jun 15 18:35 1.wav
-rw-rw-rw- 1 www-data www-data 344108 Jun 18 21:50 2.wav
-rw-rw-rw- 1 www-data www-data 753708 Jun 9 17:25 3.wav
感谢您提出任何疑难解答建议。我已经阅读了其他类似的问题/答案,但它们似乎没有解决这个特定问题。
【问题讨论】:
-
这是由于我使用的是本地生成的 SSL 证书。我正在开发一个需要 SSL 的独立无线系统,以便 getUserMedia 和 html5 音频工作,但系统无法验证证书。
标签: nginx safari html5-audio