Playing an mp3 file from the assets folder with Angular?

31 Views Asked by At

Trying to play an mp3 file with howler.js from the assets folder in the latest version of Angular.

I put an MP3 in src/assets/mp3/lost-in-sands-126335.mp3.

 audio % ls src/assets/mp3/lost-in-sands-126335.mp3 
src/assets/mp3/lost-in-sands-126335.mp3

This is what I have within the constructor of app.component:

  mp3URL:string = 'assets/mp3/lost-in-sands-126335.mp3';
  constructor() {
     const song = new Howl({
      //  autoplay: true,
      loop: true,
      volume: 1,
      format: ['mp3'],
      src: [this.mp3URL],
    });    
   song.play();
   console.log(`IS THE SONG PLAYING: `, song.playing());

When the application is served ng serve -o the song does not start playing (The console log of song.playing() is false.

Any ideas?

0

There are 0 best solutions below