mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 23:51:21 +02:00
WIP
This commit is contained in:
parent
76825529b9
commit
c545ddf75a
2 changed files with 32 additions and 11 deletions
|
|
@ -437,7 +437,7 @@ class PlaybackViewModel
|
||||||
"changeStreams: userInitiated=$userInitiated, audioIndex=$audioIndex, subtitleIndex=$subtitleIndex, " +
|
"changeStreams: userInitiated=$userInitiated, audioIndex=$audioIndex, subtitleIndex=$subtitleIndex, " +
|
||||||
"enableDirectPlay=$enableDirectPlay, enableDirectStream=$enableDirectStream",
|
"enableDirectPlay=$enableDirectPlay, enableDirectStream=$enableDirectStream",
|
||||||
)
|
)
|
||||||
|
val playerBackend = preferences.appPreferences.playbackPreferences.playerBackend
|
||||||
// TODO if the new audio or subtitle index is already in the streams (eg direct play), should toggle in the player instead
|
// TODO if the new audio or subtitle index is already in the streams (eg direct play), should toggle in the player instead
|
||||||
val maxBitrate =
|
val maxBitrate =
|
||||||
preferences.appPreferences.playbackPreferences.maxBitrate
|
preferences.appPreferences.playbackPreferences.maxBitrate
|
||||||
|
|
@ -448,7 +448,12 @@ class PlaybackViewModel
|
||||||
itemId,
|
itemId,
|
||||||
PlaybackInfoDto(
|
PlaybackInfoDto(
|
||||||
startTimeTicks = null,
|
startTimeTicks = null,
|
||||||
deviceProfile = deviceProfile,
|
deviceProfile =
|
||||||
|
if (playerBackend == PlayerBackend.EXO_PLAYER) {
|
||||||
|
deviceProfile
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
},
|
||||||
maxAudioChannels = null,
|
maxAudioChannels = null,
|
||||||
audioStreamIndex = audioIndex,
|
audioStreamIndex = audioIndex,
|
||||||
subtitleStreamIndex = subtitleIndex,
|
subtitleStreamIndex = subtitleIndex,
|
||||||
|
|
@ -491,6 +496,7 @@ class PlaybackViewModel
|
||||||
}
|
}
|
||||||
val transcodeType =
|
val transcodeType =
|
||||||
when {
|
when {
|
||||||
|
playerBackend == PlayerBackend.MPV -> PlayMethod.DIRECT_PLAY
|
||||||
source.supportsDirectPlay -> PlayMethod.DIRECT_PLAY
|
source.supportsDirectPlay -> PlayMethod.DIRECT_PLAY
|
||||||
source.supportsDirectStream -> PlayMethod.DIRECT_STREAM
|
source.supportsDirectStream -> PlayMethod.DIRECT_STREAM
|
||||||
source.supportsTranscoding -> PlayMethod.TRANSCODE
|
source.supportsTranscoding -> PlayMethod.TRANSCODE
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ import androidx.media3.common.util.ListenerSet
|
||||||
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_END_FILE
|
||||||
import com.github.damontecres.wholphin.util.mpv.MPVLib.MpvEvent.MPV_EVENT_FILE_LOADED
|
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
|
||||||
|
|
@ -68,6 +69,7 @@ class MpvPlayer(
|
||||||
private var startPositionMs: Long = 0L
|
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
|
||||||
|
private var playbackState: Int = STATE_READY
|
||||||
|
|
||||||
var isReleased = false
|
var isReleased = false
|
||||||
private set
|
private set
|
||||||
|
|
@ -144,6 +146,9 @@ class MpvPlayer(
|
||||||
mediaItems.firstOrNull()?.let {
|
mediaItems.firstOrNull()?.let {
|
||||||
mediaItem = it
|
mediaItem = it
|
||||||
}
|
}
|
||||||
|
if (surface != null) {
|
||||||
|
loadFile()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setMediaItems(
|
override fun setMediaItems(
|
||||||
|
|
@ -188,8 +193,7 @@ class MpvPlayer(
|
||||||
|
|
||||||
override fun getPlaybackState(): Int {
|
override fun getPlaybackState(): Int {
|
||||||
if (DEBUG) Timber.v("getPlaybackState")
|
if (DEBUG) Timber.v("getPlaybackState")
|
||||||
val state = STATE_READY
|
return playbackState
|
||||||
return state
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getPlaybackSuppressionReason(): Int = Player.PLAYBACK_SUPPRESSION_REASON_NONE
|
override fun getPlaybackSuppressionReason(): Int = Player.PLAYBACK_SUPPRESSION_REASON_NONE
|
||||||
|
|
@ -206,6 +210,12 @@ class MpvPlayer(
|
||||||
} else {
|
} else {
|
||||||
MPVLib.setPropertyBoolean("pause", true)
|
MPVLib.setPropertyBoolean("pause", true)
|
||||||
}
|
}
|
||||||
|
notifyListeners(EVENT_PLAY_WHEN_READY_CHANGED) {
|
||||||
|
onPlayWhenReadyChanged(
|
||||||
|
playWhenReady,
|
||||||
|
PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getPlayWhenReady(): Boolean {
|
override fun getPlayWhenReady(): Boolean {
|
||||||
|
|
@ -377,19 +387,13 @@ class MpvPlayer(
|
||||||
throwIfReleased()
|
throwIfReleased()
|
||||||
if (DEBUG) Timber.v("setVideoSurfaceView")
|
if (DEBUG) Timber.v("setVideoSurfaceView")
|
||||||
val surface = surfaceView?.holder?.surface
|
val surface = surfaceView?.holder?.surface
|
||||||
val newSurfaceSize = if (surface == null) 0 else C.LENGTH_UNSET
|
|
||||||
this.surfaceSize = if (surface == null) Size(0, 0) else Size.UNKNOWN
|
|
||||||
if (surface != null) {
|
if (surface != null) {
|
||||||
this.surface = surface
|
this.surface = surface
|
||||||
Timber.v("Queued attach")
|
Timber.v("Queued attach")
|
||||||
MPVLib.attachSurface(surface)
|
MPVLib.attachSurface(surface)
|
||||||
MPVLib.setOptionString("force-window", "yes")
|
MPVLib.setOptionString("force-window", "yes")
|
||||||
Timber.d("Attached surface")
|
Timber.d("Attached surface")
|
||||||
|
loadFile()
|
||||||
val url = mediaItem!!.localConfiguration?.uri.toString()
|
|
||||||
MPVLib.command(arrayOf("loadfile", url))
|
|
||||||
MPVLib.setPropertyString("vo", "gpu")
|
|
||||||
Timber.d("Called loadfile")
|
|
||||||
} else {
|
} else {
|
||||||
clearVideoSurfaceView(null)
|
clearVideoSurfaceView(null)
|
||||||
}
|
}
|
||||||
|
|
@ -558,9 +562,20 @@ class MpvPlayer(
|
||||||
notifyListeners(EVENT_TRACKS_CHANGED) { onTracksChanged(it) }
|
notifyListeners(EVENT_TRACKS_CHANGED) { onTracksChanged(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
MPV_EVENT_END_FILE -> {
|
||||||
|
playbackState = STATE_ENDED
|
||||||
|
notifyListeners(EVENT_PLAYBACK_STATE_CHANGED) { onPlaybackStateChanged(STATE_ENDED) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun loadFile() {
|
||||||
|
val url = mediaItem!!.localConfiguration?.uri.toString()
|
||||||
|
MPVLib.command(arrayOf("loadfile", url))
|
||||||
|
MPVLib.setPropertyString("vo", "gpu")
|
||||||
|
Timber.d("Called loadfile")
|
||||||
|
}
|
||||||
|
|
||||||
private fun throwIfReleased() {
|
private fun throwIfReleased() {
|
||||||
if (isReleased) {
|
if (isReleased) {
|
||||||
throw IllegalStateException("Cannot access MpvPlayer after it is released")
|
throw IllegalStateException("Cannot access MpvPlayer after it is released")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue