- Home
- Skills
- Mobile Development
- Android Media3 & ExoPlayer Production Audio Engine
Works with the AI Agents you already use
Android Media3 & ExoPlayer Production Audio Engine
Architect and implement production-grade Android Media3 audio engines with background playback and DSP processing.
$6.99
Android Media3 & ExoPlayer Production Audio Engine
Example session with this skill installed
Help me implement a Media3 service in Kotlin that supports background playback, handles headphone disconnects, and uses equal-power crossfading.
- Read your context and instructions
- Compiled the android media3
I have outlined the implementation for a production-grade MediaSessionService using Media3. This setup includes the necessary lifecycle management to prevent the OS from killing the playback process and implements a trigonometric crossfade to maintain constant audio energy.
Android Media3 Audio Engine Implementation
// 1. Service Implementation with ExoPlayer & MediaSession
class AudioEngineService : MediaSessionService() {
private var mediaSession: MediaSession? = null
private lateinit var exoPlayer: ExoPlayer
override fun onCreate() {
super.onCreate()
val audioAttributes = AudioAttributes.Builder()
.setContentType(C.AUDIO_CONTENT_TYPE_MUSIC)
.setUsage(C.USAGE_MEDIA)
.build()
exoPlayer = ExoPlayer.Builder(this)
.setAudioAttributes(audioAttributes, true)
.setHandleAudioBecomingNoisy(true)
.setWakeMode(C.WAKE_MODE_LOCAL)
.build()
mediaSession = MediaSession.Builder(this, exoPlayer).build()
}
override fun onGetSession(controllerInfo: MediaSession.ControllerInfo) = mediaSession
override fun onDestroy() {
mediaSession?.run {
player.release()
release()
}
super.onDestroy()
}
}
// 2. Equal-Power Crossfade Logic
fun applyEqualPowerCrossfade(player: ExoPlayer, currentMs: Long, durationMs: Long, fadeMs: Long = 3000L) {
val remaining = durationMs - currentMs
player.volume = when {
remaining <= fadeMs -> {
val ratio = (remaining.toFloat() / fadeMs).coerceIn(0f, 1f)
kotlin.math.sin(ratio.toDouble() * Math.PI / 2.0).toFloat()
}
currentMs <= fadeMs -> {
val ratio = (currentMs.toFloat() / fadeMs).coerceIn(0f, 1f)
kotlin.math.sin(ratio.toDouble() * Math.PI / 2.0).toFloat()
}
else -> 1.0f
}
}
Next steps
- Add the
FOREGROUND_SERVICE_MEDIA_PLAYBACKpermission to yourAndroidManifest.xml. - Register the service with the
androidx.media3.session.MediaSessionServiceintent filter. - Implement a
MediaControllerin your UI layer to connect to this service.
Connects securely to your tools. The creator never sees your data.
About this skill
Implementing reliable background audio on Android is notoriously difficult due to aggressive battery management and complex lifecycle requirements. This skill provides the architectural patterns needed to build production-grade audio engines using modern Android Media3 and ExoPlayer. It focuses on maintaining persistent playback, handling system-level media controls, and implementing advanced DSP features.
What it does
- Architects MediaSessionService by moving playback logic out of ViewModels and into robust background services.
- Configures ExoPlayer with essential audio attributes, wake locks, and automatic "noisy" audio handling for headphone disconnects.
- Syncs system controls to ensure metadata, artwork, and scrubbers appear correctly on lockscreens and Android Auto.
- Calculates equal-power crossfade using trigonometric curves to eliminate volume dips between tracks.
- Injects DSP pipelines through custom audio processors for real-time filtering, equalizers, and gain control.
How it works
- Initialize service by defining a
MediaSessionServicewith the required foreground service types in the manifest. - Configure player using the
ExoPlayer.Builderto set audio attributes, wake modes, and session callbacks. - Bind metadata via
MediaMetadataobjects to sync the UI state with the system media notification. - Apply processing by implementing
BaseAudioProcessorto manipulate raw PCM byte buffers for audio effects.
Frameworks & tools
Specifically designed for Android development using Kotlin, Jetpack Compose, androidx.media3, and ExoPlayer. It covers implementation requirements from Android 8.0 through Android 15+.
Why this beats prompting it yourself
Generic prompts often lead to playback being killed by the OS or incorrect notification behavior. This skill enforces strict service lifecycle rules and proven battery optimization strategies that prevent common production failures on devices like Samsung or Xiaomi.
Use cases
- Building a music streaming app with seamless DJ-style crossfading.
- Implementing a podcast player that requires persistent background playback and lockscreen controls.
- Creating an audiophile utility with custom 6-band EQ and bass boost DSP filters.
- Migrating a legacy ExoPlayer 2.x codebase to the modern Media3 standard.
Known limitations
Requires manual handling of battery optimization whitelisting prompts for specific Chinese OEMs. Does not include UI components for the player interface itself.
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Mobile Development.
Requires manual battery optimization whitelisting for specific OEMs. Focuses on the engine logic rather than UI component rendering.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 21 days ago
Permissions
No special permissions declared or detected