【问题标题】:WAV files will not play on Safari or IOS when served with Nginx使用 Nginx 服务时,WAV 文件将无法在 Safari 或 IOS 上播放
【发布时间】: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


【解决方案1】:

有几个问题: 1) 我的 SSL 证书不正确 2)当我的应用程序位于由 dns 设置的https://someothername 时,我的 SSL 证书正在使用主机名。 3) 我需要在设备上实际安装证书,而不是单击“继续”等。

在我修复了这些问题后,Safari/iOS/OS X 可以正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-11
    • 2014-03-09
    • 1970-01-01
    • 1970-01-01
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多