Android Media3 Exoplayer

Background playing, Audio focus, and PiP mode using Media3.

prasad-vennam Updated

File contents

Android Media3 & ExoPlayer 🎬

Handling streaming audio, video playback, and Picture-in-Picture.

⚡ When to Use

  • When asked to build video players, music streaming services, or complex media apps.

🏗️ Core Rules / Pillars

1. Migrating to Media3

  • Pattern: com.google.android.exoplayer2 is fully deprecated. You MUST use androidx.media3:media3-exoplayer.
  • Implementation: Instantiate the ExoPlayer.Builder(context).build() and strictly manage its lifecycle, hooking it to Compose's DisposableEffect to trigger player.release() when leaving the screen.

2. Audio Focus & Background Playback

  • Pattern: If building a music app, you MUST use MediaSession connected to a Foreground Service.
  • Implementation: Request Audio Focus automatically using Media3's player.setAudioAttributes(..., handleAudioFocus = true) so the player pauses gracefully when a phone call comes in.

🚧 Critical Anti-Hallucination Guards

  • Trap: Do not hallucinate MediaBrowserServiceCompat. Media3 replaces the entire legacy MediaSessionCompat stack with a unified MediaSessionService.

prasad-vennam/Awesome-Android-AI-Agent-Skills/tree/main/skills/android-media3-exoplayer commit 9e2fd1f613

Frequently asked questions

npx skillmds@latest add prasad-vennam/android-media3-exoplayer