Skip to content
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 @@ -326,7 +326,11 @@ internal class ArmadilloPlayerChoreographer : ArmadilloPlayer {

override fun skipBackward() = doIfPlaybackReady { controls, _ -> controls.skipToPrevious() }

override fun seekTo(position: Milliseconds) = doIfPlaybackReady { controls, _ -> controls.seekTo(position.longValue) }
override fun seekTo(position: Milliseconds) = doIfPlaybackReady { controls, _ ->
// Add a shift constant to all seeks originating from the client application
// as opposed to system originated, such as from notification
controls.seekTo(position.longValue + Constants.AUDIO_POSITION_SHIFT_IN_MS)
}

override fun seekWithinChapter(percent: Int) {
val position = stateProvider.currentState.positionFromChapterPercent(percent)
Expand Down
3 changes: 3 additions & 0 deletions Armadillo/src/main/java/com/scribd/armadillo/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ object Constants {

internal const val MAX_PARALLEL_DOWNLOADS = 6

// an arbitrarily long constant to add to seek positions from app UI
internal const val AUDIO_POSITION_SHIFT_IN_MS = 5000000000L

/**
* A seek to previousChapter command beyond this will restart the current media source instead of skipping to the previousChapter media source
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import android.view.KeyEvent
import androidx.annotation.VisibleForTesting
import com.scribd.armadillo.ArmadilloConfiguration
import com.scribd.armadillo.Constants
import com.scribd.armadillo.Constants.AUDIO_POSITION_SHIFT_IN_MS
import com.scribd.armadillo.Milliseconds
import com.scribd.armadillo.StateStore
import com.scribd.armadillo.actions.CustomMediaSessionAction
Expand Down Expand Up @@ -184,8 +185,20 @@ internal class MediaSessionCallback(private val onMediaSessionEventListener: OnM
}

override fun onSeekTo(posInMilis: Long) {
playbackEngine?.seekTo(posInMilis.milliseconds)
Log.v(TAG, "onSeekTo: $posInMilis")
// if the shift has been added, then it must have originated from app UI, because we added it
val absolutePosition = if (posInMilis >= AUDIO_POSITION_SHIFT_IN_MS) {
posInMilis - AUDIO_POSITION_SHIFT_IN_MS // undo
} else {
// possibly from notification which sends position relative to chapter start
// so, add chapter start time to make it absolute position
val chapterStartTime = playbackInfo?.progress?.currentChapterIndex?.let { chapterIndex ->
playbackInfo?.audioPlayable?.chapters?.getOrNull(chapterIndex)?.startTime?.longValue
} ?: 0
posInMilis + chapterStartTime
}

playbackEngine?.seekTo(absolutePosition.milliseconds)
Log.v(TAG, "onSeekTo: received $posInMilis, absolute $absolutePosition")
}

override fun onCustomAction(action: String?, extras: Bundle?) {
Expand Down