howler.js icon indicating copy to clipboard operation
howler.js copied to clipboard

Keyboard controls (play/pause) working on howl object but not triggering onpause/onplay callbacks

Open bar2 opened this issue 6 years ago • 10 comments

Env: OS: Mac OS X Mojave - 10.14.4 (18E226) Browser: Google Chrome 74.0.3729.108 (Official Build) (64-bit)

Background: 1- Initiate a howl object with onplay, onpause callbacks, 2- Via interface: howl objects play/pause correctly, callbacks being called, 3- Via keyboard controls (media controls for play/pause): howl objects play/pause correctly, callbacks are not being called.

I can provide code or live example to this.

bar2 avatar Apr 30 '19 21:04 bar2

I'm not sure I follow what the issue you are describing is. Code example would be helpful, thanks.

goldfire avatar Jul 05 '19 18:07 goldfire

+1

Play/Pause from my keyboard is actually playing or pausing playback but onplay/onpause callbacks are not fired, so my UI doesn't reflect the state change.

I couldn't find any documentation on how to detect keydown events from those media keys on macOS as well.

gugiserman avatar Jul 29 '19 18:07 gugiserman

Same for me I want to dispatch redux actions when i play or pause but pressing play pause on keyboard is not triggering callbacks. It breaks my whole app

blakyris avatar Nov 29 '19 00:11 blakyris

+1 for this. My UI looks buggy without those callbacks firing when the keyboard media keys are used.

damirkotoric avatar Dec 11 '19 13:12 damirkotoric

+1 This is also happening when toggling the playstate from the windows 10 panel image

Almo7aya avatar Dec 17 '19 09:12 Almo7aya

+1 I encountered the same problem, and I hope that I can have corresponding events and callbacks when using the media key

ChanMenglin avatar Jan 09 '20 02:01 ChanMenglin

Any workaround for this ?

Pabloitto avatar Apr 26 '20 20:04 Pabloitto

Workaround: Was able to tap into the navigator's mediaSession using Chrome 83 and bind the events to the play/pause functionality. Tested additionally on Safari 13.1.1, but Media Session API support doesn't seem to exist.

const howl = new Howl({/* initializers */});
if (navigator && navigator.mediaSession) {
      navigator.mediaSession.setActionHandler('play', () => howl.play());
      navigator.mediaSession.setActionHandler('pause', () => howl.pause());
}

Kevin-K avatar Jun 05 '20 14:06 Kevin-K

Workaround: Was able to tap into the navigator's mediaSession using Chrome 83 and bind the events to the play/pause functionality. Tested additionally on Safari 13.1.1, but Media Session API support doesn't seem to exist.

const howl = new Howl({/* initializers */});
if (navigator && navigator.mediaSession) {
      navigator.mediaSession.setActionHandler('play', () => howl.play());
      navigator.mediaSession.setActionHandler('pause', () => howl.pause());
}

This workaround does not seem to work when using html5: true.

petrnagy avatar Aug 31 '20 17:08 petrnagy

navigator.mediaSession

Work for me with html5 : true

Gizmo091 avatar Mar 30 '22 10:03 Gizmo091