# Android Media3 Exoplayer

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

- Skill: `prasad-vennam/android-media3-exoplayer` (Agent Skill)
- Install (CLI): `npx skillmds@latest add prasad-vennam/android-media3-exoplayer`
- Raw SKILL.md: https://api.skillmd.com/api/skills/prasad-vennam/android-media3-exoplayer/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: prasad-vennam (https://skillmd.com/u/prasad-vennam)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/prasad-vennam/android-media3-exoplayer

---


# 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`.

