处理视频退到后台进前台没有继续播放

This commit is contained in:
2025-11-28 13:56:29 +08:00
parent 73802b6e80
commit d4c553f072

View File

@@ -45,6 +45,15 @@ static void *KBPermPlayerPresentationSizeContext = &KBPermPlayerPresentationSize
[self.view addSubview:self.openButton]; [self.view addSubview:self.openButton];
[self.view addSubview:self.helpLabel]; [self.view addSubview:self.helpLabel];
// App /
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(kb_appDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(kb_appDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) { [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view); make.edges.equalTo(self.view);
@@ -128,6 +137,20 @@ static void *KBPermPlayerPresentationSizeContext = &KBPermPlayerPresentationSize
self.kb_permPlayerLayer.frame = CGRectMake(0, 0, width, height); self.kb_permPlayerLayer.frame = CGRectMake(0, 0, width, height);
} }
#pragma mark - App Lifecycle
- (void)kb_appDidBecomeActive:(NSNotification *)note {
//
if (self.isViewLoaded && self.view.window && !self.view.hidden) {
[self kb_setupPermissionVideoPlayer];
}
}
- (void)kb_appDidEnterBackground:(NSNotification *)note {
//
[self.kb_permPlayer pause];
}
- (void)dealloc { - (void)dealloc {
// //
[[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] removeObserver:self];