Aashir
Aashir

Reputation: 1

Next js website Audio stops playing as soon as i leave safari in iphone, even though safari runs in background

My problem is with my website's audio not running in background for iphone and ios but i have seen all other website getting widget in homescreen and also running in background even if i leave safari. And for your information audio does play on user interaction i am not talking about autoplay.

I want to know how to implement background play for audio even if i leave safari on iphone. I am using next js, use-sound and howler for the player, any body have any idea how can this be done?.

The player function like play seek pause everything is running as intended. After scouring all over the internet i got few leads like adding this, but it didn't work or maybe i didnt understand

 document.addEventListener('visibilitychange',() => {
 sound?.pause()
      sound?.play()   

})

and also this

   
   let userPaused = false;

   player.on('pause', () => {
   userPaused = Boolean(player.userActive());
   });

   player.on('playing', () => {
     userPaused = false;
   });

   document.addEventListener('visibilitychange', function () {
     if (document.visibilityState === 'hidden' && !userPaused) {
       try {
         player.play();
       } catch (e) {
         console.warn('Cannot play video while page is hidden.', e);
       }
     }
   });

can someone help me with this? or point me in right direction

Upvotes: 0

Views: 146

Answers (0)

Related Questions