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 PlaybackManagerOptions for defaultRewindAmount and defaultFastForwardAmount #2473

Merged
merged 2 commits into from
Feb 4, 2023
Merged
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 @@ -14,8 +14,8 @@ class UserSettingPreferences(
app = "emby",
) {
companion object {
val skipBackLength = intPreference("skipBackLength", 10000)
val skipForwardLength = intPreference("skipForwardLength", 30000)
val skipBackLength = intPreference("skipBackLength", 10_000)
val skipForwardLength = intPreference("skipForwardLength", 30_000)

val homesection0 = enumPreference("homesection0", HomeSectionType.LIBRARY_TILES_SMALL)
val homesection1 = enumPreference("homesection1", HomeSectionType.RESUME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ public ItemRowAdapter getManagedAudioQueue() {
return mManagedAudioQueue;
}

@Override
public void createManagedAudioQueue() {
private void createManagedAudioQueue() {
if (mCurrentAudioQueue != null) {
if (mManagedAudioQueue != null) {
//re-create existing one
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ interface MediaManager {
val isShuffleMode: Boolean
val currentAudioQueue: ItemRowAdapter?
val managedAudioQueue: ItemRowAdapter?
fun createManagedAudioQueue()
fun addAudioEventListener(listener: AudioEventListener)
fun removeAudioEventListener(listener: AudioEventListener)
fun saveAudioQueue(context: Context?)
Expand All @@ -28,9 +27,9 @@ interface MediaManager {
fun addToAudioQueue(items: List<BaseItemDto>)
fun removeFromAudioQueue(ndx: Int)
val isPlayingAudio: Boolean
fun playNow(context: Context?, items: List<BaseItemDto>, position: Int, shuffle: Boolean)
fun playNow(context: Context?, items: List<BaseItemDto>, shuffle: Boolean)
fun playNow(context: Context?, item: BaseItemDto)
fun playNow(context: Context, items: List<BaseItemDto>, position: Int, shuffle: Boolean)
fun playNow(context: Context, items: List<BaseItemDto>, shuffle: Boolean)
fun playNow(context: Context, item: BaseItemDto)
fun playFrom(ndx: Int): Boolean
fun shuffleAudioQueue()
val nextAudioItem: BaseItemDto?
Expand Down
5 changes: 3 additions & 2 deletions playback/core/src/main/kotlin/PlaybackManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import kotlin.reflect.KClass
class PlaybackManager internal constructor(
val backend: PlayerBackend,
private val services: MutableList<PlayerService>,
private val mediaStreamResolvers: List<MediaStreamResolver>,
mediaStreamResolvers: List<MediaStreamResolver>,

Check warning

Code scanning / detekt

Private member is unused and should be removed.

Private property `mediaStreamResolvers` is unused.
val options: PlaybackManagerOptions,
parentJob: Job? = null,
) {
val repository = PlaybackRepository()

private val job = SupervisorJob(parentJob)
val state = MutablePlayerstate()
val state = MutablePlayerstate(options)

init {
state.setBackend(backend)
Expand Down
3 changes: 2 additions & 1 deletion playback/core/src/main/kotlin/PlaybackManagerBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.jellyfin.playback.core.plugin.PlayerService

class PlaybackManagerBuilder {
private val factories = mutableListOf<PlaybackPlugin>()
val options = PlaybackManagerOptions()

fun install(pluginFactory: PlaybackPlugin) {
factories.add(pluginFactory)
Expand Down Expand Up @@ -35,7 +36,7 @@ class PlaybackManagerBuilder {

// Only support a single backend right now
require(backends.size == 1)
return PlaybackManager(backends.first(), services, mediaStreamResolvers)
return PlaybackManager(backends.first(), services, mediaStreamResolvers, options)
}
}

Expand Down
9 changes: 9 additions & 0 deletions playback/core/src/main/kotlin/PlaybackManagerOptions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.jellyfin.playback.core

import kotlinx.coroutines.flow.MutableStateFlow
import kotlin.time.Duration.Companion.seconds

class PlaybackManagerOptions {
var defaultRewindAmount = MutableStateFlow(10.seconds)
var defaultFastForwardAmount = MutableStateFlow(10.seconds)
}
11 changes: 5 additions & 6 deletions playback/core/src/main/kotlin/PlayerState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.jellyfin.playback.core.queue.EmptyQueue
import org.jellyfin.playback.core.queue.Queue
import org.jellyfin.playback.core.queue.item.QueueEntry
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds

interface PlayerState {
val queue: StateFlow<Queue>
Expand Down Expand Up @@ -45,7 +44,9 @@ interface PlayerState {
fun setSpeed(speed: Float)
}

class MutablePlayerstate : PlayerState {
class MutablePlayerstate(
private val options: PlaybackManagerOptions,
) : PlayerState {
private val _queue = MutableStateFlow<Queue>(EmptyQueue)
override val queue: StateFlow<Queue> get() = _queue.asStateFlow()

Expand Down Expand Up @@ -118,13 +119,11 @@ class MutablePlayerstate : PlayerState {
}

override fun fastForward(amount: Duration?) {
// TODO use user preference instead of hardcoded "10.seconds"
seekRelative(amount ?: 10.seconds)
seekRelative(amount ?: options.defaultFastForwardAmount.value)
}

override fun rewind(amount: Duration?) {
// TODO use user preference instead of hardcoded "10.seconds"
seekRelative(-(amount ?: 10.seconds))
seekRelative(-(amount ?: options.defaultRewindAmount.value))
}

override fun setSpeed(speed: Float) {
Expand Down