Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+21 more

    Android Media3 & ExoPlayer Production Audio Engine

    1

    Architect and implement production-grade Android Media3 audio engines with background playback and DSP processing.

    $6.99

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    Android Media3 & ExoPlayer Production Audio Engine

    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_PLAYBACK permission to your AndroidManifest.xml.
    • Register the service with the androidx.media3.session.MediaSessionService intent filter.
    • Implement a MediaController in 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

    1. Initialize service by defining a MediaSessionService with the required foreground service types in the manifest.
    2. Configure player using the ExoPlayer.Builder to set audio attributes, wake modes, and session callbacks.
    3. Bind metadata via MediaMetadata objects to sync the UI state with the system media notification.
    4. Apply processing by implementing BaseAudioProcessor to 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.

    Requires manual battery optimization whitelisting for specific OEMs. Focuses on the engine logic rather than UI component rendering.

    How to use

    1. 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. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before any payment.

    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

    Listed21 days ago

    What's inside

    Frequently Asked Questions

    This skill provides the architectural templates and logic required to build a persistent Android background service that survives aggressive OS battery management, preventing playback from being killed when the screen is off.

    Yes, this skill follows the modern androidx.media3 standards, making it the ideal resource for migrating legacy ExoPlayer 2.x implementations or starting new projects that require Android 14+ compatibility.

    It provides the logic for the MediaSessionService, ExoPlayer configuration, and DSP pipelines; however, you will still need to design and build your own UI components using Jetpack Compose or Views.

    The skill provides a specialized implementation of BaseAudioProcessor, allowing you to intercept and modify raw PCM data for effects like crossfading, equalization, and gain control without latency.

    You will receive production-ready boilerplate code, service manifest configurations, and implementation guides for Media3, though you will need to manually handle device-specific battery whitelisting prompts for certain OEMs.

    New in Mobile Development