fix chapter mark shown on start

This commit is contained in:
Christian Schabesberger 2024-09-08 15:05:57 +02:00
parent f5d3c33086
commit ba03e17088
5 changed files with 35 additions and 20 deletions

View File

@ -20,6 +20,7 @@
package net.newpipe.newplayer.model package net.newpipe.newplayer.model
import android.content.pm.ActivityInfo
import android.os.Parcelable import android.os.Parcelable
import kotlinx.android.parcel.Parcelize import kotlinx.android.parcel.Parcelize
@ -31,4 +32,12 @@ data class EmbeddedUiConfig(
val systemBarInLightMode: Boolean, val systemBarInLightMode: Boolean,
val brightness: Float, val brightness: Float,
val screenOrientation: Int val screenOrientation: Int
) : Parcelable ) : Parcelable {
companion object {
val DUMMY = EmbeddedUiConfig(
systemBarInLightMode = true,
brightness = -1f,
screenOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
)
}
}

View File

@ -83,7 +83,7 @@ data class VideoPlayerUIState(
isLoading = false, isLoading = false,
durationInMs = 12000, durationInMs = 12000,
playbackPositionInPlaylistS = 5039, playbackPositionInPlaylistS = 5039,
playbackPositionInMs = 69, playbackPositionInMs = 400,
fastSeekSeconds = 10, fastSeekSeconds = 10,
soundVolume = 0.5f, soundVolume = 0.5f,
brightness = 0.2f, brightness = 0.2f,

View File

@ -388,7 +388,6 @@ private fun Track(
) )
} }
// clear segment gaps
for (index in chapterSegments.indices) { for (index in chapterSegments.indices) {
val segment = chapterSegments[index] val segment = chapterSegments[index]
drawDot( drawDot(

View File

@ -84,10 +84,8 @@ internal fun chapterSegmentToPxValues(
): List<SegmentPxs> { ): List<SegmentPxs> {
val rangeSize = range.endInclusive - range.start val rangeSize = range.endInclusive - range.start
val sortedSegments = ArrayList(segments.distinct().sortedBy { it.start }) val sortedSegments = segments.distinct().sortedBy { it.start }
if(sortedSegments.isNotEmpty()) {
sortedSegments.removeAt(0)
}
val segmentStartPxs = sortedSegments.map { segment -> val segmentStartPxs = sortedSegments.map { segment ->
// percent of the start of this segment in the range size // percent of the start of this segment in the range size

View File

@ -47,6 +47,7 @@ import androidx.core.os.ConfigurationCompat
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import net.newpipe.newplayer.Chapter import net.newpipe.newplayer.Chapter
import net.newpipe.newplayer.R import net.newpipe.newplayer.R
import net.newpipe.newplayer.model.EmbeddedUiConfig
import net.newpipe.newplayer.model.UIModeState import net.newpipe.newplayer.model.UIModeState
import net.newpipe.newplayer.model.VideoPlayerUIState import net.newpipe.newplayer.model.VideoPlayerUIState
import net.newpipe.newplayer.model.VideoPlayerViewModel import net.newpipe.newplayer.model.VideoPlayerViewModel
@ -87,7 +88,11 @@ fun BottomUI(
Text(getTimeStringFromMs(uiState.durationInMs, getLocale() ?: locale)) Text(getTimeStringFromMs(uiState.durationInMs, getLocale() ?: locale))
val embeddedUiConfig = getEmbeddedUiConfig(LocalContext.current as Activity) val embeddedUiConfig = when (LocalContext.current) {
is Activity -> getEmbeddedUiConfig(LocalContext.current as Activity)
else -> EmbeddedUiConfig.DUMMY
}
IconButton( IconButton(
onClick = if (uiState.uiMode.fullscreen) viewModel::switchToEmbeddedView onClick = if (uiState.uiMode.fullscreen) viewModel::switchToEmbeddedView
else { else {
@ -105,6 +110,7 @@ fun BottomUI(
} }
} }
@Composable @Composable
private fun customizedSeekerColors(): SeekerColors { private fun customizedSeekerColors(): SeekerColors {
val colors = DefaultSeekerColor( val colors = DefaultSeekerColor(
@ -120,18 +126,22 @@ private fun customizedSeekerColors(): SeekerColors {
} }
private fun getSeekerSegmentsFromChapters(chapters: List<Chapter>, duration: Long) = private fun getSeekerSegmentsFromChapters(chapters: List<Chapter>, duration: Long) =
chapters.map { chapter -> chapters
val markPosition = chapter.chapterStartInMs.toFloat() / duration.toFloat() .filter { chapter ->
if (markPosition < 0f || 1f < markPosition) { if (chapter.chapterStartInMs in 1..<duration) {
Log.e( true
TAG, } else {
"Chapter mark outside of stream duration range: chapter: ${chapter.chapterTitle}, mark in ms: ${chapter.chapterStartInMs}, vidoe duration in ms: ${duration}" Log.e(
) TAG,
ChapterSegment(name = chapter.chapterTitle ?: "", start = 0f) "Chapter mark outside of stream duration range: chapter: ${chapter.chapterTitle}, mark in ms: ${chapter.chapterStartInMs}, video duration in ms: ${duration}"
} else { )
false
}
}
.map { chapter ->
val markPosition = chapter.chapterStartInMs.toFloat() / duration.toFloat()
ChapterSegment(name = chapter.chapterTitle ?: "", start = markPosition) ChapterSegment(name = chapter.chapterTitle ?: "", start = markPosition)
} }
}
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
@ -148,8 +158,7 @@ fun VideoPlayerControllerBottomUIPreview() {
viewModel = VideoPlayerViewModelDummy(), viewModel = VideoPlayerViewModelDummy(),
uiState = VideoPlayerUIState.DUMMY.copy( uiState = VideoPlayerUIState.DUMMY.copy(
uiMode = UIModeState.FULLSCREEN_VIDEO_CONTROLLER_UI, uiMode = UIModeState.FULLSCREEN_VIDEO_CONTROLLER_UI,
seekerPosition = 0.4f, seekerPosition = 0.2f,
durationInMs = 90 * 60 * 1000,
playbackPositionInMs = 3 * 60 * 1000, playbackPositionInMs = 3 * 60 * 1000,
bufferedPercentage = 0.4f bufferedPercentage = 0.4f
), ),