简体   繁体   English

如何在浏览器中播放 .m4a 文件? (反应/HTML5)

[英]How to play an .m4a file in the browser? (React/HTML5)

I'm building a website that queries the iTunes API, and in the browser I need to be able to play the 30-second song previews associated with each song in the API (which are in .m4a format)我正在构建一个查询 iTunes API 的网站,并且在浏览器中我需要能够播放与 API 中每首歌曲相关联的 30 秒歌曲预览(采用 .m4a 格式)

I've tried playing the file in both of the following ways, but neither worked:我已经尝试通过以下两种方式播放文件,但都没有奏效:

<audio controls="controls">
    <source src={track1} type="audio/m4a" />
</audio>

<video width="320" height="240">
    <source src={track1} type="video/mp4">
    </source>
</video>

When I tried using the audio tag, a media player appeared on the page, but it didn't actually load the file.当我尝试使用音频标签时,页面上出现了一个媒体播放器,但它实际上并没有加载文件。

I've been researching this for a couple of hours but I haven't been able to find a way of accomplishing this (it doesn't seem like it should be this hard).我已经研究了几个小时,但我一直没能找到一种方法来完成这个(它似乎不应该这么难)。 Does anyone have any ideas of how I might make get this working?有没有人对我如何让这个工作有任何想法? Thanks very much非常感谢

Did you check the path of your sound files is correct?您是否检查过声音文件的路径是否正确? I was having this same issue on a React project.我在 React 项目中遇到了同样的问题。

Check the network tab in Dev tools to see what the status code is for your sound file resource.检查开发工具中的网络选项卡以查看声音文件资源的状态代码。 If it's 206 then it's most likely a file path issue:如果是 206,那么很可能是文件路径问题:

开发工具网络选项卡

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

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