mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 23:51:21 +02:00
Fix seek start & clean up code
This commit is contained in:
parent
5255a89126
commit
c648be4fa3
3 changed files with 17 additions and 2 deletions
|
|
@ -274,7 +274,7 @@ fun SeekBar(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
interactionSource = interactionSource,
|
interactionSource = interactionSource,
|
||||||
enabled = isEnabled,
|
enabled = isEnabled,
|
||||||
durationMs = player.contentDuration,
|
durationMs = player.duration,
|
||||||
seekBack = seekBack,
|
seekBack = seekBack,
|
||||||
seekForward = seekForward,
|
seekForward = seekForward,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ object MPVProperty {
|
||||||
const val HWDEC = "hwdec-current"
|
const val HWDEC = "hwdec-current"
|
||||||
const val MUTE = "mute"
|
const val MUTE = "mute"
|
||||||
const val TRACK_AUDIO = "current-tracks/audio/selected"
|
const val TRACK_AUDIO = "current-tracks/audio/selected"
|
||||||
|
const val SEEKABLE = "seekable"
|
||||||
|
|
||||||
val observedProperties =
|
val observedProperties =
|
||||||
mapOf(
|
mapOf(
|
||||||
|
|
@ -38,5 +39,6 @@ object MPVProperty {
|
||||||
HWDEC to MPV_FORMAT_NONE,
|
HWDEC to MPV_FORMAT_NONE,
|
||||||
MUTE to MPV_FORMAT_FLAG,
|
MUTE to MPV_FORMAT_FLAG,
|
||||||
TRACK_AUDIO to MPV_FORMAT_NONE,
|
TRACK_AUDIO to MPV_FORMAT_NONE,
|
||||||
|
SEEKABLE to MPV_FORMAT_FLAG,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import androidx.media3.common.text.CueGroup
|
||||||
import androidx.media3.common.util.Size
|
import androidx.media3.common.util.Size
|
||||||
import androidx.media3.common.util.UnstableApi
|
import androidx.media3.common.util.UnstableApi
|
||||||
import androidx.media3.common.util.Util
|
import androidx.media3.common.util.Util
|
||||||
|
import com.github.damontecres.wholphin.util.mpv.MPVLib.MpvEvent.MPV_EVENT_FILE_LOADED
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import kotlin.concurrent.atomics.ExperimentalAtomicApi
|
import kotlin.concurrent.atomics.ExperimentalAtomicApi
|
||||||
import kotlin.time.Duration.Companion.seconds
|
import kotlin.time.Duration.Companion.seconds
|
||||||
|
|
@ -48,6 +49,7 @@ class MpvPlayer(
|
||||||
|
|
||||||
private var mediaItem: MediaItem? = null
|
private var mediaItem: MediaItem? = null
|
||||||
|
|
||||||
|
private var startPositionMs: Long = 0L
|
||||||
private var durationMs: Long = 0L
|
private var durationMs: Long = 0L
|
||||||
private var positionMs: Long = 0L
|
private var positionMs: Long = 0L
|
||||||
|
|
||||||
|
|
@ -135,7 +137,7 @@ class MpvPlayer(
|
||||||
) {
|
) {
|
||||||
if (DEBUG) Timber.v("setMediaItems")
|
if (DEBUG) Timber.v("setMediaItems")
|
||||||
setMediaItems(mediaItems.subList(startIndex, mediaItems.size), false)
|
setMediaItems(mediaItems.subList(startIndex, mediaItems.size), false)
|
||||||
seekTo(startPositionMs)
|
this.startPositionMs = startPositionMs
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun addMediaItems(
|
override fun addMediaItems(
|
||||||
|
|
@ -164,6 +166,8 @@ class MpvPlayer(
|
||||||
|
|
||||||
override fun prepare() {
|
override fun prepare() {
|
||||||
if (DEBUG) Timber.v("prepare")
|
if (DEBUG) Timber.v("prepare")
|
||||||
|
durationMs = 0L
|
||||||
|
positionMs = 0L
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getPlaybackState(): Int {
|
override fun getPlaybackState(): Int {
|
||||||
|
|
@ -235,6 +239,7 @@ class MpvPlayer(
|
||||||
override fun release() {
|
override fun release() {
|
||||||
Timber.i("release")
|
Timber.i("release")
|
||||||
if (!isReleased) {
|
if (!isReleased) {
|
||||||
|
MPVLib.removeObserver(this)
|
||||||
clearVideoSurfaceView(null)
|
clearVideoSurfaceView(null)
|
||||||
MPVLib.destroy()
|
MPVLib.destroy()
|
||||||
}
|
}
|
||||||
|
|
@ -519,6 +524,14 @@ class MpvPlayer(
|
||||||
|
|
||||||
override fun event(eventId: Int) {
|
override fun event(eventId: Int) {
|
||||||
Timber.v("event: $eventId")
|
Timber.v("event: $eventId")
|
||||||
|
when (eventId) {
|
||||||
|
MPV_EVENT_FILE_LOADED -> {
|
||||||
|
Timber.d("Seeking to $startPositionMs")
|
||||||
|
if (startPositionMs > 0) {
|
||||||
|
seekTo(startPositionMs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun throwIfReleased() {
|
private fun throwIfReleased() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue