Playback Overlap Issue When App Reloads

Hi everyone,

I’m building a music player app using ExoPlayer combined with a custom MediaNotification extension.

Problem:

When the app reloads (like reopening the screen or app regaining focus), and a song is already playing in the background, pressing a new play button causes overlapping audio — instead of pausing the previous one.


:test_tube: What I’ve Tried:

  1. :white_check_mark: Using a CallbackMusicPlayer block to handle:

    • "Play" → resumes ExoPlayer
    • "Pause" → pauses ExoPlayer
    • "Next", "Previous", etc.
  2. :white_check_mark: Created a custom procedure:

This allows me to simulate notification actions using logic, not taps.

  1. :white_check_mark: Tried using TinyDB to save playback state and song info

When I tap the Pause button on the notification manually, it works perfectly (pauses all sounds, even if overlapping).


:magnifying_glass_tilted_left: What I Need:

How can I auto-pause any ongoing background playback (from my own app’s ExoPlayer) when:

  • The screen initializes again
  • Or before a new song starts playing

Bonus: Is there a way to detect and control the currently playing instance without relying only on manual notification actions?

Any help or ideas would be greatly appreciated :folded_hands: