TheWidlarzGroup / react-native-video

A <Video /> component for react-native
https://docs.thewidlarzgroup.com/react-native-video/
MIT License
7.2k stars 2.9k forks source link

Background music stops when ignoreSilentSwitch="ignore" on iOS #3186

Open bmitioglov opened 1 year ago

bmitioglov commented 1 year ago

Bug

Background music stops when ignoreSilentSwitch="ignore"

Platform

Which player are you experiencing the problem on:

Environment info

"^6.0.0-alpha.6" Device: iPhone 12 Pro, iOS: 16.5.1

Steps To Reproduce

1. Configure a video like this

<Video
          source={{uri: previewVideoLink}}  
          paused={true}                
          style={styles.backgroundVideo} 
          controls={true}
          ignoreSilentSwitch="ignore"
          resizeMode="cover"
          disableFocus={true}
          pictureInPicture={true}
        />

2. Start music in the background (Spotify for example), run the app, and open the view with this video component -> Spotify music stops.

3. It works correctly when I set ignoreSilentSwitch to obey, but I need to ignore the silent switch and at the same time not block other sounds. ...

Expected behaviour

  1. Background music keeps playing unless I hit the play of my app video

Reproducible sample code

<Video
          source={{uri: previewVideoLink}}  
          paused={true}                
          style={styles.backgroundVideo} 
          controls={true}
          ignoreSilentSwitch="ignore"
          resizeMode="cover"
          disableFocus={true}
          pictureInPicture={true}
        />
bmitioglov commented 1 year ago

Downgraded to this version: "react-native-video": "^5.2.1", and now it works as expected, background music is playing until I hit play in the video. So looks like there is something wrong with the newer version (6.0.0-alpha.6).

bmitioglov commented 1 year ago

also, UI freeze is not there with the older version (when I was opening the view with the video it kind of waited until my video stream was loaded)

freeboub commented 2 months ago

I just try to reproduce this issue with react native video version. It seems to be fixed (we had some merged PR recently around this audio management feature). I will close the issue, let me know if I need to reopen. notice that I added in the sample:

        ignoreSilentSwitch="ignore"
        disableFocus={true}
        pictureInPicture={true}

Tested on emulator (which doesn't support pip, maybe that is the issue)

ctriantaf commented 2 months ago

@freeboub I'm using v6.4.5 and I can reproduce the issue in iOS in my current project.

Using only ignoreSilentSwitch="obey" will keep the background music playing - but that doesn't make sense to me. I would assume that muted={false} should be enough to prevent background music from pausing.

freeboub commented 2 months ago

@ctriantaf I think you should also enable https://thewidlarzgroup.github.io/react-native-video/component/props#playwheninactive and https://thewidlarzgroup.github.io/react-native-video/component/props#playinbackground

ctriantaf commented 2 months ago

@freeboub I tried enable both playWhenInactive and playInBackground and changing ignoreSilentSwitch="ignore" but the background music stops when the video is mounted. I'll stick to ignoreSilentSwitch="obey" for now as it seems to work.

github-actions[bot] commented 2 weeks ago

This issue is stale because it has been open for 30 days with no activity. If there won't be any activity in the next 14 days, this issue will be closed automatically.

bmitioglov commented 2 weeks ago

Was it fixed in the new version?