mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-21 10:08:21 +02:00
This commit is contained in:
parent
9da21b57c7
commit
42fec4831e
3 changed files with 20 additions and 7 deletions
|
@ -24,6 +24,7 @@ class AudiobookProgressSyncer constructor(playerNotificationService:PlayerNotifi
|
||||||
var listeningTimerRunning:Boolean = false
|
var listeningTimerRunning:Boolean = false
|
||||||
|
|
||||||
private var webviewOpenOnStart:Boolean = false
|
private var webviewOpenOnStart:Boolean = false
|
||||||
|
private var webviewClosedMidSession:Boolean = false
|
||||||
private var listeningBookTitle:String? = ""
|
private var listeningBookTitle:String? = ""
|
||||||
private var listeningBookIsLocal:Boolean = false
|
private var listeningBookIsLocal:Boolean = false
|
||||||
private var listeningBookId:String? = ""
|
private var listeningBookId:String? = ""
|
||||||
|
@ -54,9 +55,16 @@ class AudiobookProgressSyncer constructor(playerNotificationService:PlayerNotifi
|
||||||
listeningTimerTask = Timer("ListeningTimer", false).schedule(0L, 5000L) {
|
listeningTimerTask = Timer("ListeningTimer", false).schedule(0L, 5000L) {
|
||||||
Handler(Looper.getMainLooper()).post() {
|
Handler(Looper.getMainLooper()).post() {
|
||||||
// Webview was closed while android auto is open - switch to native sync
|
// Webview was closed while android auto is open - switch to native sync
|
||||||
if (!playerNotificationService.getIsWebviewOpen() && webviewOpenOnStart) {
|
var isWebviewOpen = playerNotificationService.getIsWebviewOpen()
|
||||||
|
if (!isWebviewOpen && webviewOpenOnStart) {
|
||||||
Log.d(tag, "Listening Timer: webview closed Switching to native sync tracking")
|
Log.d(tag, "Listening Timer: webview closed Switching to native sync tracking")
|
||||||
webviewOpenOnStart = false
|
webviewOpenOnStart = false
|
||||||
|
webviewClosedMidSession = true
|
||||||
|
lastUpdateTime = System.currentTimeMillis() / 1000L
|
||||||
|
} else if (isWebviewOpen && webviewClosedMidSession) {
|
||||||
|
Log.d(tag, "Listening Timer: webview re-opened Switching back to webview sync tracking")
|
||||||
|
webviewClosedMidSession = false
|
||||||
|
webviewOpenOnStart = true
|
||||||
lastUpdateTime = System.currentTimeMillis() / 1000L
|
lastUpdateTime = System.currentTimeMillis() / 1000L
|
||||||
}
|
}
|
||||||
if (!webviewOpenOnStart && playerNotificationService.currentPlayer.isPlaying) {
|
if (!webviewOpenOnStart && playerNotificationService.currentPlayer.isPlaying) {
|
||||||
|
@ -97,7 +105,7 @@ class AudiobookProgressSyncer constructor(playerNotificationService:PlayerNotifi
|
||||||
// Send sync data only for streaming books
|
// Send sync data only for streaming books
|
||||||
var syncData: JSObject = JSObject()
|
var syncData: JSObject = JSObject()
|
||||||
syncData.put("timeListened", elapsed)
|
syncData.put("timeListened", elapsed)
|
||||||
syncData.put("currentTime", playerNotificationService.getCurrentTime())
|
syncData.put("currentTime", playerNotificationService.getCurrentTime() / 1000)
|
||||||
syncData.put("streamId", listeningStreamId)
|
syncData.put("streamId", listeningStreamId)
|
||||||
syncData.put("audiobookId", listeningBookId)
|
syncData.put("audiobookId", listeningBookId)
|
||||||
sendStreamSyncData(syncData) {
|
sendStreamSyncData(syncData) {
|
||||||
|
|
|
@ -185,15 +185,20 @@ export default {
|
||||||
return this.book.authorFL
|
return this.book.authorFL
|
||||||
},
|
},
|
||||||
chapters() {
|
chapters() {
|
||||||
return this.audiobook ? this.audiobook.chapters || [] : []
|
return (this.audiobook ? this.audiobook.chapters || [] : []).map((chapter) => {
|
||||||
|
var chap = { ...chapter }
|
||||||
|
chap.start = Number(chap.start)
|
||||||
|
chap.end = Number(chap.end)
|
||||||
|
return chap
|
||||||
|
})
|
||||||
},
|
},
|
||||||
currentChapter() {
|
currentChapter() {
|
||||||
if (!this.audiobook || !this.chapters.length) return null
|
if (!this.audiobook || !this.chapters.length) return null
|
||||||
return this.chapters.find((ch) => Number(ch.start.toFixed(2)) <= this.currentTime && Number(ch.end.toFixed(2)) > this.currentTime)
|
return this.chapters.find((ch) => Number(Number(ch.start).toFixed(2)) <= this.currentTime && Number(Number(ch.end).toFixed(2)) > this.currentTime)
|
||||||
},
|
},
|
||||||
nextChapter() {
|
nextChapter() {
|
||||||
if (!this.chapters.length) return
|
if (!this.chapters.length) return
|
||||||
return this.chapters.find((c) => Number(c.start.toFixed(2)) > this.currentTime)
|
return this.chapters.find((c) => Number(Number(c.start).toFixed(2)) > this.currentTime)
|
||||||
},
|
},
|
||||||
currentChapterTitle() {
|
currentChapterTitle() {
|
||||||
return this.currentChapter ? this.currentChapter.title : ''
|
return this.currentChapter ? this.currentChapter.title : ''
|
||||||
|
@ -336,7 +341,7 @@ export default {
|
||||||
|
|
||||||
// If 1 second or less into current chapter, then go to previous
|
// If 1 second or less into current chapter, then go to previous
|
||||||
if (this.currentTime - this.currentChapter.start <= 1) {
|
if (this.currentTime - this.currentChapter.start <= 1) {
|
||||||
var currChapterIndex = this.chapters.findIndex((ch) => ch.start <= this.currentTime && ch.end >= this.currentTime)
|
var currChapterIndex = this.chapters.findIndex((ch) => Number(ch.start) <= this.currentTime && Number(ch.end) >= this.currentTime)
|
||||||
if (currChapterIndex > 0) {
|
if (currChapterIndex > 0) {
|
||||||
var prevChapter = this.chapters[currChapterIndex - 1]
|
var prevChapter = this.chapters[currChapterIndex - 1]
|
||||||
this.seek(prevChapter.start)
|
this.seek(prevChapter.start)
|
||||||
|
|
|
@ -78,7 +78,7 @@ export default {
|
||||||
},
|
},
|
||||||
currentChapter() {
|
currentChapter() {
|
||||||
if (!this.audiobook || !this.chapters.length) return null
|
if (!this.audiobook || !this.chapters.length) return null
|
||||||
return this.chapters.find((ch) => ch.start <= this.currentTime && ch.end > this.currentTime)
|
return this.chapters.find((ch) => Number(ch.start) <= this.currentTime && Number(ch.end) > this.currentTime)
|
||||||
},
|
},
|
||||||
socketConnected() {
|
socketConnected() {
|
||||||
return this.$store.state.socketConnected
|
return this.$store.state.socketConnected
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue