mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
more cleanup + more features for the offline player
This commit is contained in:
parent
ef4e48e347
commit
e718937dd6
@ -5,7 +5,6 @@ import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.app.Service
|
||||
import android.content.Intent
|
||||
import android.media.session.PlaybackState
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.IBinder
|
||||
@ -18,8 +17,6 @@ import com.github.libretube.constants.BACKGROUND_CHANNEL_ID
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.constants.PLAYER_NOTIFICATION_ID
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
import com.github.libretube.db.DatabaseHelper
|
||||
import com.github.libretube.extensions.query
|
||||
import com.github.libretube.extensions.toID
|
||||
import com.github.libretube.util.AutoPlayHelper
|
||||
import com.github.libretube.util.NowPlayingNotification
|
||||
@ -89,8 +86,6 @@ class BackgroundMode : Service() {
|
||||
/**
|
||||
* Autoplay Preference
|
||||
*/
|
||||
private val autoplay = PreferenceHelper.getBoolean(PreferenceKeys.AUTO_PLAY, true)
|
||||
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
|
||||
/**
|
||||
@ -191,7 +186,7 @@ class BackgroundMode : Service() {
|
||||
|
||||
fetchSponsorBlockSegments()
|
||||
|
||||
if (autoplay) setNextStream()
|
||||
if (PlayerHelper.autoPlayEnabled) setNextStream()
|
||||
}
|
||||
|
||||
/**
|
||||
@ -217,21 +212,13 @@ class BackgroundMode : Service() {
|
||||
override fun onPlaybackStateChanged(state: Int) {
|
||||
when (state) {
|
||||
Player.STATE_ENDED -> {
|
||||
if (autoplay) playNextVideo()
|
||||
if (PlayerHelper.autoPlayEnabled) playNextVideo()
|
||||
}
|
||||
Player.STATE_IDLE -> {
|
||||
onDestroy()
|
||||
}
|
||||
Player.STATE_BUFFERING -> {}
|
||||
Player.STATE_READY -> {}
|
||||
PlaybackState.STATE_PAUSED -> {
|
||||
query {
|
||||
DatabaseHelper.saveWatchPosition(
|
||||
videoId,
|
||||
player?.currentPosition ?: 0L
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -332,11 +319,7 @@ class BackgroundMode : Service() {
|
||||
val segmentEnd = (segment.segment[1] * 1000f).toLong()
|
||||
val currentPosition = player?.currentPosition
|
||||
if (currentPosition in segmentStart until segmentEnd) {
|
||||
if (PreferenceHelper.getBoolean(
|
||||
"sb_notifications_key",
|
||||
true
|
||||
)
|
||||
) {
|
||||
if (PlayerHelper.sponsorBlockNotifications) {
|
||||
try {
|
||||
Toast.makeText(this, R.string.segment_skipped, Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
|
@ -13,13 +13,11 @@ import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.WindowInsetsControllerCompat
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
import com.github.libretube.databinding.ActivityOfflinePlayerBinding
|
||||
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
|
||||
import com.github.libretube.ui.base.BaseActivity
|
||||
import com.github.libretube.util.DownloadHelper
|
||||
import com.github.libretube.util.PlayerHelper
|
||||
import com.github.libretube.util.PreferenceHelper
|
||||
import com.google.android.exoplayer2.ExoPlayer
|
||||
import com.google.android.exoplayer2.MediaItem
|
||||
import com.google.android.exoplayer2.source.MergingMediaSource
|
||||
@ -165,13 +163,7 @@ class OfflinePlayerActivity : BaseActivity() {
|
||||
override fun onUserLeaveHint() {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
|
||||
|
||||
if (!PreferenceHelper.getBoolean(
|
||||
PreferenceKeys.PICTURE_IN_PICTURE,
|
||||
true
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
if (!PlayerHelper.pipEnabled) return
|
||||
|
||||
if (player.playbackState == PlaybackState.STATE_PAUSED) return
|
||||
|
||||
|
@ -10,7 +10,6 @@ import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
import com.github.libretube.databinding.DoubleTapOverlayBinding
|
||||
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
|
||||
import com.github.libretube.models.interfaces.DoubleTapInterface
|
||||
@ -19,13 +18,12 @@ import com.github.libretube.obj.BottomSheetItem
|
||||
import com.github.libretube.ui.activities.MainActivity
|
||||
import com.github.libretube.ui.sheets.PlaybackSpeedSheet
|
||||
import com.github.libretube.util.DoubleTapListener
|
||||
import com.github.libretube.util.PreferenceHelper
|
||||
import com.github.libretube.util.PlayerHelper
|
||||
import com.google.android.exoplayer2.PlaybackParameters
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelector
|
||||
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout
|
||||
import com.google.android.exoplayer2.ui.StyledPlayerView
|
||||
import com.google.android.exoplayer2.util.RepeatModeUtil
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
internal class CustomExoPlayerView(
|
||||
@ -53,27 +51,9 @@ internal class CustomExoPlayerView(
|
||||
/**
|
||||
* Preferences
|
||||
*/
|
||||
var autoplayEnabled = PreferenceHelper.getBoolean(
|
||||
PreferenceKeys.AUTO_PLAY,
|
||||
true
|
||||
)
|
||||
var autoplayEnabled = PlayerHelper.autoPlayEnabled
|
||||
|
||||
private val playbackSpeed = PreferenceHelper.getString(
|
||||
PreferenceKeys.PLAYBACK_SPEED,
|
||||
"1"
|
||||
).replace("F", "")
|
||||
|
||||
private val seekIncrement = PreferenceHelper.getString(
|
||||
PreferenceKeys.SEEK_INCREMENT,
|
||||
"10.0"
|
||||
).toFloat()
|
||||
.roundToInt()
|
||||
.toLong() * 1000
|
||||
|
||||
private var resizeModePref = PreferenceHelper.getString(
|
||||
PreferenceKeys.PLAYER_RESIZE_MODE,
|
||||
"fit"
|
||||
)
|
||||
private var resizeModePref = PlayerHelper.resizeModePref
|
||||
|
||||
private fun toggleController() {
|
||||
if (isControllerFullyVisible) hideController() else showController()
|
||||
@ -108,7 +88,7 @@ internal class CustomExoPlayerView(
|
||||
initializeAdvancedOptions(context)
|
||||
|
||||
player?.playbackParameters = PlaybackParameters(
|
||||
playbackSpeed.toFloat(),
|
||||
PlayerHelper.playbackSpeed.toFloat(),
|
||||
1.0f
|
||||
)
|
||||
|
||||
@ -250,7 +230,7 @@ internal class CustomExoPlayerView(
|
||||
|
||||
private fun enableDoubleTapToSeek() {
|
||||
// set seek increment text
|
||||
val seekIncrementText = (seekIncrement / 1000).toString()
|
||||
val seekIncrementText = (PlayerHelper.seekIncrement / 1000).toString()
|
||||
doubleTapOverlayBinding?.rewindTV?.text = seekIncrementText
|
||||
doubleTapOverlayBinding?.forwardTV?.text = seekIncrementText
|
||||
doubleTapListener =
|
||||
@ -265,7 +245,7 @@ internal class CustomExoPlayerView(
|
||||
}
|
||||
|
||||
private fun rewind() {
|
||||
player?.seekTo((player?.currentPosition ?: 0L) - seekIncrement)
|
||||
player?.seekTo((player?.currentPosition ?: 0L) - PlayerHelper.seekIncrement)
|
||||
|
||||
// show the rewind button
|
||||
doubleTapOverlayBinding?.rewindBTN.apply {
|
||||
@ -289,7 +269,7 @@ internal class CustomExoPlayerView(
|
||||
}
|
||||
|
||||
private fun forward() {
|
||||
player?.seekTo(player!!.currentPosition + seekIncrement)
|
||||
player?.seekTo(player!!.currentPosition + PlayerHelper.seekIncrement)
|
||||
|
||||
// show the forward button
|
||||
doubleTapOverlayBinding?.forwardBTN.apply {
|
||||
|
@ -6,6 +6,7 @@ import android.view.accessibility.CaptioningManager
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
import com.google.android.exoplayer2.ui.CaptionStyleCompat
|
||||
import com.google.android.exoplayer2.video.VideoSize
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
object PlayerHelper {
|
||||
// get the audio source following the users preferences
|
||||
@ -259,6 +260,32 @@ object PlayerHelper {
|
||||
"64"
|
||||
)
|
||||
|
||||
val autoPlayEnabled: Boolean
|
||||
get() = PreferenceHelper.getBoolean(
|
||||
PreferenceKeys.AUTO_PLAY,
|
||||
true
|
||||
)
|
||||
|
||||
val seekIncrement: Long
|
||||
get() = PreferenceHelper.getString(
|
||||
PreferenceKeys.SEEK_INCREMENT,
|
||||
"10.0"
|
||||
).toFloat()
|
||||
.roundToInt()
|
||||
.toLong() * 1000
|
||||
|
||||
val playbackSpeed: String
|
||||
get() = PreferenceHelper.getString(
|
||||
PreferenceKeys.PLAYBACK_SPEED,
|
||||
"1"
|
||||
).replace("F", "")
|
||||
|
||||
val resizeModePref: String
|
||||
get() = PreferenceHelper.getString(
|
||||
PreferenceKeys.PLAYER_RESIZE_MODE,
|
||||
"fit"
|
||||
)
|
||||
|
||||
fun getDefaultResolution(context: Context): String {
|
||||
return if (NetworkHelper.isNetworkMobile(context)) {
|
||||
PreferenceHelper.getString(
|
||||
|
Loading…
x
Reference in New Issue
Block a user