mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
Fix SponsorBlock segment loop at end of video
This commit is contained in:
parent
9746d5a5fd
commit
e4627fd156
@ -26,6 +26,7 @@ import com.google.android.exoplayer2.PlaybackParameters
|
||||
import com.google.android.exoplayer2.audio.AudioAttributes
|
||||
import com.google.android.exoplayer2.ui.CaptionStyleCompat
|
||||
import com.google.android.exoplayer2.video.VideoSize
|
||||
import kotlin.math.absoluteValue
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
object PlayerHelper {
|
||||
@ -485,10 +486,18 @@ object PlayerHelper {
|
||||
* @param skipManually Whether the event gets handled by the function caller
|
||||
* @return If segment found and [skipManually] is true, the end position of the segment in ms, otherwise null
|
||||
*/
|
||||
fun ExoPlayer.checkForSegments(context: Context, segments: List<Segment>, skipManually: Boolean = false): Long? {
|
||||
segments.forEach { segment ->
|
||||
fun ExoPlayer.checkForSegments(
|
||||
context: Context,
|
||||
segments: List<Segment>,
|
||||
skipManually: Boolean = false
|
||||
): Long? {
|
||||
for (segment in segments) {
|
||||
val segmentStart = (segment.segment[0] * 1000f).toLong()
|
||||
val segmentEnd = (segment.segment[1] * 1000f).toLong()
|
||||
|
||||
// avoid seeking to the same segment multiple times, e.g. when the SB segment is at the end of the video
|
||||
if ((duration - currentPosition).absoluteValue < 500) continue
|
||||
|
||||
if (currentPosition in segmentStart until segmentEnd) {
|
||||
if (!skipManually) {
|
||||
if (sponsorBlockNotifications) {
|
||||
|
@ -112,6 +112,7 @@ class BackgroundMode : LifecycleService() {
|
||||
val notification: Notification = Notification.Builder(this, BACKGROUND_CHANNEL_ID)
|
||||
.setContentTitle(getString(R.string.app_name))
|
||||
.setContentText(getString(R.string.playingOnBackground))
|
||||
.setSmallIcon(R.drawable.ic_launcher_lockscreen)
|
||||
.build()
|
||||
|
||||
startForeground(PLAYER_NOTIFICATION_ID, notification)
|
||||
|
@ -114,6 +114,10 @@ import com.google.android.exoplayer2.ui.StyledPlayerView
|
||||
import com.google.android.exoplayer2.upstream.DefaultDataSource
|
||||
import com.google.android.exoplayer2.util.MimeTypes
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
import java.util.concurrent.Executors
|
||||
import kotlin.math.abs
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
@ -121,10 +125,6 @@ import kotlinx.coroutines.withContext
|
||||
import kotlinx.datetime.LocalDate
|
||||
import kotlinx.serialization.encodeToString
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
import java.util.concurrent.Executors
|
||||
import kotlin.math.abs
|
||||
|
||||
class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user