From fa79b2d73d372e7941ad61f669786eb80b44b663 Mon Sep 17 00:00:00 2001 From: odylomv Date: Sat, 20 Feb 2021 00:30:07 +0200 Subject: [PATCH 1/2] feat: add global playback speed setting --- .../fragment/VideoMenuSpeedFragment.java | 31 +++++++++++++++++-- .../peertube/service/VideoPlayerService.java | 9 ++++-- app/src/main/res/values/constants.xml | 19 ++++++++++++ app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/root_preferences.xml | 9 ++++++ 5 files changed, 66 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoMenuSpeedFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoMenuSpeedFragment.java index c43f084..1fc333f 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoMenuSpeedFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoMenuSpeedFragment.java @@ -16,7 +16,9 @@ */ package net.schueller.peertube.fragment; +import android.content.SharedPreferences; import android.os.Bundle; +import android.preference.PreferenceManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -72,8 +74,7 @@ public class VideoMenuSpeedFragment extends BottomSheetDialogFragment { TextView speed15 = view.findViewById(R.id.video_speed15); TextView speed20 = view.findViewById(R.id.video_speed20); - // Default - setVideoSpeed(1.0f, speed10Icon); + setDefaultVideoSpeed(); // Attach the listener speed05.setOnClickListener(v -> setVideoSpeed(0.5f, speed05Icon)); @@ -103,4 +104,30 @@ public class VideoMenuSpeedFragment extends BottomSheetDialogFragment { new Iconics.Builder().on(icon).build(); } + private void setDefaultVideoSpeed() { + SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext()); + String speed = sharedPref.getString(getString(R.string.pref_video_speed_key), "1.0"); + + switch (speed) { + case "0.5": + setVideoSpeed(0.5f, speed05Icon); + break; + case "0.75": + setVideoSpeed(0.75f, speed075Icon); + break; + case "1.0": + setVideoSpeed(1.0f, speed10Icon); + break; + case "1.25": + setVideoSpeed(1.25f, speed125Icon); + break; + case "1.5": + setVideoSpeed(1.5f, speed15Icon); + break; + case "2.0": + setVideoSpeed(2.0f, speed20Icon); + break; + } + } + } \ No newline at end of file diff --git a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java index 9c5fde3..a118a5f 100644 --- a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java +++ b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java @@ -24,6 +24,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.media.AudioManager; @@ -32,6 +33,7 @@ import android.os.Binder; import android.os.Build; import android.os.Bundle; import android.os.IBinder; +import android.preference.PreferenceManager; import android.webkit.URLUtil; import androidx.annotation.Nullable; @@ -255,8 +257,11 @@ public class VideoPlayerService extends Service { // Auto play player.setPlayWhenReady(true); - //reset playback speed - this.setPlayBackSpeed(1.0f); + //set playback speed to global default + SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); + float speed = Float.parseFloat(sharedPref.getString(getString(R.string.pref_video_speed_key), "1.0")); + + this.setPlayBackSpeed(speed); playerNotificationManager = PlayerNotificationManager.createWithNotificationChannel( context, PLAYBACK_CHANNEL_ID, R.string.playback_channel_name, diff --git a/app/src/main/res/values/constants.xml b/app/src/main/res/values/constants.xml index 72c48d6..36afab1 100644 --- a/app/src/main/res/values/constants.xml +++ b/app/src/main/res/values/constants.xml @@ -11,6 +11,7 @@ pref_show_nsfw pref_language + pref_video_speed pref_back_pause pref_background_behavior pref_torrent_player @@ -582,4 +583,22 @@ High + + 0.5x + 0.75x + Normal + 1.25x + 1.5x + 2x + + + + 0.5 + 0.75 + 1.0 + 1.25 + 1.5 + 2.0 + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 43befd3..45de62e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -54,6 +54,8 @@ PeerTube Server Background Playback If enabled, continues to play video in background. + Default Playback Speed + Select the global Video Playback Speed Pause on back button Pause background play when pressing back during video playback. Application Language diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index 2c76891..f8d2179 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -51,6 +51,15 @@ + + Date: Sat, 20 Feb 2021 12:41:20 +0100 Subject: [PATCH 2/2] fix: Crashing of devices sdk 21,22,23,24 on start, fixes #262 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9eff0e3..1ede120 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -140,8 +140,8 @@ dependencies { implementation "com.google.android.exoplayer:extension-mediasession:$exoplayer" implementation "com.google.android.exoplayer:extension-okhttp:$exoplayer" - // date formatter - implementation 'org.ocpsoft.prettytime:prettytime:5.0.0.Final' + // date formatter, do not update past 4.0.4 https://github.com/sschueller/peertube-android/issues/262 + implementation 'org.ocpsoft.prettytime:prettytime:4.0.4.Final' // Version comparison implementation 'org.apache.maven:maven-artifact:3.6.3'