fix chapter mark shown on start
This commit is contained in:
parent
f5d3c33086
commit
ba03e17088
|
@ -20,6 +20,7 @@
|
|||
|
||||
package net.newpipe.newplayer.model
|
||||
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.os.Parcelable
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
|
||||
|
@ -31,4 +32,12 @@ data class EmbeddedUiConfig(
|
|||
val systemBarInLightMode: Boolean,
|
||||
val brightness: Float,
|
||||
val screenOrientation: Int
|
||||
) : Parcelable
|
||||
) : Parcelable {
|
||||
companion object {
|
||||
val DUMMY = EmbeddedUiConfig(
|
||||
systemBarInLightMode = true,
|
||||
brightness = -1f,
|
||||
screenOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||
)
|
||||
}
|
||||
}
|
|
@ -83,7 +83,7 @@ data class VideoPlayerUIState(
|
|||
isLoading = false,
|
||||
durationInMs = 12000,
|
||||
playbackPositionInPlaylistS = 5039,
|
||||
playbackPositionInMs = 69,
|
||||
playbackPositionInMs = 400,
|
||||
fastSeekSeconds = 10,
|
||||
soundVolume = 0.5f,
|
||||
brightness = 0.2f,
|
||||
|
|
|
@ -388,7 +388,6 @@ private fun Track(
|
|||
)
|
||||
}
|
||||
|
||||
// clear segment gaps
|
||||
for (index in chapterSegments.indices) {
|
||||
val segment = chapterSegments[index]
|
||||
drawDot(
|
||||
|
|
|
@ -84,10 +84,8 @@ internal fun chapterSegmentToPxValues(
|
|||
): List<SegmentPxs> {
|
||||
|
||||
val rangeSize = range.endInclusive - range.start
|
||||
val sortedSegments = ArrayList(segments.distinct().sortedBy { it.start })
|
||||
if(sortedSegments.isNotEmpty()) {
|
||||
sortedSegments.removeAt(0)
|
||||
}
|
||||
val sortedSegments = segments.distinct().sortedBy { it.start }
|
||||
|
||||
val segmentStartPxs = sortedSegments.map { segment ->
|
||||
|
||||
// percent of the start of this segment in the range size
|
||||
|
|
|
@ -47,6 +47,7 @@ import androidx.core.os.ConfigurationCompat
|
|||
import androidx.lifecycle.viewModelScope
|
||||
import net.newpipe.newplayer.Chapter
|
||||
import net.newpipe.newplayer.R
|
||||
import net.newpipe.newplayer.model.EmbeddedUiConfig
|
||||
import net.newpipe.newplayer.model.UIModeState
|
||||
import net.newpipe.newplayer.model.VideoPlayerUIState
|
||||
import net.newpipe.newplayer.model.VideoPlayerViewModel
|
||||
|
@ -87,7 +88,11 @@ fun BottomUI(
|
|||
|
||||
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(
|
||||
onClick = if (uiState.uiMode.fullscreen) viewModel::switchToEmbeddedView
|
||||
else {
|
||||
|
@ -105,6 +110,7 @@ fun BottomUI(
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
private fun customizedSeekerColors(): SeekerColors {
|
||||
val colors = DefaultSeekerColor(
|
||||
|
@ -120,18 +126,22 @@ private fun customizedSeekerColors(): SeekerColors {
|
|||
}
|
||||
|
||||
private fun getSeekerSegmentsFromChapters(chapters: List<Chapter>, duration: Long) =
|
||||
chapters.map { chapter ->
|
||||
val markPosition = chapter.chapterStartInMs.toFloat() / duration.toFloat()
|
||||
if (markPosition < 0f || 1f < markPosition) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Chapter mark outside of stream duration range: chapter: ${chapter.chapterTitle}, mark in ms: ${chapter.chapterStartInMs}, vidoe duration in ms: ${duration}"
|
||||
)
|
||||
ChapterSegment(name = chapter.chapterTitle ?: "", start = 0f)
|
||||
} else {
|
||||
chapters
|
||||
.filter { chapter ->
|
||||
if (chapter.chapterStartInMs in 1..<duration) {
|
||||
true
|
||||
} else {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Chapter mark outside of stream duration range: chapter: ${chapter.chapterTitle}, mark in ms: ${chapter.chapterStartInMs}, video duration in ms: ${duration}"
|
||||
)
|
||||
false
|
||||
}
|
||||
}
|
||||
.map { chapter ->
|
||||
val markPosition = chapter.chapterStartInMs.toFloat() / duration.toFloat()
|
||||
ChapterSegment(name = chapter.chapterTitle ?: "", start = markPosition)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
@ -148,8 +158,7 @@ fun VideoPlayerControllerBottomUIPreview() {
|
|||
viewModel = VideoPlayerViewModelDummy(),
|
||||
uiState = VideoPlayerUIState.DUMMY.copy(
|
||||
uiMode = UIModeState.FULLSCREEN_VIDEO_CONTROLLER_UI,
|
||||
seekerPosition = 0.4f,
|
||||
durationInMs = 90 * 60 * 1000,
|
||||
seekerPosition = 0.2f,
|
||||
playbackPositionInMs = 3 * 60 * 1000,
|
||||
bufferedPercentage = 0.4f
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue