Skip to content

Commit f2fe9c6

Browse files
authored
Merge pull request #193 from kdroidFilter/docs/dispose-documentation
docs: add KDoc for dispose() and rememberVideoPlayerState()
2 parents 4aa0dd9 + 3fafdc5 commit f2fe9c6

1 file changed

Lines changed: 33 additions & 6 deletions

File tree

mediaplayer/src/commonMain/kotlin/io/github/kdroidfilter/composemediaplayer/VideoPlayerState.kt

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,24 @@ interface VideoPlayerState {
150150
// Cleanup
151151

152152
/**
153-
* Releases resources used by the video player and disposes of the state.
153+
* Releases all resources used by the video player (native players, coroutines, observers, etc.).
154+
*
155+
* **You do not need to call this manually** when using [rememberVideoPlayerState], which is the
156+
* recommended way to create a player state in a composable. It automatically calls [dispose]
157+
* via a [DisposableEffect] when the composable leaves the composition.
158+
*
159+
* Only call this directly if you create the state manually via [createVideoPlayerState] outside
160+
* of a composable lifecycle:
161+
* ```
162+
* val state = createVideoPlayerState()
163+
* try {
164+
* // use the player...
165+
* } finally {
166+
* state.dispose()
167+
* }
168+
* ```
169+
*
170+
* After calling [dispose], the state should not be reused.
154171
*/
155172
fun dispose()
156173
}
@@ -162,12 +179,22 @@ interface VideoPlayerState {
162179
expect fun createVideoPlayerState(audioMode: AudioMode = AudioMode()): VideoPlayerState
163180

164181
/**
165-
* Creates and manages an instance of `VideoPlayerState` within a composable function, ensuring
166-
* proper disposal of the player state when the composable leaves the composition. This function
167-
* is used to remember the video player state throughout the composition lifecycle.
182+
* Creates and remembers a [VideoPlayerState], automatically releasing all player resources
183+
* when the composable leaves the composition.
168184
*
169-
* @return The remembered instance of `VideoPlayerState`, which provides functionalities for
170-
* controlling and managing video playback, such as play, pause, stop, and seek.
185+
* This is the **recommended** way to obtain a [VideoPlayerState]. You do not need to call
186+
* [VideoPlayerState.dispose] yourself — cleanup is handled via [DisposableEffect].
187+
*
188+
* ```
189+
* @Composable
190+
* fun MyPlayer() {
191+
* val playerState = rememberVideoPlayerState()
192+
* // use playerState — resources are freed automatically on removal
193+
* }
194+
* ```
195+
*
196+
* @param audioMode The audio mode configuration for the player.
197+
* @return The remembered instance of [VideoPlayerState].
171198
*/
172199
@Composable
173200
fun rememberVideoPlayerState(audioMode: AudioMode = AudioMode()): VideoPlayerState {

0 commit comments

Comments
 (0)