Skip to content

Instantly share code, notes, and snippets.

@mchowning
Created December 15, 2023 20:37
Show Gist options
  • Save mchowning/70ec0879dc87f7c191fc3a2826510828 to your computer and use it in GitHub Desktop.
Save mchowning/70ec0879dc87f7c191fc3a2826510828 to your computer and use it in GitHub Desktop.
Logging media events on 7.54-rc-3 build
diff --git a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/MediaSessionManager.kt b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/MediaSessionManager.kt
index 7dfd2cab2..0d6902069 100644
--- a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/MediaSessionManager.kt
+++ b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/MediaSessionManager.kt
@@ -118,6 +118,7 @@ class MediaSessionManager(
playbackManager,
episodeManager,
enqueueCommand = { tag, command ->
+ Timber.i("TEST123, adding command to queue: $tag")
val added = commandQueue.tryEmit(Pair(tag, command))
if (added) {
Timber.i("Added command to queue: $tag")
@@ -149,6 +150,7 @@ class MediaSessionManager(
@OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch {
commandQueue.collect { (tag, command) ->
+ Timber.i("TEST123, executing queued command: $tag")
LogBuffer.i(LogBuffer.TAG_PLAYBACK, "Executing queued command: $tag")
command()
}
@@ -493,6 +495,7 @@ class MediaSessionManager(
if (Intent.ACTION_MEDIA_BUTTON == mediaButtonEvent.action) {
val keyEvent = IntentCompat.getParcelableExtra(mediaButtonEvent, Intent.EXTRA_KEY_EVENT, KeyEvent::class.java)
?: return false
+ Timber.i("TEST123, $keyEvent")
if (keyEvent.action == KeyEvent.ACTION_DOWN) {
when (keyEvent.keyCode) {
KeyEvent.KEYCODE_HEADSETHOOK -> {
@@ -537,6 +540,7 @@ class MediaSessionManager(
}
private fun handleMediaButtonSingleTap() {
+ Timber.i("TEST123, handleMediaButtonSingleTap")
// this code allows the user to double tap their play pause button to skip ahead. Basically it allows them 600ms to press it again to cause a skip instead of a play/pause
if (playPauseTimer == null) {
playPauseTimer = Timer().apply {
@@ -545,6 +549,7 @@ class MediaSessionManager(
override fun run() {
logEvent("play from headset hook", inSessionCallback = false)
playbackManager.playPause(sourceView = source)
+ Timber.i("TEST123 performing play/pause")
playPauseTimer = null
}
},
@@ -561,10 +566,12 @@ class MediaSessionManager(
}
private fun handleMediaButtonDoubleTap() {
+ Timber.i("TEST123, handleMediaButtonDoubleTap")
handleMediaButtonAction(settings.headphoneControlsNextAction.value)
}
private fun handleMediaButtonTripleTap() {
+ Timber.i("TEST123, handleMediaButtonTripleTap")
handleMediaButtonAction(settings.headphoneControlsPreviousAction.value)
}
@@ -592,10 +599,12 @@ class MediaSessionManager(
override fun onPlay() {
logEvent("play")
+ Timber.i("TEST123, onPlay")
enqueueCommand("play") { playbackManager.playQueueSuspend(sourceView = source) }
}
override fun onPause() {
+ Timber.i("TEST123, onPause")
logEvent("pause")
enqueueCommand("pause") { playbackManager.pauseSuspend(sourceView = source) }
}
@@ -611,15 +620,18 @@ class MediaSessionManager(
// note: the stop event is called from cars when they only want to pause, this is less destructive and doesn't cause issues if they try to play again
override fun onStop() {
logEvent("stop")
+ Timber.i("TEST123, onStop")
enqueueCommand("stop") { playbackManager.pauseSuspend(sourceView = source) }
}
override fun onSkipToPrevious() {
logEvent("skip backwards")
+ Timber.i("TEST123, onSkipToPrevious")
enqueueCommand("skip backwards") { playbackManager.skipBackwardSuspend(sourceView = source) }
}
override fun onSkipToNext() {
+ Timber.i("TEST123, onSkipToNext")
logEvent("skip forwards")
enqueueCommand("skip forwards") { playbackManager.skipForwardSuspend(sourceView = source) }
}
@@ -635,6 +647,7 @@ class MediaSessionManager(
}
override fun onPlayFromMediaId(mediaId: String?, extras: Bundle?) {
+ Timber.i("TEST123, onPlayFromMediaId")
mediaId ?: return
launch {
logEvent("play from media id", inSessionCallback = false)
@@ -653,6 +666,7 @@ class MediaSessionManager(
}
override fun onCustomAction(action: String?, extras: Bundle?) {
+ Timber.i("TEST123, onCustomAction")
action ?: return
when (action) {
@@ -674,6 +688,7 @@ class MediaSessionManager(
}
override fun onSkipToQueueItem(id: Long) {
+ Timber.i("TEST123, onSkipToQueueItem")
val state = playbackManager.upNextQueue.changesObservable.blockingFirst()
if (state is UpNextQueue.State.Loaded) {
state.queue.find { it.adapterId == id }?.let { episode ->
@@ -686,6 +701,7 @@ class MediaSessionManager(
}
override fun onSeekTo(pos: Long) {
+ Timber.i("TEST123, onSeekTo")
logEvent("seek to $pos")
enqueueCommand("seek to $pos") {
playbackManager.seekToTimeMsSuspend(pos.toInt())
@@ -695,6 +711,7 @@ class MediaSessionManager(
}
private fun markAsPlayed() {
+ Timber.i("TEST123, markAsPlayed")
launch {
val episode = playbackManager.getCurrentEpisode()
episodeManager.markAsPlayed(episode, playbackManager, podcastManager)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment