Remove rememberMediaPlayer function #389
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refactor MediaController instantiation to singleton pattern
Description
This PR refactors the media controller to prevent it from being created and destroyed with the UI lifecycle.
This caused unnecessary service reconnections during navigation.
Key Changes
1. Architecture: Singleton Pattern
MediaSessionConnectionClass: Created a singleton class responsible for managing the lifecycle of theMediaControllerand its connection to theMediaService.MusicPlayerImplinstance is now held by this singleton, ensuring playback state persists across the entire application lifecycle, regardless of UI navigation.2. Dependency Injection
MediaSessionConnectionas asingledefinition in the Koin module (Dependencies.kt), making it available app-wide.3. Refactoring:
rememberMediaPlayer->observeMusicPlayerRememberMediaPlayer.kt->ObserveMusicPlayer.kt.rememberMediaPlayer()toobserveMusicPlayer(). This naming accurately reflects that the Composable now only observes an existing singleton state rather than creating and remembering a new player instance.eventLoggerparameter from the function signature.4. Updated Call Sites
Refactored the following components to use the new
observeMusicPlayer()function:MusicPlayerScreenMiniPlayerNFTLibraryPresenterBenefits
MediaControllerreconnection logic on every screen composition.