如何使用 next.js 导入 mp3 文件?

发布于 2025-01-11 17:31:58 字数 487 浏览 3 评论 0原文

我正在尝试将 mp3 文件导入到我的 next.js 项目 - 在此处输入图像描述

我想从 AudioPlayer.js 访问文件“DRUMS.mp3”,所以我编写了

从以下位置导入鼓'../resources/DRUMS.mp3';

但这出现了:

在此处输入图像描述

我还安装了 - 'npm install file-loader --save-dev' 但这没有帮助。

感谢所有回复者!

I'm trying to import mp3 files to my next.js project - enter image description here

I want to access the file 'DRUMS.mp3' from AudioPlayer.js so I wrote

import drums from '../resources/DRUMS.mp3';

but this comes up:

enter image description here

I've also installed - 'npm install file-loader --save-dev'
but that didn't help.

Thanks to all responders!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灰色世界里的红玫瑰 2025-01-18 17:31:58

您可以使用 html audio 标签来播放它 - 将其放在公共文件夹中,然后直接引用它们,即

 <audio
        controls
        src="/DRUMS.mp3">
            Your browser does not support the
            <code>audio</code> element.
    </audio>

如果您想进一步与音频 api 交互,您可以使用 webaudio API - https://www.html5rocks.com/en/tutorials/webaudio/intro/

You could just use an html audio tag to play it - place it in the public folder and then reference them directly, i.e

 <audio
        controls
        src="/DRUMS.mp3">
            Your browser does not support the
            <code>audio</code> element.
    </audio>

If you want to further interact with the audio api, you could use the webaudio API - https://www.html5rocks.com/en/tutorials/webaudio/intro/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文