1

I am using howler.js to play audio and declaring instance as

sound = new Howl({
  src: ['../assets/test.mp3'],
  html5: true,
  onpause: () => {
    this.playButton = true;
  }  });

All works fine but when audio is played , chrome android shows notification of song playing, and when we pause audio through notification it is not detected by howler.js.

Please let me know how to detect it in our code.

Vikram Sapate
  • 1,087
  • 1
  • 11
  • 16

1 Answers1

1

Sounds like a bug, I guess you could open an issue on the project's tracker.

For an ugly workaround, you can access the original HTMLAudioElement through

const elem = sound
  ._sounds[0] // OP has only one media
  ._node; // the DOM element

This element will receive the DOM events appropriately, so you can hook on it directly:

elem.addEventListener('pause', () => {
  this.playButton = true;
});
Kaiido
  • 123,334
  • 13
  • 219
  • 285
  • Thanks @Kaiido for answer. I tried above but it didn' t work. elem is not listening 'pause'. And also when sound is paused through notification "this.sound.playing()" returns true , it's too weird – Vikram Sapate Jul 24 '20 at 12:49
  • For me it definitely worked https://plnkr.co/edit/Dh0OlH3drxAjtrui?open=lib%2Fscript.js – Kaiido Jul 24 '20 at 14:23
  • Thanks @Kaiido. It works, now I can toggle the playButton ,but problem is that when we pause song through notification and again play through houwler.js play() function , the song starts from beginning . There is need of synchronization between these two events. – Vikram Sapate Jul 26 '20 at 12:49