Reputation: 157
I am using an AVPlayerViewController to display a video with an AVPlayer.
When I lock the phone screen the video keeps playing on the background.
How can I prevent this?
Upvotes: 2
Views: 1396
Reputation: 487
Try this disable background mode for Audio and Airplay
- (void)applicationDidEnterBackground:(UIApplication *)application {
// pause the video here
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
// resume video when screen unlock
}
Upvotes: 1
Reputation: 2413
Go through this blog post, it will help you out
How to Detect When an App Is Coming From the Lockscreen or Homescreen on iOS
- (void)applicationDidEnterBackground:(UIApplication *)application {
CGFloat screenBrightness = [[UIScreen mainScreen] brightness];
NSLog(@"Screen brightness: %f", screenBrightness);
self.backgroundedToLockScreen = screenBrightness <= 0.0;
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
if (self.backgroundedToLockScreen) {
... // App was backgrounded to lock screen
} else {
... // App was backgrounded on purpose by tapping the home button or switching Apps.
}
self.backgroundedToLockScreen = NO;
}
Upvotes: 0