I have an iOS app built in React Native that plays video content using the react-native-video package and allows the use of AirPlay. When the app enters the background (pressing the home button, locking the screen or opening the swipe down menu) the video is paused and you have to resume play from the control center or lock screen media controls. I understand this is the expected behaviour of AVPlayer and I am trying to implement the following solution from the Apple documentation:
Remove/Restore the AVPlayerLayer and its associated AVPlayer
The code snippets provided are in Swift and I cannot seem to find a complete example of achieving this in my AppDelegate.m file using Objective-C.
I found the following snippet but I am unsure about the steps for getting my player view.
/* Remove the AVPlayerLayer from its associated AVPlayer
once the app is in the background. */
- (void)applicationDidEnterBackground:(UIApplication *)application {
MyPlayerLayerView *playerView = <#Get your player view#>;
[[playerView playerLayer] setPlayer:nil]; // remove the player
}
/* Restore the AVPlayer when the app is active again. */
- (void)applicationDidBecomeActive:(UIApplication *)application {
MyPlayerLayerView *playerView = <#Get your player view#>;
[[playerView playerLayer] setPlayer:_player]; // restore the player
}