react-native-video: [BUG]: playInBackground does not work on iOS in basic example project

Version

v6 (Beta)

What platforms are you having the problem on?

iOS

Architecture

Old architecture

What happened?

6.0.0-beta.7

Enable playInBackground as noted in the docs, including ignoreSilentSwitch=‘ignore’. I checked the background audio in Xcode for the project.

I drag the app upwards to background it and the video stops. I expected audio to continue.

When using breakpoints and logs in Xcode, I do not see any problems with the function applicationDidEnterBackground since it correctly does not set the player to nil and I didn’t see anything else run to set the rate to 0 or pause the video, I’m very confused as to what causes the video player’s audio to stop.

Perhaps the audio session type is wrong?

Reproduction

https://github.com/paulrinaldi/react-native-video

Reproduction

Step to reproduce this bug are: Pull the forked project (or get a diff and apply it), run git clean -xdf && yarn xbasic install && cd examples/basic/ios && pod install && cd - && yarn xbasic ios ^ if this fails to create the bundler (which it does for me), I then open examples/basic/ios/videoplayer.xcworkspace in Xcode and hit play.

Let video load, drag app upward to background the app, observe the audio (video’s audio) stop. When you open the app up again in the simulator, you’ll notice it continues to play.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (11 by maintainers)

Commits related to this issue

Most upvoted comments

This make sense will try to make PR with this

I fixed it by setting:

if #available(iOS 15.0, *) {
    _playerLayer?.player?.audiovisualBackgroundPlaybackPolicy = .continuesIfPossible
}

, it used to be .automatic in that method https://developer.apple.com/documentation/avfoundation/avplayer/3787548-audiovisualbackgroundplaybackpol @KrzysztofMoch Now I need to make it still pause when other audio plays…

This may then only work for iOS 15+… Some data on worldwide use of iOS versions: https://www.statista.com/statistics/565270/apple-devices-ios-version-share-worldwide/

Oh yes it is - will check it, why it is not working (I remember it work last time when I was testing it 😅)