PlatformPictureInPicture.kt
composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/services/media/player/PlatformPictureInPicture.kt
1package eu.friedcutlet.yokan.services.media.player23import io.github.kdroidfilter.composemediaplayer.VideoPlayerState4import kotlinx.coroutines.flow.Flow5import kotlinx.coroutines.flow.MutableStateFlow6import kotlinx.coroutines.flow.StateFlow7import kotlinx.coroutines.flow.asStateFlow8import kotlinx.coroutines.flow.emptyFlow910/** Remote controls shown in the system PiP window (Android) or the browser's PiP window (web). */11enum class PictureInPictureAction { SkipForward, Previous, Next, Play, Pause }1213/** System picture-in-picture. The defaults describe a platform without it; see [NoPictureInPicture]. */14internal interface PictureInPicturePlatform {15 val isSupported: Boolean get() = false16 val active: StateFlow<Boolean>17 val actions: Flow<PictureInPictureAction> get() = emptyFlow()1819 fun request(controller: MediaPlayerController? = null): Boolean = false20 fun setPlaybackState(active: Boolean, eligible: Boolean, admitted: () -> Boolean) = Unit2122 /** [replaceWithPrevious] swaps the first action from +10 s to the previous episode. */23 fun updateActions(playing: Boolean, replaceWithPrevious: Boolean) = Unit2425 /** Bind platform callbacks to this exact controller/state pair; return its identity-safe removal. */26 fun bindSurface(controller: MediaPlayerController, state: VideoPlayerState): () -> Unit = {}27}2829internal object NoPictureInPicture : PictureInPicturePlatform {30 override val active: StateFlow<Boolean> = MutableStateFlow(false).asStateFlow()31}3233internal expect val pictureInPicturePlatform: PictureInPicturePlatform34