fix chapter mark shown on start
This commit is contained in:
parent
f5d3c33086
commit
ba03e17088
|
@ -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
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
|
@ -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,
|
||||||
|
|
|
@ -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(
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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) {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
Log.e(
|
Log.e(
|
||||||
TAG,
|
TAG,
|
||||||
"Chapter mark outside of stream duration range: chapter: ${chapter.chapterTitle}, mark in ms: ${chapter.chapterStartInMs}, vidoe duration in ms: ${duration}"
|
"Chapter mark outside of stream duration range: chapter: ${chapter.chapterTitle}, mark in ms: ${chapter.chapterStartInMs}, video duration in ms: ${duration}"
|
||||||
)
|
)
|
||||||
ChapterSegment(name = chapter.chapterTitle ?: "", start = 0f)
|
false
|
||||||
} else {
|
|
||||||
ChapterSegment(name = chapter.chapterTitle ?: "", start = markPosition)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.map { chapter ->
|
||||||
|
val markPosition = chapter.chapterStartInMs.toFloat() / duration.toFloat()
|
||||||
|
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
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in New Issue