From cbfc78bfebdf536266cce247640a7cba6c1e69aa Mon Sep 17 00:00:00 2001 From: MShekow Date: Sun, 9 Aug 2020 16:54:40 +0200 Subject: [PATCH] Improved a few logging statements --- .../stopit/service/MediaCallbackService.kt | 13 +++++++------ .../stopit/service/PlaybackStateChangeProcessor.kt | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/de/augmentedmind/stopit/service/MediaCallbackService.kt b/app/src/main/java/de/augmentedmind/stopit/service/MediaCallbackService.kt index df79aeb..d8ffc18 100644 --- a/app/src/main/java/de/augmentedmind/stopit/service/MediaCallbackService.kt +++ b/app/src/main/java/de/augmentedmind/stopit/service/MediaCallbackService.kt @@ -108,20 +108,21 @@ class MediaCallbackService : Service(), OnSharedPreferenceChangeListener { return } val newState = state.state + Log.d(TAG, "onPlaybackStateChanged $newState (last: $lastState)") if (newState == lastState) { + Log.d(TAG, "onPlaybackStateChanged(): ignoring new state $newState because " + + "it matches the old state") return } if (newState != PlaybackState.STATE_PAUSED && newState != PlaybackState.STATE_PLAYING) { - Log.d(TAG, "onPlaybackStateChanged: ignoring irrelevant state $newState") + Log.d(TAG, "onPlaybackStateChanged(): ignoring irrelevant state $newState") return } - Log.d(TAG, "pos " + state.position + " last updttime " + state.lastPositionUpdateTime) val timestampSeconds = (state.position / 1000).toInt() - Log.d(TAG, "timestampSeconds $timestampSeconds") - val correspondingController = controllers[packageAndSessionName] - stateChangeProcessor.processStateChange(newState, timestampSeconds, correspondingController, this.cachedMetadata, this.cachedMediaId) + val correspondingController = controllers[packageAndSessionName]!! + stateChangeProcessor.processStateChange(newState, timestampSeconds, + correspondingController, this.cachedMetadata, this.cachedMediaId) lastState = newState - Log.d(TAG, "onPlaybackStateChanged " + state.state) } override fun onMetadataChanged(metadata: MediaMetadata?) { diff --git a/app/src/main/java/de/augmentedmind/stopit/service/PlaybackStateChangeProcessor.kt b/app/src/main/java/de/augmentedmind/stopit/service/PlaybackStateChangeProcessor.kt index c8acf85..1803960 100644 --- a/app/src/main/java/de/augmentedmind/stopit/service/PlaybackStateChangeProcessor.kt +++ b/app/src/main/java/de/augmentedmind/stopit/service/PlaybackStateChangeProcessor.kt @@ -23,11 +23,11 @@ class PlaybackStateChangeProcessor(val onBookmarkDetected: (Bookmark) -> (Unit), private var lastPauseTimestampMs: Long = 0 private var lastMetaData: AudioMetadata? = null - fun processStateChange(newState: Int, timestampSeconds: Int, controller: MediaController?, + fun processStateChange(newState: Int, timestampSeconds: Int, controller: MediaController, cachedMetadata: AudioMetadata?, cachedMediaId: String?) { val metaData: AudioMetadata? val mediaId: String? - val mediaMetadata = controller!!.metadata + val mediaMetadata = controller.metadata if (mediaMetadata == null) { Log.e(TAG, "processStateChange(): Unable to get metadata (null was returned), " + "using cached one instead")