简体   繁体   English

M4A 文件无法在 Safari 中播放,但在 Chrome 中播放

[英]M4A File Not Playing in Safari But Does Play in Chrome

I have an MP3 and a M4A file in <audio> tags.我在<audio>标签中有一个 MP3 和一个 M4A 文件。 The MP3 file plays fine in Safari and Chrome and the M4A file plays fine in Chrome, but the M4A doesn't play in Safari. MP3 文件在 Safari 和 Chrome 中播放良好,M4A 文件在 Chrome 中播放良好,但 M4A 在 Safari 中无法播放。 I can see the audio controls in Safari for the M4A.我可以在 Safari 中看到 M4A 的音频控件。 I click on the play icon, but nothing happens.我点击播放图标,但没有任何反应。

Even for the MP3 file that plays fine in Safari, when I click on the Network tab, I see a "An error occurred trying to load resource."即使对于在 Safari 中播放良好的 MP3 文件,当我单击“网络”选项卡时,我也会看到“尝试加载资源时发生错误”。 message in the Preview tab.预览选项卡中的消息。 I noticed that in Chrome, the Transfer Encoding is coming back as chunked but in Safari it's Identity.我注意到在 Chrome 中,传输编码作为分块返回,但在 Safari 中它是身份。

MP3 response - Safari: MP3 响应 - Safari:

HTTP/1.1 200 OK
Content-Type: audio/mpeg
Content-Disposition: inline; filename=Audio.mp3
X-XSS-Protection: 1
Transfer-Encoding: Identity
Date: Sat, 04 Apr 2020 00:10:29 GMT
Connection: keep-alive
X-Content-Type-Options: nosniff
Accept-Ranges: bytes
X-Frame-Options: SAMEORIGIN
X-Powered-By: Express
X-RequestID: undefined
X-Permitted-Cross-Domain-Policies: none
Strict-Transport-Security: max-age=3600

M4A Response - Safari: M4A 响应 - Safari:

Response
HTTP/1.1 200 OK
Content-Type: audio/mp4
Content-Disposition: inline; filename=Audio.m4a
X-XSS-Protection: 1
Transfer-Encoding: Identity
Date: Sat, 04 Apr 2020 00:10:29 GMT
Connection: keep-alive
X-Content-Type-Options: nosniff
Accept-Ranges: bytes
X-Frame-Options: SAMEORIGIN
X-Powered-By: Express
X-RequestID: undefined
X-Permitted-Cross-Domain-Policies: none
Strict-Transport-Security: max-age=3600

M4 Response - Chrome M4 响应 - 铬

Accept-Ranges: bytes
Connection: keep-alive
Content-disposition: inline; filename=Audio.m4a
Content-Type: audio/mp4
Date: Sat, 04 Apr 2020 00:15:02 GMT
Strict-Transport-Security: max-age=3600
Transfer-Encoding: chunked
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Permitted-Cross-Domain-Policies: none
X-Powered-By: Express
X-RequestID: undefined
X-XSS-Protection: 1

I solved this putting two sources URL's on audio tag;我解决了这个问题,将两个源 URL 放在音频标签上; the same URL with different's way to read the encoding:相同的 URL 读取编码的方式不同:

<audio controls>
    <source src="{.URL}" type="audio/ogg">
    <source src="{.URL}" type="audio/mp4">
</audio>

The server that give the response should have the header Accept-Ranges, to transfer the file chunked by several parts.给出响应的服务器应该有 header 接受范围,以传输由几个部分分块的文件。 You can see more on this answer: Does iPhone/iPad Safari require 'Accept-Ranges' header for video?您可以在此答案中看到更多信息: iPhone/iPad Safari 是否需要“Accept-Ranges”header 用于视频?

I hope that this help.我希望这会有所帮助。

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

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