mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
Merge pull request #2502 from Bnyro/sponsorblock-duration
Show the video duration when SponsorBlock segments get skipped
This commit is contained in:
commit
cf918979ae
@ -701,6 +701,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
playerBinding.exoProgress.setSegments(segmentData.segments)
|
playerBinding.exoProgress.setSegments(segmentData.segments)
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
playerBinding.sbToggle.visibility = View.VISIBLE
|
playerBinding.sbToggle.visibility = View.VISIBLE
|
||||||
|
updateDisplayedDuration()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -711,18 +712,17 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
// switch back to normal speed when on the end of live stream
|
// switch back to normal speed when on the end of live stream
|
||||||
if (exoPlayer.duration - exoPlayer.currentPosition < 7000) {
|
if (exoPlayer.duration - exoPlayer.currentPosition < 7000) {
|
||||||
exoPlayer.setPlaybackSpeed(1F)
|
exoPlayer.setPlaybackSpeed(1F)
|
||||||
playerBinding.liveSeparator.visibility = View.GONE
|
playerBinding.timeSeparator.visibility = View.GONE
|
||||||
playerBinding.liveDiff.text = ""
|
playerBinding.liveDiff.text = ""
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG(), "changing the time")
|
|
||||||
// live stream but not watching at the end/live position
|
// live stream but not watching at the end/live position
|
||||||
playerBinding.liveSeparator.visibility = View.VISIBLE
|
playerBinding.timeSeparator.visibility = View.VISIBLE
|
||||||
val diffText = DateUtils.formatElapsedTime(
|
val diffText = DateUtils.formatElapsedTime(
|
||||||
(exoPlayer.duration - exoPlayer.currentPosition) / 1000
|
(exoPlayer.duration - exoPlayer.currentPosition) / 1000
|
||||||
)
|
)
|
||||||
playerBinding.liveDiff.text = "-$diffText"
|
playerBinding.liveDiff.text = "-$diffText"
|
||||||
}
|
}
|
||||||
// call it again
|
// call the function again after 100ms
|
||||||
handler
|
handler
|
||||||
.postDelayed(this@PlayerFragment::refreshLiveStatus, 100)
|
.postDelayed(this@PlayerFragment::refreshLiveStatus, 100)
|
||||||
}
|
}
|
||||||
@ -745,9 +745,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
// position is almost the end of the video => don't seek, start from beginning
|
// position is almost the end of the video => don't seek, start from beginning
|
||||||
if (position != null && position < streams.duration!! * 1000 * 0.9) {
|
if (position != null && position < streams.duration!! * 1000 * 0.9) {
|
||||||
exoPlayer.seekTo(
|
exoPlayer.seekTo(position)
|
||||||
position
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -798,10 +796,11 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun handleLiveVideo() {
|
private fun handleLiveVideo() {
|
||||||
playerBinding.exoTime.visibility = View.GONE
|
playerBinding.exoPosition.visibility = View.GONE
|
||||||
playerBinding.liveLL.visibility = View.VISIBLE
|
playerBinding.liveDiff.visibility = View.VISIBLE
|
||||||
playerBinding.liveIndicator.setOnClickListener {
|
playerBinding.duration.text = getString(R.string.live)
|
||||||
exoPlayer.seekTo(exoPlayer.duration - 1000)
|
playerBinding.exoTime.setOnClickListener {
|
||||||
|
exoPlayer.seekTo(exoPlayer.duration)
|
||||||
}
|
}
|
||||||
refreshLiveStatus()
|
refreshLiveStatus()
|
||||||
}
|
}
|
||||||
@ -883,6 +882,8 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onPlaybackStateChanged(playbackState: Int) {
|
override fun onPlaybackStateChanged(playbackState: Int) {
|
||||||
|
updateDisplayedDuration()
|
||||||
|
|
||||||
exoPlayerView.keepScreenOn = !(
|
exoPlayerView.keepScreenOn = !(
|
||||||
playbackState == Player.STATE_IDLE ||
|
playbackState == Player.STATE_IDLE ||
|
||||||
playbackState == Player.STATE_ENDED
|
playbackState == Player.STATE_ENDED
|
||||||
@ -997,6 +998,29 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the displayed duration of the video
|
||||||
|
*/
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
|
private fun updateDisplayedDuration() {
|
||||||
|
if (exoPlayer.duration == Long.MAX_VALUE || isLive) return
|
||||||
|
|
||||||
|
val durationWithSponsorBlock = if (
|
||||||
|
!this::segmentData.isInitialized || this.segmentData.segments.isEmpty()
|
||||||
|
) {
|
||||||
|
null
|
||||||
|
} else {
|
||||||
|
val difference = segmentData.segments.sumOf {
|
||||||
|
it.segment[1] - it.segment[0]
|
||||||
|
}.toInt()
|
||||||
|
DateUtils.formatElapsedTime(exoPlayer.duration.div(1000) - difference)
|
||||||
|
}
|
||||||
|
|
||||||
|
playerBinding.duration.text = DateUtils.formatElapsedTime(
|
||||||
|
exoPlayer.duration.div(1000)
|
||||||
|
) + if (durationWithSponsorBlock != null) " ($durationWithSponsorBlock)" else ""
|
||||||
|
}
|
||||||
|
|
||||||
private fun syncQueueButtons() {
|
private fun syncQueueButtons() {
|
||||||
if (!PlayerHelper.skipButtonsEnabled) return
|
if (!PlayerHelper.skipButtonsEnabled) return
|
||||||
|
|
||||||
@ -1267,7 +1291,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
// control for the track sources like subtitles and audio source
|
// control for the track sources like subtitles and audio source
|
||||||
trackSelector = DefaultTrackSelector(requireContext())
|
trackSelector = DefaultTrackSelector(requireContext())
|
||||||
|
|
||||||
val params = trackSelector.updateParameters {
|
trackSelector.updateParameters {
|
||||||
setPreferredAudioLanguage(
|
setPreferredAudioLanguage(
|
||||||
Locale.getDefault().language.lowercase().substring(0, 2)
|
Locale.getDefault().language.lowercase().substring(0, 2)
|
||||||
)
|
)
|
||||||
|
@ -224,45 +224,22 @@
|
|||||||
android:text="00:00"
|
android:text="00:00"
|
||||||
tools:ignore="HardcodedText" />
|
tools:ignore="HardcodedText" />
|
||||||
|
|
||||||
<TextView
|
|
||||||
style="@style/TimeString"
|
|
||||||
android:text=" • "
|
|
||||||
tools:ignore="HardcodedText" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@id/exo_duration"
|
|
||||||
style="@style/TimeString"
|
|
||||||
android:text="00:00"
|
|
||||||
tools:ignore="HardcodedText" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/liveLL"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:layout_marginStart="10dp"
|
|
||||||
android:visibility="gone">
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/liveDiff"
|
android:id="@+id/liveDiff"
|
||||||
style="@style/TimeString"
|
style="@style/TimeString"
|
||||||
tools:text="05:10" />
|
tools:text="05:10"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/liveSeparator"
|
android:id="@+id/time_separator"
|
||||||
style="@style/TimeString"
|
style="@style/TimeString"
|
||||||
android:layout_marginHorizontal="5dp"
|
|
||||||
android:paddingHorizontal="0dp"
|
|
||||||
android:text=" • "
|
android:text=" • "
|
||||||
android:visibility="gone"
|
|
||||||
tools:ignore="HardcodedText" />
|
tools:ignore="HardcodedText" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/liveIndicator"
|
android:id="@+id/duration"
|
||||||
style="@style/TimeString"
|
style="@style/TimeString"
|
||||||
android:text="@string/live" />
|
tools:text="00:00" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user