iOS AVPlayer:屏幕锁定时暂停视频

时间:2015-07-06 11:06:31

标签: ios iphone ipad avplayer

我正在使用AVPlayerViewController来显示带有AVPlayer的视频。

当我锁定手机屏幕时,视频会继续在后台播放。

我该如何防止这种情况?

2 个答案:

答案 0 :(得分:1)

尝试禁用音频和播放的背景模式

String appPackageName = getPackageName();
    try {
        startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse("market://details?id=" + appPackageName)));
    } catch (android.content.ActivityNotFoundException anfe) {
        startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse("https://play.google.com/store/apps/details?id="
                        + appPackageName)));
    }

答案 1 :(得分:0)

浏览此博客文章,它将帮助您

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;
}