fix progress bar data loss after restore from app destroy when playing is on

This commit is contained in:
svd 2021-10-27 15:12:36 +08:00
parent fde6a4e8ec
commit 55f032d887
3 changed files with 8 additions and 0 deletions

View file

@ -96,11 +96,14 @@ class MyNativeAudio : Plugin() {
//if (!isPlaying) currentTime -= playerNotificationService.calcPauseSeekBackTime()
var id = playerNotificationService.getCurrentAudiobookId()
Log.d(tag, "Get Current id $id")
var duration = playerNotificationService.getDuration()
Log.d(tag, "Get duration $duration")
val ret = JSObject()
ret.put("lastPauseTime", lastPauseTime)
ret.put("currentTime", currentTime)
ret.put("isPlaying", isPlaying)
ret.put("id", id)
ret.put("duration", duration)
call.resolve(ret)
}
}

View file

@ -493,6 +493,10 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
return lastPauseTime
}
fun getDuration() : Long {
return mPlayer.duration
}
fun calcPauseSeekBackTime() : Long {
if (lastPauseTime <= 0) return 0
var time: Long = System.currentTimeMillis() - lastPauseTime

View file

@ -228,6 +228,7 @@ export default {
console.log('Same audiobook')
this.isPaused = !data.isPlaying
this.currentTime = Number((data.currentTime / 1000).toFixed(2))
this.totalDuration = Number((data.duration / 1000).toFixed(2))
this.timeupdate()
if (data.isPlaying) {
console.log('playing - continue')