Skip to content

MediaSession API music controllers not showing on mobile locked screens when playing an audio file (Android/Chrome and iPhone/Safari) #1657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 of 4 tasks
Crandy9 opened this issue May 5, 2023 · 4 comments
Labels

Comments

@Crandy9
Copy link

Crandy9 commented May 5, 2023

Documentation Is:

  • Missing
  • Confusing
  • Incorrect
  • Other

Describe Issue

I have a music player powered by howlerjs in my Vuejs app. The audio source is served to dynamically created howler instances from my Django backend API. I have custom functions for my music player that calls the howler methods (play, pause, skip forward, back) within them. So the actual howler play() and pause() methods are not called in the howler onplay() and onpause() methods. Everything works good, there are no errors and the audio correctly plays in my app. However, the chrome browser for Android and Safari for iPhone do not sense that audio is playing and therefore the music controllers do not show up in the lock screens or notifications tab of the phone.

Here is an example from https://web.dev/media-session/ what I am trying to do. But according to that article, the browser should automatically pick up when an audio file is playing in the browser and display the media controls. But that is not happening in my case

How do I notify chrome and safari that an audio file is playing to display the media controls? I have no audio html tags setup in my vuejs components because I am creating a music player from the ground up using howler. Maybe that's why?

Thank you

Here is my howlerjs code:

    createHowlInstance(state , src) {
      const newHowlInstance = new Howl({
            src: [src],
            // html5: false,
            preload: true,
            xhr: {
              headers: {
                'Accept-Ranges': 'bytes'
              }
            },
            onplay: () => {
              
            },
            onpause: () => {

            },
            onstop: () => {

            },
            // when the song finishes playing go to next song
            onend: () => {

            },
            onloaderror: (error) => {
              console.log('error loading audio file', error)
            },
            onplayerror: (error) => {
              console.log('error playing audio file', error)
            },
      }); 
      state.howlInstance = newHowlInstance 

        if (navigator && navigator.mediaSession) {

            navigator.mediaSession.setActionHandler('play', () => {
              console.log('play')
              newHowlInstance.play();
            });
            navigator.mediaSession.setActionHandler('pause', () => {
              console.log('pause')
              newHowlInstance.pause();
            });  
        }
            
    },

Suggested Improvement

I tried html: true, html: false checked other related issues here

#1262

and here

#1175 (comment)

@Crandy9 Crandy9 added the docs label May 5, 2023
@Sandakan
Copy link

@Crandy9 Maybe you could try setting the html5 option to true and see if this fixes the problem.
I have a problem with something like this, and mediaSession works when html5 is set to true.

@bikubi
Copy link
Contributor

bikubi commented Jul 11, 2023

Looks like a duplicate of my #1383

I have also a fix you might want to try #1530
(looks like I should follow up on that PR...)

@ranxin001
Copy link

@Crandy9 Maybe you could try setting the html5 option to true and see if this fixes the problem. I have a problem with something like this, and mediaSession works when html5 is set to true.

I`m not working

@ranxin001
Copy link

Looks like a duplicate of my #1383

I have also a fix you might want to try #1530 (looks like I should follow up on that PR...)

Too strong,That's it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants