Skip to content

Fix Video Player Behavior on Screen Lock for iOS and Android#92

Merged
kdroidFilter merged 9 commits intomasterfrom
fix-different-behavior-on-locked-screen-#75
Jul 30, 2025
Merged

Fix Video Player Behavior on Screen Lock for iOS and Android#92
kdroidFilter merged 9 commits intomasterfrom
fix-different-behavior-on-locked-screen-#75

Conversation

@kdroidFilter
Copy link
Copy Markdown
Owner

This PR addresses inconsistent behavior when locking the screen during video playback across iOS and Android platforms. Previously, on Android, videos would continue playing when the screen was locked, while on iOS, videos would pause but the isPlaying state would incorrectly remain true.

Changes Made

iOS Implementation
  • Added notification observers for app lifecycle events:
    • UIApplicationDidEnterBackgroundNotification (screen lock)
    • UIApplicationWillEnterForegroundNotification (screen unlock)
  • When the screen is locked:
    • Store the current playing state
    • Update isPlaying state to match the actual player state
  • When the screen is unlocked:
    • Resume playback if the video was playing before locking
    • Properly update the isPlaying state
Android Implementation
  • Added a BroadcastReceiver to listen for screen events:
    • ACTION_SCREEN_OFF (screen lock)
    • ACTION_SCREEN_ON (screen unlock)
  • When the screen is locked:
    • Store the current playing state
    • Pause playback if the video was playing
  • When the screen is unlocked:
    • Resume playback if the video was playing before locking
  • Properly register/unregister the receiver to prevent memory leaks

Benefits

  • Consistent behavior across platforms: videos pause when the screen is locked and resume when unlocked
  • Accurate isPlaying state that correctly reflects the actual playback state
  • Improved user experience with predictable video behavior
  • Proper resource management to prevent memory leaks

This PR resolves the issue where playerState.isPlaying would return true on iOS even when the video was actually paused after screen lock. #75

Introduced the `initializeplayerState` parameter to control whether videos start playing automatically or remain paused after opening. Updated methods, documentation, and UI components across platforms to support and reflect this behavior. Enhanced customization and user control over playback initialization.
Introduced the `initializeplayerState` parameter to control whether videos start playing automatically or remain paused after opening. Updated methods, documentation, and UI components across platforms to support and reflect this behavior. Enhanced customization and user control over playback initialization.
Introduced the ability to start video playback in a paused state by adding a `startPlayback` parameter to media initialization. Enhanced frame caching and state management to ensure smooth handling of initial paused states, preventing unwanted playback and ensuring proper UI loading behavior.
Ensure proper initialization and cleanup by updating loading state on initialization, marking user pause explicitly, and resetting the current frame during media release.
…on Android by updating `_hasMedia` and adding a pause action when playback isn't started automatically.
Centralized resource cleanup by introducing `cleanupCurrentPlayer` for better maintainability and consistency. Updated observer management to prevent redundant updates and improved playback state transitions. Enhanced periodic position update handling by associating observers with specific player instances.
…emove unused imports in `VideoPlayerSurface` for cleanup.
Implemented screen lock detection on Android and app lifecycle observers on iOS to manage playback behavior during screen locks or app backgrounding. Enhanced state handling to pause/resume playback automatically based on device state changes, ensuring consistent playback experience across platforms.
@kdroidFilter kdroidFilter merged commit 89c2ede into master Jul 30, 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