Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to customize seek time #3794

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ class UserPreferences(context: Context) : SharedPreferenceStore(
*/
var nextUpTimeout = intPreference("next_up_timeout", 1000 * 7)

/**
* Duration how far to rewind/forward item
* Stored in milliseconds
*/
var seekTime = intPreference("seek_time", 1000 * 15)

/**
* Duration in seconds to subtract from resume time
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ import kotlin.math.min

class CustomSeekProvider(
private val videoPlayerAdapter: VideoPlayerAdapter,
private val seekTime: Int,
) : PlaybackSeekDataProvider() {
companion object {
private const val SEEK_LENGTH = 30000L
}

override fun getSeekPositions(): LongArray {
if (!videoPlayerAdapter.canSeek()) return LongArray(0)

val duration = videoPlayerAdapter.duration
val size = ceil(duration.toDouble() / SEEK_LENGTH.toDouble()).toInt() + 1
return LongArray(size) { i -> min(i * SEEK_LENGTH, duration) }

val size = ceil(duration.toDouble() / seekTime.toDouble()).toInt() + 1
return LongArray(size) { i -> min(i * seekTime.toLong(), duration) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

import androidx.leanback.app.PlaybackSupportFragment;

import org.jellyfin.androidtv.preference.UserPreferences;
import org.jellyfin.androidtv.ui.playback.CustomPlaybackOverlayFragment;
import org.jellyfin.androidtv.ui.playback.PlaybackController;
import org.jellyfin.androidtv.ui.playback.PlaybackControllerContainer;
import org.koin.java.KoinJavaComponent;

import kotlin.Lazy;
import timber.log.Timber;
Expand All @@ -18,6 +20,7 @@ public class LeanbackOverlayFragment extends PlaybackSupportFragment {
private VideoPlayerAdapter playerAdapter;
private boolean shouldShowOverlay = true;
private Lazy<PlaybackControllerContainer> playbackControllerContainer = inject(PlaybackControllerContainer.class);
private final Integer seekTime = KoinJavaComponent.<UserPreferences>get(UserPreferences.class).get(UserPreferences.Companion.getSeekTime());

@Override
public void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -76,7 +79,7 @@ public void mediaInfoChanged() {

playerGlue.invalidatePlaybackControls();
playerGlue.setSeekEnabled(playerAdapter.canSeek());
playerGlue.setSeekProvider(playerAdapter.canSeek() ? new CustomSeekProvider(playerAdapter) : null);
playerGlue.setSeekProvider(playerAdapter.canSeek() ? new CustomSeekProvider(playerAdapter, seekTime) : null);
recordingStateChanged();
playerAdapter.updateDuration();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ class PlaybackPreferencesScreen : OptionsFragment() {
setContent(R.string.sum_enable_cinema_mode)
bind(userPreferences, UserPreferences.cinemaModeEnabled)
}

@Suppress("MagicNumber")
seekbar {
setTitle(R.string.pref_seek_time_title)
setContent(R.string.pref_seek_time_summary)
min = 1_000
max = 60_000
increment = 1_000
valueFormatter = object : DurationSeekBarPreference.ValueFormatter() {
override fun display(value: Int) = "${value / 1000}s"
}
bind(userPreferences, UserPreferences.seekTime)
}
}

category {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@
<string name="pref_about_title">About</string>
<string name="pref_external_player">Use external player</string>
<string name="pref_next_up_timeout_summary">How long to wait before playing the next item</string>
<string name="pref_seek_time_summary">How far to rewind/forward</string>
<string name="pref_seek_time_title">Seek time</string>
<string name="pref_next_up_timeout_title">Next up timer duration</string>
<string name="pref_next_up_timeout_disabled">∞</string>
<string name="watch_now">Watch now</string>
Expand Down