Skip to content

Prevent Video Player Pausing During Screen Rotation and Fullscreen Transitions on iOS#89

Merged
kdroidFilter merged 5 commits intomasterfrom
fix-Fix-fullscreen-player-does-not-rotate-with-device-rotation-ios-#72
Jul 29, 2025
Merged

Prevent Video Player Pausing During Screen Rotation and Fullscreen Transitions on iOS#89
kdroidFilter merged 5 commits intomasterfrom
fix-Fix-fullscreen-player-does-not-rotate-with-device-rotation-ios-#72

Conversation

@kdroidFilter
Copy link
Copy Markdown
Owner

Prevent Video Player Pausing During Screen Rotation and Fullscreen Transitions

Problem

The video player was pausing unexpectedly when:

  • The device screen was rotated
  • The player transitioned to or from fullscreen mode

This created a disruptive user experience as playback would stop and require manual restarting after these common UI transitions.

Solution

I implemented a solution that prevents the player from pausing during these transitions while maintaining the existing behavior for other scenarios:

  1. Added a pauseOnDispose parameter to VideoPlayerSurfaceImpl function (defaulting to true for backward compatibility)
  2. Modified the DisposableEffect in VideoPlayerSurface.ios.kt to only pause the player if pauseOnDispose is true
  3. Set pauseOnDispose to false in the main VideoPlayerSurface function to handle rotation
  4. Set pauseOnDispose to false in the fullscreen transition to handle fullscreen mode
  5. Added logging to help with debugging and understanding the component lifecycle

Implementation Details

The core of the fix is in VideoPlayerSurface.ios.kt, where we now conditionally pause the player when the view is disposed:

DisposableEffect(Unit) {
    onDispose {
        Logger.d { "[VideoPlayerSurface] Disposing" }
        // Only pause if pauseOnDispose is true (prevents pausing during rotation or fullscreen transitions)
        if (pauseOnDispose) {
            Logger.d { "[VideoPlayerSurface] Pausing on dispose" }
            playerState.pause()
        } else {
            Logger.d { "[VideoPlayerSurface] Not pausing on dispose (rotation or fullscreen transition)" }
        }
        avPlayerViewController.removeFromParentViewController()
    }
}

Testing

The changes were tested on iOS devices with:

  • Various screen rotations (portrait to landscape and vice versa)
  • Transitions to and from fullscreen mode
  • Different video content types and lengths

The player now continues playback smoothly during these transitions without interruption.

Considerations

  • This change only affects the iOS implementation, as the issue was specific to the iOS platform
  • The default behavior (pausing on dispose) is preserved for other scenarios to maintain backward compatibility
  • Additional logging was added to help with debugging and understanding the component lifecycle

Enhanced resource cleanup during disposal to ensure synchronous and safe operations. Introduced an `isDisposing` flag to prevent redundant calls and race conditions. Improved coroutine handling, added checks to avoid processing during disposal, and centralized resource cleanup logic.
Introduced an `onReset` callback to ensure proper resource cleanup by nullifying the player instance when the view is recycled in a LazyList.
…rSaveable` in `VideoPlayerSurface` and synchronize with `playerState`.
Adjusted `VideoPlayerSurface` logic to avoid pausing the video player during screen rotations or entering fullscreen mode. Updated `pauseOnDispose` handling and player configuration to ensure smoother transitions, while maintaining proper cleanup and state management.
@kdroidFilter kdroidFilter changed the title Prevent Video Player Pausing During Screen Rotation and Fullscreen Transitions Prevent Video Player Pausing During Screen Rotation and Fullscreen Transitions on iOS Jul 29, 2025
@kdroidFilter kdroidFilter merged commit 7a126b4 into master Jul 29, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant