diff --git a/android/app/src/main/java/com/audiobookshelf/app/player/MediaProgressSyncer.kt b/android/app/src/main/java/com/audiobookshelf/app/player/MediaProgressSyncer.kt index 25a35876..25bea081 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/player/MediaProgressSyncer.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/player/MediaProgressSyncer.kt @@ -109,11 +109,23 @@ class MediaProgressSyncer(val playerNotificationService:PlayerNotificationServic // Local library item is linked to a server library item // Send sync to server also if connected to this server and local item belongs to this server if (!it.libraryItemId.isNullOrEmpty() && it.serverConnectionConfigId != null && DeviceManager.serverConnectionConfig?.id == it.serverConnectionConfigId) { - apiHandler.sendLocalProgressSync(it) { + apiHandler.sendLocalProgressSync(it) { syncSuccess -> Log.d( tag, "Local progress sync data sent to server $currentDisplayTitle for time $currentTime" ) + if (syncSuccess) { + failedSyncs = 0 + playerNotificationService.alertSyncSuccess() + } else { + failedSyncs++ + if (failedSyncs == 2) { + playerNotificationService.alertSyncFailing() // Show alert in client + failedSyncs = 0 + } + Log.e(tag, "Local Progress sync failed ($failedSyncs) to send to server $currentDisplayTitle for time $currentTime") + } + cb() } } else { @@ -125,13 +137,14 @@ class MediaProgressSyncer(val playerNotificationService:PlayerNotificationServic if (it) { Log.d(tag, "Progress sync data sent to server $currentDisplayTitle for time $currentTime") failedSyncs = 0 + playerNotificationService.alertSyncSuccess() } else { failedSyncs++ if (failedSyncs == 2) { playerNotificationService.alertSyncFailing() // Show alert in client failedSyncs = 0 } - Log.d(tag, "Progress sync failed ($failedSyncs) to send to server $currentDisplayTitle for time $currentTime") + Log.e(tag, "Progress sync failed ($failedSyncs) to send to server $currentDisplayTitle for time $currentTime") } cb() } diff --git a/android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationService.kt b/android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationService.kt index 060e4f56..8b0c09cf 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationService.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationService.kt @@ -58,6 +58,7 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { fun onPlaybackFailed(errorMessage:String) fun onMediaPlayerChanged(mediaPlayer:String) fun onProgressSyncFailing() + fun onProgressSyncSuccess() } private val tag = "PlayerService" @@ -722,6 +723,10 @@ class PlayerNotificationService : MediaBrowserServiceCompat() { clientEventEmitter?.onProgressSyncFailing() } + fun alertSyncSuccess() { + clientEventEmitter?.onProgressSyncSuccess() + } + // // MEDIA BROWSER STUFF (ANDROID AUTO) // diff --git a/android/app/src/main/java/com/audiobookshelf/app/plugins/AbsAudioPlayer.kt b/android/app/src/main/java/com/audiobookshelf/app/plugins/AbsAudioPlayer.kt index 2e2bdb35..b0d82226 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/plugins/AbsAudioPlayer.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/plugins/AbsAudioPlayer.kt @@ -80,6 +80,10 @@ class AbsAudioPlayer : Plugin() { override fun onProgressSyncFailing() { emit("onProgressSyncFailing", "") } + + override fun onProgressSyncSuccess() { + emit("onProgressSyncSuccess", "") + } }) } mainActivity.pluginCallback = foregroundServiceReady diff --git a/android/app/src/main/java/com/audiobookshelf/app/server/ApiHandler.kt b/android/app/src/main/java/com/audiobookshelf/app/server/ApiHandler.kt index 80846d85..aebcede3 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/server/ApiHandler.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/server/ApiHandler.kt @@ -230,11 +230,15 @@ class ApiHandler(var ctx:Context) { } } - fun sendLocalProgressSync(playbackSession:PlaybackSession, cb: () -> Unit) { + fun sendLocalProgressSync(playbackSession:PlaybackSession, cb: (Boolean) -> Unit) { val payload = JSObject(jacksonMapper.writeValueAsString(playbackSession)) postRequest("/api/session/local", payload) { - cb() + if (!it.getString("error").isNullOrEmpty()) { + cb(false) + } else { + cb(true) + } } } diff --git a/components/app/AudioPlayer.vue b/components/app/AudioPlayer.vue index 14b8ee92..61a94a19 100644 --- a/components/app/AudioPlayer.vue +++ b/components/app/AudioPlayer.vue @@ -34,6 +34,10 @@
+ +
+ error +
@@ -129,13 +133,16 @@ export default { onPlaybackClosedListener: null, onPlayingUpdateListener: null, onMetadataListener: null, + onProgressSyncFailing: null, + onProgressSyncSuccess: null, touchStartY: 0, touchStartTime: 0, touchEndY: 0, useChapterTrack: false, isLoading: false, touchTrackStart: false, - dragPercent: 0 + dragPercent: 0, + syncStatus: 0 } }, watch: { @@ -675,6 +682,7 @@ export default { this.isEnded = false this.isLoading = true + this.syncStatus = 0 this.$store.commit('setPlayerItem', this.playbackSession) // Set track width @@ -703,6 +711,8 @@ export default { this.onPlaybackFailedListener = AbsAudioPlayer.addListener('onPlaybackFailed', this.onPlaybackFailed) this.onPlayingUpdateListener = AbsAudioPlayer.addListener('onPlayingUpdate', this.onPlayingUpdate) this.onMetadataListener = AbsAudioPlayer.addListener('onMetadata', this.onMetadata) + this.onProgressSyncFailing = AbsAudioPlayer.addListener('onProgressSyncFailing', this.showProgressSyncIsFailing) + this.onProgressSyncSuccess = AbsAudioPlayer.addListener('onProgressSyncSuccess', this.showProgressSyncSuccess) }, screenOrientationChange() { setTimeout(this.updateScreenSize, 50) @@ -716,6 +726,12 @@ export default { minimizePlayerEvt() { console.log('Minimize Player Evt') this.showFullscreen = false + }, + showProgressSyncIsFailing() { + this.syncStatus = this.$constants.SyncStatus.FAILED + }, + showProgressSyncSuccess() { + this.syncStatus = this.$constants.SyncStatus.SUCCESS } }, mounted() { @@ -751,6 +767,8 @@ export default { if (this.onPlaybackSessionListener) this.onPlaybackSessionListener.remove() if (this.onPlaybackClosedListener) this.onPlaybackClosedListener.remove() if (this.onPlaybackFailedListener) this.onPlaybackFailedListener.remove() + if (this.onProgressSyncFailing) this.onProgressSyncFailing.remove() + if (this.onProgressSyncSuccess) this.onProgressSyncSuccess.remove() clearInterval(this.playInterval) } } diff --git a/components/app/AudioPlayerContainer.vue b/components/app/AudioPlayerContainer.vue index df90791c..0516fd98 100644 --- a/components/app/AudioPlayerContainer.vue +++ b/components/app/AudioPlayerContainer.vue @@ -30,11 +30,9 @@ export default { onSleepTimerEndedListener: null, onSleepTimerSetListener: null, onMediaPlayerChangedListener: null, - onProgressSyncFailing: null, sleepInterval: null, currentEndOfChapterTime: 0, - serverLibraryItemId: null, - syncFailedToast: null + serverLibraryItemId: null } }, watch: { @@ -255,10 +253,6 @@ export default { onMediaPlayerChanged(data) { var mediaPlayer = data.value this.$store.commit('setMediaPlayer', mediaPlayer) - }, - showProgressSyncIsFailing() { - if (!isNaN(this.syncFailedToast)) this.$toast.dismiss(this.syncFailedToast) - this.syncFailedToast = this.$toast('Progress is not being synced', { timeout: false, type: 'error' }) } }, mounted() { @@ -266,7 +260,6 @@ export default { this.onSleepTimerEndedListener = AbsAudioPlayer.addListener('onSleepTimerEnded', this.onSleepTimerEnded) this.onSleepTimerSetListener = AbsAudioPlayer.addListener('onSleepTimerSet', this.onSleepTimerSet) this.onMediaPlayerChangedListener = AbsAudioPlayer.addListener('onMediaPlayerChanged', this.onMediaPlayerChanged) - this.onProgressSyncFailing = AbsAudioPlayer.addListener('onProgressSyncFailing', this.showProgressSyncIsFailing) this.playbackSpeed = this.$store.getters['user/getUserSetting']('playbackRate') console.log(`[AudioPlayerContainer] Init Playback Speed: ${this.playbackSpeed}`) @@ -283,7 +276,6 @@ export default { if (this.onSleepTimerEndedListener) this.onSleepTimerEndedListener.remove() if (this.onSleepTimerSetListener) this.onSleepTimerSetListener.remove() if (this.onMediaPlayerChangedListener) this.onMediaPlayerChangedListener.remove() - if (this.onProgressSyncFailing) this.onProgressSyncFailing.remove() // if (this.$server.socket) { // this.$server.socket.off('stream_open', this.streamOpen) diff --git a/components/connection/ServerConnectForm.vue b/components/connection/ServerConnectForm.vue index 4ef943f9..047a37cc 100644 --- a/components/connection/ServerConnectForm.vue +++ b/components/connection/ServerConnectForm.vue @@ -152,7 +152,7 @@ export default { var payload = await this.authenticateToken() if (payload) { - this.setUserAndConnection(payload.user, payload.userDefaultLibraryId) + this.setUserAndConnection(payload) } else { this.showAuth = true } diff --git a/plugins/constants.js b/plugins/constants.js index b1471010..e6e84210 100644 --- a/plugins/constants.js +++ b/plugins/constants.js @@ -5,6 +5,12 @@ const DownloadStatus = { FAILED: 3 } +const SyncStatus = { + UNSET: 0, + SUCCESS: 1, + FAILED: 2 +} + const CoverDestination = { METADATA: 0, AUDIOBOOK: 1 @@ -31,6 +37,7 @@ const PlayerState = { const Constants = { DownloadStatus, + SyncStatus, CoverDestination, BookCoverAspectRatio, PlayMethod,