Merge pull request #578 from Bnyro/master

autopause option
This commit is contained in:
Bnyro 2022-06-20 14:22:57 +02:00 committed by GitHub
commit 97c083ad7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 5 deletions

View File

@ -10,6 +10,7 @@ import android.net.Uri
import android.os.Build
import android.os.Build.VERSION.SDK_INT
import android.os.Bundle
import android.os.PowerManager
import android.support.v4.media.session.MediaSessionCompat
import android.text.Html
import android.text.TextUtils
@ -323,6 +324,23 @@ class PlayerFragment : Fragment() {
if (!commentsLoaded!!) fetchComments()
}
override fun onPause() {
// pause the player if the screen is turned off
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
val pausePlayerOnScreenOffEnabled = sharedPreferences
.getBoolean("pause_screen_off", false)
// check whether the screen is on
val pm = context?.getSystemService(Context.POWER_SERVICE) as PowerManager
val isScreenOn = pm.isInteractive
// pause player if screen off and setting enabled
if (exoPlayer != null && !isScreenOn && pausePlayerOnScreenOffEnabled) {
exoPlayer.pause()
}
super.onPause()
}
override fun onDestroy() {
super.onDestroy()
try {

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="300"
android:viewportHeight="300"
android:tint="?android:attr/colorControlNormal">
<path
android:fillColor="#FF000000"
android:pathData="M150,0c-82.84,0 -150,67.16 -150,150c0,82.84 67.16,150 150,150c82.84,0 150,-67.17 150,-150C300,67.16 232.85,0 150,0zM134.41,194.54c0,9.5 -7.7,17.2 -17.2,17.2s-17.2,-7.7 -17.2,-17.2V105.46c0,-9.5 7.7,-17.2 17.2,-17.2s17.2,7.7 17.2,17.2V194.54zM198.96,194.54c0,9.5 -7.7,17.2 -17.2,17.2c-9.5,0 -17.2,-7.7 -17.2,-17.2V105.46c0,-9.5 7.7,-17.2 17.2,-17.2s17.2,7.7 17.2,17.2V194.54z" />
</vector>

View File

@ -1,10 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="459"
android:viewportHeight="459"
android:viewportWidth="485.74"
android:viewportHeight="485.74"
android:tint="?android:attr/colorControlNormal">
<path
android:fillColor="#FF000000"
android:pathData="M229.5,0C102.75,0 0,102.75 0,229.5S102.75,459 229.5,459S459,356.25 459,229.5S356.25,0 229.5,0zM310.29,239.65l-111.76,76.08c-3.76,2.56 -8.63,2.83 -12.65,0.7c-4.02,-2.13 -6.54,-6.3 -6.54,-10.85V153.42c0,-4.55 2.52,-8.73 6.54,-10.85c4.02,-2.13 8.89,-1.86 12.65,0.7l111.76,76.08c3.36,2.29 5.37,6.09 5.37,10.15C315.66,233.56 313.65,237.36 310.29,239.65z" />
android:pathData="M242.87,0C108.73,0 0,108.74 0,242.86c0,134.14 108.73,242.88 242.87,242.88c134.14,0 242.86,-108.74 242.86,-242.88C485.74,108.74 377.01,0 242.87,0zM338.41,263.94l-134.36,92.73c-16.78,11.59 -30.58,4.25 -30.58,-16.32V145.38c0,-20.56 13.81,-27.9 30.58,-16.31l134.32,92.73C355.14,233.38 355.18,252.35 338.41,263.94z" />
</vector>

View File

@ -197,4 +197,7 @@
<string name="player_summary">Quality and player behavior</string>
<string name="seek_increment">Seek increment</string>
<string name="piped_summary">Piped is an open-source alternative web-frontend for YouTube provides the API we use. Without Piped, LibreTube wouldn\'t exist. Huge thanks to their devs!</string>
<string name="pauseOnScreenOff">Autopause</string>
<string name="pauseOnScreenOff_summary">Pause the player when the screen is turned off.</string>
<string name="autoplay_summary">Automatically play the next video when the current is finished.</string>
</resources>

View File

@ -57,8 +57,13 @@
android:icon="@drawable/ic_play_filled"
app:key="autoplay"
app:title="@string/player_autoplay"
android:summaryOff="@string/disabled"
android:summaryOn="@string/enabled" />
android:summary="@string/autoplay_summary" />
<SwitchPreferenceCompat
android:icon="@drawable/ic_pause_filled"
app:key="pause_screen_off"
app:title="@string/pauseOnScreenOff"
android:summary="@string/pauseOnScreenOff_summary" />
</PreferenceCategory>