mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-30 23:27:17 +02:00
Merge pull request #20 from svdztn/fix_seekback_with_no_play
Fix seekback with no play & progress bar data loss
This commit is contained in:
@@ -96,11 +96,14 @@ class MyNativeAudio : Plugin() {
|
|||||||
//if (!isPlaying) currentTime -= playerNotificationService.calcPauseSeekBackTime()
|
//if (!isPlaying) currentTime -= playerNotificationService.calcPauseSeekBackTime()
|
||||||
var id = playerNotificationService.getCurrentAudiobookId()
|
var id = playerNotificationService.getCurrentAudiobookId()
|
||||||
Log.d(tag, "Get Current id $id")
|
Log.d(tag, "Get Current id $id")
|
||||||
|
var duration = playerNotificationService.getDuration()
|
||||||
|
Log.d(tag, "Get duration $duration")
|
||||||
val ret = JSObject()
|
val ret = JSObject()
|
||||||
ret.put("lastPauseTime", lastPauseTime)
|
ret.put("lastPauseTime", lastPauseTime)
|
||||||
ret.put("currentTime", currentTime)
|
ret.put("currentTime", currentTime)
|
||||||
ret.put("isPlaying", isPlaying)
|
ret.put("isPlaying", isPlaying)
|
||||||
ret.put("id", id)
|
ret.put("id", id)
|
||||||
|
ret.put("duration", duration)
|
||||||
call.resolve(ret)
|
call.resolve(ret)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -388,11 +388,16 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
currentAudiobook!!.hasPlayerLoaded = true
|
currentAudiobook!!.hasPlayerLoaded = true
|
||||||
sendClientMetadata("ready")
|
if (lastPauseTime == 0L) {
|
||||||
|
sendClientMetadata("ready_no_sync")
|
||||||
|
lastPauseTime = -1;
|
||||||
|
}
|
||||||
|
else sendClientMetadata("ready")
|
||||||
}
|
}
|
||||||
if (mPlayer.playbackState == Player.STATE_BUFFERING) {
|
if (mPlayer.playbackState == Player.STATE_BUFFERING) {
|
||||||
Log.d(tag, "STATE_BUFFERING : " + mPlayer.currentPosition.toString())
|
Log.d(tag, "STATE_BUFFERING : " + mPlayer.currentPosition.toString())
|
||||||
sendClientMetadata("buffering")
|
if (lastPauseTime == 0L) sendClientMetadata("buffering_no_sync")
|
||||||
|
else sendClientMetadata("buffering")
|
||||||
}
|
}
|
||||||
if (mPlayer.playbackState == Player.STATE_ENDED) {
|
if (mPlayer.playbackState == Player.STATE_ENDED) {
|
||||||
Log.d(tag, "STATE_ENDED")
|
Log.d(tag, "STATE_ENDED")
|
||||||
@@ -488,6 +493,10 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
|
|||||||
return lastPauseTime
|
return lastPauseTime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getDuration() : Long {
|
||||||
|
return mPlayer.duration
|
||||||
|
}
|
||||||
|
|
||||||
fun calcPauseSeekBackTime() : Long {
|
fun calcPauseSeekBackTime() : Long {
|
||||||
if (lastPauseTime <= 0) return 0
|
if (lastPauseTime <= 0) return 0
|
||||||
var time: Long = System.currentTimeMillis() - lastPauseTime
|
var time: Long = System.currentTimeMillis() - lastPauseTime
|
||||||
|
|||||||
@@ -74,7 +74,8 @@ export default {
|
|||||||
seekedTime: 0,
|
seekedTime: 0,
|
||||||
seekLoading: false,
|
seekLoading: false,
|
||||||
onPlayingUpdateListener: null,
|
onPlayingUpdateListener: null,
|
||||||
onMetadataListener: null
|
onMetadataListener: null,
|
||||||
|
noSyncUpdateTime: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -100,7 +101,7 @@ export default {
|
|||||||
MyNativeAudio.seekForward({ amount: '10000' })
|
MyNativeAudio.seekForward({ amount: '10000' })
|
||||||
},
|
},
|
||||||
sendStreamUpdate() {
|
sendStreamUpdate() {
|
||||||
this.$emit('updateTime', this.currentTime)
|
this.$emit('updateTime', this.currentTime)
|
||||||
},
|
},
|
||||||
setStreamReady() {
|
setStreamReady() {
|
||||||
this.readyTrackWidth = this.trackWidth
|
this.readyTrackWidth = this.trackWidth
|
||||||
@@ -150,7 +151,8 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.updateTimestamp()
|
this.updateTimestamp()
|
||||||
this.sendStreamUpdate()
|
if (this.noSyncUpdateTime) this.noSyncUpdateTime = false
|
||||||
|
else this.sendStreamUpdate()
|
||||||
|
|
||||||
var perc = this.currentTime / this.totalDuration
|
var perc = this.currentTime / this.totalDuration
|
||||||
var ptWidth = Math.round(perc * this.trackWidth)
|
var ptWidth = Math.round(perc * this.trackWidth)
|
||||||
@@ -226,6 +228,7 @@ export default {
|
|||||||
console.log('Same audiobook')
|
console.log('Same audiobook')
|
||||||
this.isPaused = !data.isPlaying
|
this.isPaused = !data.isPlaying
|
||||||
this.currentTime = Number((data.currentTime / 1000).toFixed(2))
|
this.currentTime = Number((data.currentTime / 1000).toFixed(2))
|
||||||
|
this.totalDuration = Number((data.duration / 1000).toFixed(2))
|
||||||
this.timeupdate()
|
this.timeupdate()
|
||||||
if (data.isPlaying) {
|
if (data.isPlaying) {
|
||||||
console.log('playing - continue')
|
console.log('playing - continue')
|
||||||
@@ -330,7 +333,9 @@ export default {
|
|||||||
this.setFromObj()
|
this.setFromObj()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.timeupdate()
|
if ((this.stateName === 'ready_no_sync') || (this.stateName === 'buffering_no_sync')) this.noSyncUpdateTime = true
|
||||||
|
|
||||||
|
this.timeupdate()
|
||||||
},
|
},
|
||||||
init() {
|
init() {
|
||||||
this.onPlayingUpdateListener = MyNativeAudio.addListener('onPlayingUpdate', this.onPlayingUpdate)
|
this.onPlayingUpdateListener = MyNativeAudio.addListener('onPlayingUpdate', this.onPlayingUpdate)
|
||||||
|
|||||||
Reference in New Issue
Block a user