fix: pip works only for first invocation
This commit is contained in:
1 parent
879c2f368c
commit
03cabd0506
1 file changed
+24
-20
@@ -100,12 +100,26 @@
|
|||||||
|
|
||||||
- (void)pictureInPictureControllerDidStopPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
|
- (void)pictureInPictureControllerDidStopPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
|
||||||
_streamView.hidden = NO;
|
_streamView.hidden = NO;
|
||||||
|
|
||||||
if (!_isRestoringFromPiP) {
|
if (!_isRestoringFromPiP) {
|
||||||
[self returnToMainFrame];
|
[self returnToMainFrame];
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_isRestoringFromPiP = NO;
|
_isRestoringFromPiP = NO;
|
||||||
|
|
||||||
|
[self cleanupPiPController];
|
||||||
|
|
||||||
|
// Immediately set up a new PiP controller.
|
||||||
|
// We cannot wait for a delegate callback that will not fire again.
|
||||||
|
// At this point, we know the stream is active and the renderer is available.
|
||||||
|
if (self->_streamMan && self->_streamMan.videoRenderer) {
|
||||||
|
Log(LOG_I, @"Re-initializing PiP controller immediately after restore.");
|
||||||
|
[self setupPiPControllerWithRenderer:self->_streamMan.videoRenderer];
|
||||||
|
} else {
|
||||||
|
Log(LOG_E, @"Failed to re-initialize PiP controller: renderer was not available.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)pictureInPictureController:(AVPictureInPictureController *)pictureInPictureController restoreUserInterfaceForPictureInPictureStopWithCompletionHandler:(void (^)(BOOL restored))completionHandler {
|
- (void)pictureInPictureController:(AVPictureInPictureController *)pictureInPictureController restoreUserInterfaceForPictureInPictureStopWithCompletionHandler:(void (^)(BOOL restored))completionHandler {
|
||||||
_isRestoringFromPiP = YES;
|
_isRestoringFromPiP = YES;
|
||||||
_streamView.hidden = NO;
|
_streamView.hidden = NO;
|
||||||
@@ -836,15 +850,6 @@
|
|||||||
|
|
||||||
// This will fire if the user opens control center or gets a low battery message
|
// This will fire if the user opens control center or gets a low battery message
|
||||||
- (void)applicationWillResignActive:(NSNotification *)notification {
|
- (void)applicationWillResignActive:(NSNotification *)notification {
|
||||||
if (_settings.enablePIP && self.pipController && !self.pipController.isPictureInPictureActive && self.pipController.isPictureInPicturePossible) {
|
|
||||||
VideoDecoderRenderer *renderer = self.streamMan.videoRenderer;
|
|
||||||
if (renderer && renderer.displayLayer && self.view.window) {
|
|
||||||
Log(LOG_I, @"Starting Picture in Picture");
|
|
||||||
[self.pipController startPictureInPicture];
|
|
||||||
} else {
|
|
||||||
Log(LOG_I, @"Skipping PiP start: Renderer/Layer/Window not ready OR PiP not possible.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (_inactivityTimer != nil) {
|
if (_inactivityTimer != nil) {
|
||||||
[_inactivityTimer invalidate];
|
[_inactivityTimer invalidate];
|
||||||
_inactivityTimer = nil;
|
_inactivityTimer = nil;
|
||||||
@@ -883,24 +888,24 @@
|
|||||||
|
|
||||||
// This fires when the home button is pressed
|
// This fires when the home button is pressed
|
||||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||||
|
Log(LOG_I, @"Application entering background.");
|
||||||
Log(LOG_I, @"Terminating stream immediately for backgrounding");
|
|
||||||
|
|
||||||
if (_inactivityTimer != nil) {
|
if (_inactivityTimer != nil) {
|
||||||
[_inactivityTimer invalidate];
|
[_inactivityTimer invalidate];
|
||||||
_inactivityTimer = nil;
|
_inactivityTimer = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
// [self returnToMainFrame];
|
// To prevent a race condition, check if PiP is POSSIBLE.
|
||||||
// Don't terminate if pip is active
|
// This property is true even during the slight delay before `isPictureInPictureActive` becomes true.
|
||||||
if (_settings.enablePIP && self.pipController && self.pipController.isPictureInPictureActive) {
|
// If PiP is possible, we should not start a termination timer.
|
||||||
Log(LOG_I, @"PIP is active, not terminating stream");
|
if (_settings.enablePIP && self.pipController && self.pipController.isPictureInPicturePossible) {
|
||||||
|
Log(LOG_I, @"PiP is possible, avoiding inactivity timer.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !TARGET_OS_TV
|
#if !TARGET_OS_TV
|
||||||
// Terminate the stream if the app is inactive for 60 seconds
|
// Only start the timer if PiP is truly not possible.
|
||||||
Log(LOG_I, @"Starting inactivity termination timer");
|
Log(LOG_I, @"PiP not possible, starting inactivity termination timer.");
|
||||||
_inactivityTimer = [NSTimer scheduledTimerWithTimeInterval:60
|
_inactivityTimer = [NSTimer scheduledTimerWithTimeInterval:60
|
||||||
target:self
|
target:self
|
||||||
selector:@selector(inactiveTimerExpired:)
|
selector:@selector(inactiveTimerExpired:)
|
||||||
@@ -908,7 +913,6 @@
|
|||||||
repeats:NO];
|
repeats:NO];
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)expandSettingsView{
|
- (void)expandSettingsView{
|
||||||
self.mainFrameViewcontroller.settingsExpandedInStreamView = true; //notify mainFrameViewContorller that this is a setting expansion in stream view, some settings shall be disabled.
|
self.mainFrameViewcontroller.settingsExpandedInStreamView = true; //notify mainFrameViewContorller that this is a setting expansion in stream view, some settings shall be disabled.
|
||||||
[self.mainFrameViewcontroller expandSettingsView];
|
[self.mainFrameViewcontroller expandSettingsView];
|
||||||
|
|||||||
Reference in new issue
Block a user