abbasfreestyle / react-native-af-video-player

MIT License
381 stars 289 forks source link

No background audio on real iOS device #131

Open flexgrip opened 5 years ago

flexgrip commented 5 years ago

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 commented 5 years ago

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

flexgrip commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 :)

yehancha commented 5 years ago

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