useAudioPlayer icon indicating copy to clipboard operation
useAudioPlayer copied to clipboard

Playback events are not triggered by media session API

Open humbkr opened this issue 5 years ago • 7 comments

Describe the bug Chrome and other browsers now ship with a feature to control media directly from the browser using the media session API: https://developer.mozilla.org/en-US/docs/Web/API/Media_Session_API https://techcrunch.com/2020/01/16/chrome-gets-global-media-controls

Problem: when using the Chrome media controls, the playback events like play, pause, ... are not triggered, ie isPlaying is not updated, resulting in an out of sync UI.

To Reproduce Steps to reproduce the behavior:

  1. Using Chrome, start playing an audio file via an html button
  2. Use the browser media controls to pause the playback
  3. The audio is paused but the isPlaying variable is not updated

Expected behavior The useAudioPlayer() state reflects the state of the audio playback.

Environment (please complete the following information):

  • Browser/ browser version: Chrome
  • Library version: 0.0.18
  • React version: 16.3.1
  • Node version: 10.15.0

Related issue: https://github.com/goldfire/howler.js/issues/1262

humbkr avatar Aug 06 '20 14:08 humbkr

+1, lmk if I can help with this @E-Kuerschner

joeyiny avatar Jul 09 '23 22:07 joeyiny

@joeyiny I have something working locally! Hoping to get a release out this week cc @humbkr

E-Kuerschner avatar Jul 10 '23 02:07 E-Kuerschner

@joeyiny sorry for the delay! I still have a branch open for this but i ran into some difficulties with the global version of the hook. Will keep posting updates here

E-Kuerschner avatar Aug 10 '23 00:08 E-Kuerschner

@E-Kuerschner got it, let me know if i can help

joeyiny avatar Aug 10 '23 02:08 joeyiny

hey @joeyiny, @humbkr are you able to use the media session if you create the sound with html5 set to true?

const { load } = useAudioPlayer()

load({
  src: '/myFile.mp3',
  html5: true
})

After doing some research it appears that the media notification will only be set if an audio or video element is present on the page.

see: https://stackoverflow.com/questions/52226454/media-notifications-using-the-media-session-web-api-doesnt-work-with-web-audio

E-Kuerschner avatar Sep 20 '23 10:09 E-Kuerschner

pausing work on this for the time being since the Media Session Notification feature will not work with the Web Audio Api which is the default mode of operation for Howler. In order to integrate with the MediaSession the Howl needs to be created with the html5 option set to true.

E-Kuerschner avatar Oct 28 '23 13:10 E-Kuerschner