Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play An MP3 in Angular Using <audio> Tag

Tags:

angular

Very new to Angular. I'm trying to play a hard-coded mp3 file with Angular

I have the mp3 file in the same path as my component, and I'm trying to use the tag like:

<audio controls src={{./name-of-file.mp3}}></audio>

However, this is not working. Is there a straightforward way to hardcode a brief mp3 file into my app?

like image 264
Jon Avatar asked Sep 12 '25 16:09

Jon


2 Answers

Okay, actually it looks like Angular just didn't like the file location. Moving the audio file to another folder did the trick: <audio controls><source src="../../audio/name-of-file.mp3" type="audio/mpeg" /></audio>

like image 78
Jon Avatar answered Sep 14 '25 09:09

Jon


any img/icon/music should be put in the assets folder

or you could configure in angular.json other assets folders paths

like image 22
JiBi Avatar answered Sep 14 '25 07:09

JiBi