make fast seek foo work
This commit is contained in:
parent
545f9d6650
commit
a5c9baa26d
|
@ -52,8 +52,6 @@ interface NewPlayer {
|
||||||
fun prepare()
|
fun prepare()
|
||||||
fun play()
|
fun play()
|
||||||
fun pause()
|
fun pause()
|
||||||
fun fastSeek(steps: Int)
|
|
||||||
fun seekTo(millisecond: Long)
|
|
||||||
fun addToPlaylist(newItem: String)
|
fun addToPlaylist(newItem: String)
|
||||||
fun addListener(callbackListener: Listener)
|
fun addListener(callbackListener: Listener)
|
||||||
|
|
||||||
|
@ -85,9 +83,15 @@ class NewPlayerImpl(override val internal_player: Player, override val repositor
|
||||||
|
|
||||||
private var callbackListeners: MutableList<NewPlayer.Listener> = ArrayList()
|
private var callbackListeners: MutableList<NewPlayer.Listener> = ArrayList()
|
||||||
|
|
||||||
override val duartion: Long = internal_player.duration
|
override val duartion: Long
|
||||||
override val bufferedPercentage: Int = internal_player.bufferedPercentage
|
get() = internal_player.duration
|
||||||
override var currentPosition: Long = internal_player.currentPosition
|
|
||||||
|
override val bufferedPercentage: Int
|
||||||
|
get() = internal_player.bufferedPercentage
|
||||||
|
override var currentPosition: Long
|
||||||
|
get() = internal_player.currentPosition
|
||||||
|
set(value) {internal_player.seekTo(value)}
|
||||||
|
|
||||||
override var fastSeekAmountSec: Int = 10
|
override var fastSeekAmountSec: Int = 10
|
||||||
override var playBackMode: PlayMode = PlayMode.EMBEDDED_VIDEO
|
override var playBackMode: PlayMode = PlayMode.EMBEDDED_VIDEO
|
||||||
override var playList: MutableList<String> = ArrayList<String>()
|
override var playList: MutableList<String> = ArrayList<String>()
|
||||||
|
@ -114,15 +118,6 @@ class NewPlayerImpl(override val internal_player: Player, override val repositor
|
||||||
internal_player.pause()
|
internal_player.pause()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fastSeek(steps: Int) {
|
|
||||||
val currentPosition = internal_player.currentPosition
|
|
||||||
internal_player.seekTo(currentPosition + fastSeekAmountSec * 1000 * steps)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun seekTo(millisecond: Long) {
|
|
||||||
internal_player.seekTo(millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun addToPlaylist(newItem: String) {
|
override fun addToPlaylist(newItem: String) {
|
||||||
Log.d(TAG, "Not implemented add to playlist")
|
Log.d(TAG, "Not implemented add to playlist")
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ import net.newpipe.newplayer.ui.ContentScale
|
||||||
|
|
||||||
interface VideoPlayerViewModel {
|
interface VideoPlayerViewModel {
|
||||||
var newPlayer: NewPlayer?
|
var newPlayer: NewPlayer?
|
||||||
val player: Player?
|
val internalPlayer: Player?
|
||||||
val uiState: StateFlow<VideoPlayerUIState>
|
val uiState: StateFlow<VideoPlayerUIState>
|
||||||
var minContentRatio: Float
|
var minContentRatio: Float
|
||||||
var maxContentRatio: Float
|
var maxContentRatio: Float
|
||||||
|
|
|
@ -65,12 +65,11 @@ class VideoPlayerViewModelImpl @Inject constructor(
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
installExoPlayer()
|
installExoPlayer()
|
||||||
mutableUiState.update { it.copy(fastseekSeconds = field?.fastSeekAmountSec ?: 10) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override val uiState = mutableUiState.asStateFlow()
|
override val uiState = mutableUiState.asStateFlow()
|
||||||
|
|
||||||
override val player: Player?
|
override val internalPlayer: Player?
|
||||||
get() = newPlayer?.internal_player
|
get() = newPlayer?.internal_player
|
||||||
|
|
||||||
override var minContentRatio: Float = 4F / 3F
|
override var minContentRatio: Float = 4F / 3F
|
||||||
|
@ -109,7 +108,7 @@ class VideoPlayerViewModelImpl @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun installExoPlayer() {
|
private fun installExoPlayer() {
|
||||||
player?.let { player ->
|
internalPlayer?.let { player ->
|
||||||
Log.d(TAG, "Install player: ${player.videoSize.width}")
|
Log.d(TAG, "Install player: ${player.videoSize.width}")
|
||||||
|
|
||||||
player.addListener(object : Player.Listener {
|
player.addListener(object : Player.Listener {
|
||||||
|
@ -228,9 +227,9 @@ class VideoPlayerViewModelImpl @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateProgressOnce() {
|
private fun updateProgressOnce() {
|
||||||
val progress = player?.currentPosition ?: 0
|
val progress = internalPlayer?.currentPosition ?: 0
|
||||||
val duration = player?.duration ?: 1
|
val duration = internalPlayer?.duration ?: 1
|
||||||
val bufferedPercentage = (player?.bufferedPercentage?.toFloat() ?: 0f) / 100f
|
val bufferedPercentage = (internalPlayer?.bufferedPercentage?.toFloat() ?: 0f) / 100f
|
||||||
val progressPercentage = progress.toFloat() / duration.toFloat()
|
val progressPercentage = progress.toFloat() / duration.toFloat()
|
||||||
|
|
||||||
mutableUiState.update {
|
mutableUiState.update {
|
||||||
|
@ -259,8 +258,8 @@ class VideoPlayerViewModelImpl @Inject constructor(
|
||||||
override fun seekingFinished() {
|
override fun seekingFinished() {
|
||||||
resetHideUiDelayedJob()
|
resetHideUiDelayedJob()
|
||||||
val seekerPosition = mutableUiState.value.seekerPosition
|
val seekerPosition = mutableUiState.value.seekerPosition
|
||||||
val seekPositionInMs = (player?.duration?.toFloat() ?: 0F) * seekerPosition
|
val seekPositionInMs = (internalPlayer?.duration?.toFloat() ?: 0F) * seekerPosition
|
||||||
newPlayer?.seekTo(seekPositionInMs.toLong())
|
newPlayer?.currentPosition = seekPositionInMs.toLong()
|
||||||
Log.i(TAG, "Seek to Ms: $seekPositionInMs")
|
Log.i(TAG, "Seek to Ms: $seekPositionInMs")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,7 +281,9 @@ class VideoPlayerViewModelImpl @Inject constructor(
|
||||||
|
|
||||||
override fun fastSeekFinished() {
|
override fun fastSeekFinished() {
|
||||||
val fastSeekAmount = mutableUiState.value.fastseekSeconds
|
val fastSeekAmount = mutableUiState.value.fastseekSeconds
|
||||||
newPlayer?.fastSeek(fastSeekAmount)
|
Log.d(TAG, "$fastSeekAmount")
|
||||||
|
|
||||||
|
newPlayer?.currentPosition = (newPlayer?.currentPosition ?: 0) + (fastSeekAmount * 1000)
|
||||||
mutableUiState.update {
|
mutableUiState.update {
|
||||||
it.copy(fastseekSeconds = 0)
|
it.copy(fastseekSeconds = 0)
|
||||||
}
|
}
|
||||||
|
@ -306,7 +307,7 @@ class VideoPlayerViewModelImpl @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getEmbeddedUiRatio() =
|
private fun getEmbeddedUiRatio() =
|
||||||
player?.let { player ->
|
internalPlayer?.let { player ->
|
||||||
val videoRatio = VideoSize.fromMedia3VideoSize(player.videoSize).getRatio()
|
val videoRatio = VideoSize.fromMedia3VideoSize(player.videoSize).getRatio()
|
||||||
return (if (videoRatio.isNaN())
|
return (if (videoRatio.isNaN())
|
||||||
currentContentRatio
|
currentContentRatio
|
||||||
|
@ -320,7 +321,7 @@ class VideoPlayerViewModelImpl @Inject constructor(
|
||||||
companion object {
|
companion object {
|
||||||
val dummy = object : VideoPlayerViewModel {
|
val dummy = object : VideoPlayerViewModel {
|
||||||
override var newPlayer: NewPlayer? = null
|
override var newPlayer: NewPlayer? = null
|
||||||
override val player: Player? = null
|
override val internalPlayer: Player? = null
|
||||||
override val uiState = MutableStateFlow(VideoPlayerUIState.DEFAULT)
|
override val uiState = MutableStateFlow(VideoPlayerUIState.DEFAULT)
|
||||||
override var minContentRatio = 4F / 3F
|
override var minContentRatio = 4F / 3F
|
||||||
override var maxContentRatio = 16F / 9F
|
override var maxContentRatio = 16F / 9F
|
||||||
|
|
|
@ -62,7 +62,7 @@ fun VideoPlayerUI(
|
||||||
) {
|
) {
|
||||||
if (viewModel == null) {
|
if (viewModel == null) {
|
||||||
VideoPlayerLoadingPlaceholder()
|
VideoPlayerLoadingPlaceholder()
|
||||||
} else if (viewModel.player == null) {
|
} else if (viewModel.internalPlayer == null) {
|
||||||
VideoPlayerLoadingPlaceholder(viewModel.uiState.collectAsState().value.embeddedUiRatio)
|
VideoPlayerLoadingPlaceholder(viewModel.uiState.collectAsState().value.embeddedUiRatio)
|
||||||
} else {
|
} else {
|
||||||
val uiState by viewModel.uiState.collectAsState()
|
val uiState by viewModel.uiState.collectAsState()
|
||||||
|
@ -136,7 +136,7 @@ fun VideoPlayerUI(
|
||||||
) {
|
) {
|
||||||
Box(contentAlignment = Alignment.Center) {
|
Box(contentAlignment = Alignment.Center) {
|
||||||
PlaySurface(
|
PlaySurface(
|
||||||
player = viewModel.player,
|
player = viewModel.internalPlayer,
|
||||||
lifecycle = lifecycle,
|
lifecycle = lifecycle,
|
||||||
fitMode = uiState.contentFitMode,
|
fitMode = uiState.contentFitMode,
|
||||||
uiRatio = if (uiState.fullscreen) screenRatio else uiState.embeddedUiRatio,
|
uiRatio = if (uiState.fullscreen) screenRatio else uiState.embeddedUiRatio,
|
||||||
|
|
Loading…
Reference in New Issue