react-native-af-video-player icon indicating copy to clipboard operation
react-native-af-video-player copied to clipboard

No background audio on real iOS device

Open flexgrip opened this issue 5 years ago • 5 comments

Hello,

In the simulator, background audio works great. I've followed the instructions and enabled background audio in xcode, as well as set all of the props to true or 'ignore'

playWhenInactive={this.state.playWhenInactive}
playInBackground={this.state.playInBackground}
ignoreSilentSwitch={this.state.ignoreSilentSwitch}

Since it works in the sim, I assumed I had all of the settings right. But when testing on a real iPhone 6s, hitting the home button while playing a video causes the audio to slowly mute, killing background audio.

Any ideas? I'm running the latest version of react-native-af, as well as RN 0.60.3

Thanks!

flexgrip avatar Jul 20 '19 07:07 flexgrip

Just noticed that ignoreSilentSwitch Isn’t working either. Totally mutes the audio...

flexgrip avatar Jul 20 '19 08:07 flexgrip

So it seems to work, depending on the orientation of the moon and the price of tea in China. Sometimes xcode builds a version that works, sometimes it doesn't. I can't seem to find the culprit.

I have no idea why it works on android, then doesn't work on iOS. Then I'll build it again a few hours later with no changes and it works great. I think maybe the only difference is one build is a debug build and another is a release build in xcode? Not sure why that would matter though, they still use the same Info.plist.

I guess I'll close this.

flexgrip avatar Jul 21 '19 22:07 flexgrip

Nope. It's definitely related to this player. What I can do is swap this out for react-native-video, then swap back to this player without doing a complete reload and it'll then play in the background. If I kill the app and restart, it won't. So I think it has something to do with the react-native-video dependency being too old or something.

Steps to reproduce:

  1. Setup a normal react-native-video instance so that playInBackground works.
  2. Change import line back to react-native-af-video-player
  3. Reload app without killing it. ... playInBackground and ignoreSilentSwitch works.
  4. Kill the app in iOS and run it again ... now they don't work.

I am assuming this is because when you kill the app and start over, it is pulling in that dependency again? Not sure.

I tried updating react-native-video in this package.json to the current latest (4.4.4). Did not work.

I'll keep chugging along and try to figure out what the deal is.

flexgrip avatar Jul 22 '19 02:07 flexgrip

Ok. So I did some manual edits to the af package itself. My suspicion was that the props weren't being passed or implemented somehow. So I manually edited playsInBackground and ignoreSilentSwitch and rebuilt everything. Then it started working.

I am also using @jay0512's fork: https://github.com/jay0512/react-native-af-video-player

I'll try to figure out why the props aren't properly being passed and provide a PR to fix it. Any help would be appreciated :)

flexgrip avatar Jul 22 '19 02:07 flexgrip

I had audio on my headphone but not the phone speakers. In my case I had turned on the hardware silent switch. Turning off did fix it. It seems the issue is with internal management of the react-native-video prop "ignoreSilentSwitch" as @flexgrip suggested.

react-native-audio repo also has listed few issues related to this and this post helped me: https://github.com/react-native-community/react-native-video/issues/874#issuecomment-369840510

yehancha avatar Aug 23 '19 05:08 yehancha