mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-04 18:15:01 +02:00
Fix:Auto rewind and jump forward/jump backward on multi-tracks #143
This commit is contained in:
parent
be885009ad
commit
8411428241
7 changed files with 173 additions and 27 deletions
|
@ -66,19 +66,26 @@ class PlayerListener(var playerNotificationService:PlayerNotificationService) :
|
|||
Log.d(tag, "EVENT IS PLAYING CHANGED ${playerNotificationService.getMediaPlayer()}")
|
||||
|
||||
if (player.isPlaying) {
|
||||
Log.d(tag, "SeekBackTime: Player is playing")
|
||||
if (lastPauseTime > 0) {
|
||||
if (onSeekBack) onSeekBack = false
|
||||
else {
|
||||
Log.d(tag, "SeekBackTime: playing started now set seek back time $lastPauseTime")
|
||||
var backTime = calcPauseSeekBackTime()
|
||||
if (backTime > 0) {
|
||||
if (backTime >= playerNotificationService.mPlayer.currentPosition) backTime = playerNotificationService.mPlayer.currentPosition - 500
|
||||
if (backTime >= playerNotificationService.getCurrentTime()) backTime = playerNotificationService.getCurrentTime() - 500
|
||||
Log.d(tag, "SeekBackTime $backTime")
|
||||
onSeekBack = true
|
||||
playerNotificationService.seekBackward(backTime)
|
||||
} else {
|
||||
Log.d(tag, "SeekBackTime: back time is 0")
|
||||
}
|
||||
}
|
||||
}
|
||||
} else lastPauseTime = System.currentTimeMillis()
|
||||
} else {
|
||||
Log.d(tag, "SeekBackTime: Player not playing set last pause time")
|
||||
lastPauseTime = System.currentTimeMillis()
|
||||
}
|
||||
|
||||
// Start/stop progress sync interval
|
||||
Log.d(tag, "Playing ${playerNotificationService.getCurrentBookTitle()}")
|
||||
|
@ -96,12 +103,10 @@ class PlayerListener(var playerNotificationService:PlayerNotificationService) :
|
|||
if (lastPauseTime <= 0) return 0
|
||||
var time: Long = System.currentTimeMillis() - lastPauseTime
|
||||
var seekback: Long
|
||||
if (time < 60000) seekback = 0
|
||||
else if (time < 120000) seekback = 10000
|
||||
else if (time < 300000) seekback = 15000
|
||||
else if (time < 1800000) seekback = 20000
|
||||
else if (time < 3600000) seekback = 25000
|
||||
else seekback = 29500
|
||||
if (time < 3000) seekback = 0
|
||||
else if (time < 300000) seekback = 10000 // 3s to 5m = jump back 10s
|
||||
else if (time < 1800000) seekback = 20000 // 5m to 30m = jump back 20s
|
||||
else seekback = 29500 // 30m and up = jump back 30s
|
||||
return seekback
|
||||
}
|
||||
}
|
||||
|
|
|
@ -509,11 +509,13 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
|
|||
}
|
||||
|
||||
fun seekForward(amount: Long) {
|
||||
currentPlayer.seekTo(currentPlayer.currentPosition + amount)
|
||||
seekPlayer(getCurrentTime() + amount)
|
||||
// currentPlayer.seekTo(currentPlayer.currentPosition + amount)
|
||||
}
|
||||
|
||||
fun seekBackward(amount: Long) {
|
||||
currentPlayer.seekTo(currentPlayer.currentPosition - amount)
|
||||
seekPlayer(getCurrentTime() - amount)
|
||||
// currentPlayer.seekTo(currentPlayer.currentPosition - amount)
|
||||
}
|
||||
|
||||
fun setPlaybackSpeed(speed: Float) {
|
||||
|
|
|
@ -330,7 +330,7 @@ class AbsDownloader : Plugin() {
|
|||
}
|
||||
}
|
||||
|
||||
fun checkDownloads(downloadItem: DownloadItem) {
|
||||
private fun checkDownloads(downloadItem: DownloadItem) {
|
||||
val itemParts = downloadItem.downloadItemParts.map { it }
|
||||
for (downloadItemPart in itemParts) {
|
||||
if (downloadItemPart.downloadId != null) {
|
||||
|
|
|
@ -108,6 +108,11 @@ export default {
|
|||
text: 'Local Media',
|
||||
to: '/localMedia/folders'
|
||||
})
|
||||
// items.push({
|
||||
// icon: 'settings',
|
||||
// text: 'Settings',
|
||||
// to: '/settings'
|
||||
// })
|
||||
}
|
||||
return items
|
||||
},
|
||||
|
|
48
components/ui/ToggleSwitch.vue
Normal file
48
components/ui/ToggleSwitch.vue
Normal file
|
@ -0,0 +1,48 @@
|
|||
<template>
|
||||
<div>
|
||||
<div class="border rounded-full border-gray-400 flex items-center cursor-pointer w-10 justify-start" :class="className" @click.stop="clickToggle">
|
||||
<span class="rounded-full border w-5 h-5 border-gray-100 shadow transform transition-transform duration-100" :class="switchClassName"></span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
props: {
|
||||
value: Boolean,
|
||||
onColor: {
|
||||
type: String,
|
||||
default: 'success'
|
||||
},
|
||||
offColor: {
|
||||
type: String,
|
||||
default: 'primary'
|
||||
},
|
||||
disabled: Boolean
|
||||
},
|
||||
computed: {
|
||||
toggleValue: {
|
||||
get() {
|
||||
return this.value
|
||||
},
|
||||
set(val) {
|
||||
this.$emit('input', val)
|
||||
}
|
||||
},
|
||||
className() {
|
||||
if (this.disabled) return this.toggleValue ? `bg-${this.onColor} cursor-not-allowed` : `bg-${this.offColor} cursor-not-allowed`
|
||||
return this.toggleValue ? `bg-${this.onColor}` : `bg-${this.offColor}`
|
||||
},
|
||||
switchClassName() {
|
||||
var bgColor = this.disabled ? 'bg-gray-300' : 'bg-white'
|
||||
return this.toggleValue ? 'translate-x-5 ' + bgColor : bgColor
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
clickToggle() {
|
||||
if (this.disabled) return
|
||||
this.toggleValue = !this.toggleValue
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -1,16 +0,0 @@
|
|||
<template>
|
||||
<div class="w-full h-full">
|
||||
<p class="text-xl text-center py-8">Under Construction...</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {}
|
||||
},
|
||||
computed: {},
|
||||
methods: {},
|
||||
mounted() {}
|
||||
}
|
||||
</script>
|
102
pages/settings.vue
Normal file
102
pages/settings.vue
Normal file
|
@ -0,0 +1,102 @@
|
|||
<template>
|
||||
<div class="w-full h-full p-8">
|
||||
<div class="flex items-center py-3" @click="toggleDisableAutoRewind">
|
||||
<div class="w-10 flex justify-center">
|
||||
<ui-toggle-switch v-model="settings.disableAutoRewind" @input="saveSettings" />
|
||||
</div>
|
||||
<p class="pl-4">Disable Auto Rewind</p>
|
||||
</div>
|
||||
<div class="flex items-center py-3" @click="toggleJumpBackwards">
|
||||
<div class="w-10 flex justify-center">
|
||||
<span class="material-icons text-4xl">{{ currentJumpBackwardsTimeIcon }}</span>
|
||||
</div>
|
||||
<p class="pl-4">Jump backwards time</p>
|
||||
</div>
|
||||
<div class="flex items-center py-3" @click="toggleJumpForwards">
|
||||
<div class="w-10 flex justify-center">
|
||||
<span class="material-icons text-4xl">{{ currentJumpForwardsTimeIcon }}</span>
|
||||
</div>
|
||||
<p class="pl-4">Jump forwards time</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
settings: {
|
||||
disableAutoRewind: false,
|
||||
jumpForwardsTime: 10000,
|
||||
jumpBackwardsTime: 10000
|
||||
},
|
||||
jumpForwardsItems: [
|
||||
{
|
||||
icon: 'forward_5',
|
||||
value: 5000
|
||||
},
|
||||
{
|
||||
icon: 'forward_10',
|
||||
value: 10000
|
||||
},
|
||||
{
|
||||
icon: 'forward_30',
|
||||
value: 30000
|
||||
}
|
||||
],
|
||||
jumpBackwardsItems: [
|
||||
{
|
||||
icon: 'replay_5',
|
||||
value: 5000
|
||||
},
|
||||
{
|
||||
icon: 'replay_10',
|
||||
value: 10000
|
||||
},
|
||||
{
|
||||
icon: 'replay_30',
|
||||
value: 30000
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
currentJumpForwardsTimeIcon() {
|
||||
return this.jumpForwardsItems[this.currentJumpForwardsTimeIndex].icon
|
||||
},
|
||||
currentJumpForwardsTimeIndex() {
|
||||
return this.jumpForwardsItems.findIndex((jfi) => jfi.value === this.settings.jumpForwardsTime)
|
||||
},
|
||||
currentJumpBackwardsTimeIcon() {
|
||||
return this.jumpBackwardsItems[this.currentJumpBackwardsTimeIndex].icon
|
||||
},
|
||||
currentJumpBackwardsTimeIndex() {
|
||||
return this.jumpBackwardsItems.findIndex((jfi) => jfi.value === this.settings.jumpBackwardsTime)
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
toggleDisableAutoRewind() {
|
||||
this.settings.disableAutoRewind = !this.settings.disableAutoRewind
|
||||
this.saveSettings()
|
||||
},
|
||||
toggleJumpForwards() {
|
||||
var next = (this.currentJumpForwardsTimeIndex + 1) % 3
|
||||
this.settings.jumpForwardsTime = this.jumpForwardsItems[next].value
|
||||
this.saveSettings()
|
||||
},
|
||||
toggleJumpBackwards() {
|
||||
var next = (this.currentJumpBackwardsTimeIndex + 4) % 3
|
||||
console.log('next', next)
|
||||
if (next > 2) return
|
||||
this.settings.jumpBackwardsTime = this.jumpBackwardsItems[next].value
|
||||
this.saveSettings()
|
||||
},
|
||||
saveSettings() {
|
||||
// TODO: Save settings
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
// TODO: Load settings
|
||||
}
|
||||
}
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue