pixijs / sound

WebAudio API playback library, with filters. Modern audio playback for modern browsers.
https://pixijs.io/sound/examples/
MIT License
404 stars 68 forks source link

Safari Changing to different tab not muting sound #266

Open turkerfatih opened 3 months ago

turkerfatih commented 3 months ago

Step to reproduce

  1. Open https://pixijs.io/sound/examples/demo.html
  2. Play any loop sound (without clicking anywhere , first click should be playing loop sound)
  3. Switch different tab sound is still playing which should not. If you click anywhere after play sound then switch tab it works as expected.

Specs: Safari 17.1 MacOS: Sonoma 14.1.1

turkerfatih commented 3 months ago

Workaround is the usingvisibilityjs (https://www.npmjs.com/package/visibilityjs)

import * as Visibility  from "visibilityjs";
import { sound } from "@pixi/sound";
Visibility.change((e,s)=>this.onVisibilityChange(e,s));
    private onVisibilityChange(e:Event, state:string)
    {
      if(state=='hidden')
      {
        sound.muteAll()

      }else{
        sound.unmuteAll()
      }
    }