I cannot reproduce your issue. If I setup a project, according to your description it works just fine.
I created a default project Next.js 15 project:
npx create-next-app@latest
Added an MP3 to public/audio/sample.mp3
Replaced the page.tsx
with:
"use client";
const playDeleteSound = async () => {
try {
const audio = new Audio("/audio/sample.mp3");
await audio.play();
} catch (error) {
console.log("Audio playback error:", error);
}
};
export default function Home() {
return (
<div className="flex items-center justify-center min-h-screen bg-gray-100">
<button
onClick={playDeleteSound}
className="px-6 py-3 rounded-2xl bg-blue-600 text-white text-lg font-semibold shadow-md hover:bg-blue-700 transition"
>
▶ Play Sound
</button>
</div>
);
}
It shows a play button, when I click that, it starts playing the file.
Full project code: https://github.com/Borewit/serve-mp3-with-nextjs