Kotlin sample that plays adaptive HLS, DASH, and progressive video with AndroidX Media3 ExoPlayer.
This project uses Media3 1.11.1 (media3-exoplayer, media3-exoplayer-hls, media3-exoplayer-dash, media3-ui, and media3-session), verified on Google Maven and the Media3 release notes (stable as of 10 September 2026).
- Plays a short playlist of official Media3 demo samples via
ExoPlayer.setMediaItems(mediaIdon each item is used for CMCD). - Uses
androidx.media3.ui.PlayerViewwith rewind / fast-forward (15s seek increments), next / previous, buffering indicator, subtitle button, repeat (one/all), and shuffle. - Restores the current item, playback position, play-when-ready, speed, mute, repeat, and shuffle across lifecycle events.
- Lets you pick video quality, audio, and text tracks with
Player.trackSelectionParametersandTrackSelectionOverride(the same Tracks APIs Media3 documents for manual selection). - Shows a retry overlay on
Player.Listener.onPlayerErrorusing the Media3PlaybackExceptionerror code. - Publishes an in-activity
MediaSessionso headset, Bluetooth, and system media keys can control the sameExoPlayerinstance while the activity is alive. - Picture-in-picture on API 26+: Home / PiP button uses
PictureInPictureParams. Playback continues in PiP; overlay controls hide. - Overlay controls for playback speed (
0.5x–2.0x), mute / unmute, and resize mode (Fit/Zoom/FillviaPlayerView.resizeMode). - Audio:
AudioAttributes(USAGE_MEDIA,AUDIO_CONTENT_TYPE_MOVIE) with audio-focus handling, plussetHandleAudioBecomingNoisy(true)so playback pauses when a headset is unplugged. - Locks:
ExoPlayer.Builder.setWakeMode(C.WAKE_MODE_NETWORK)so Media3 holds aWakeLockandWifiLockwhile the player is buffering or ready withplayWhenReady(WAKE_LOCKis declared). - Analytics:
PlaybackStatsListenerplusAnalyticsListener.onEventsdrive an overlay with play time, mean video bitrate, dropped frames, and bandwidth. - Subtitles:
PlayerView.subtitleViewusesCaptionStyleCompat(white outlined cues) and a larger fractional text size. - Loading:
DefaultMediaSourceFactory.setCmcdConfigurationFactorysends CMCD request headers, andDefaultLoadErrorHandlingPolicy(6)retries transient loads before failing.
The sample URIs are taken from the Media3 main demo media list:
| Sample | URI |
|---|---|
| Apple BIPBOP HLS (fMP4) | https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8 |
| Tears of Steel DASH HD (clear H264) | https://storage.googleapis.com/wvmedia/clear/h264/tears/tears.mpd |
| Screens 480p (FMP4, H264) | https://storage.googleapis.com/exoplayer-test-media-1/gen-3/screens/dash-vod-single-segment/video-avc-baseline-480.mp4 |
DRM-protected entries from that list are intentionally omitted here (see the separate ExoPlayer DRM sample).
MediaSession.Builder(context, player) is enough for media keys while the player is owned by MainActivity. A MediaSessionService / PlayerNotificationManager foreground notification is not used: this is still a foreground video demo (with PiP), not a background playback service.
- JDK 17 (Android Gradle Plugin 8.11)
- Android Studio Ladybug / Narwhal or newer (or command-line SDK)
- Android SDK with
compileSdk36 /targetSdk35 - Device or emulator on API 24+ with network access
- Unit tests:
./gradlew :app:testDebugUnitTest
From this directory:
./gradlew :app:assembleDebug
./gradlew :app:testDebugUnitTestInstall on a connected device:
./gradlew :app:installDebugOr open the project in Android Studio, wait for Gradle sync, and run the app configuration.
The app needs INTERNET (playlists and segments) and WAKE_LOCK (Media3 wake/wifi locks). Both are already declared.
| Artifact | Role |
|---|---|
androidx.media3:media3-exoplayer:1.11.1 |
Player, TrackSelectionParameters |
androidx.media3:media3-exoplayer-hls:1.11.1 |
HLS MediaSource (from MediaItem URI) |
androidx.media3:media3-exoplayer-dash:1.11.1 |
DASH MediaSource (from MediaItem URI) |
androidx.media3:media3-ui:1.11.1 |
PlayerView / PlayerControlView |
androidx.media3:media3-session:1.11.1 |
MediaSession |
Docs: Getting started with ExoPlayer, Track selection, MediaSession.
MIT License. See the license text below.
MIT License
Copyright (c) 2023 Halil OZEL
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, and/or sell copies of the Software, and
to permit persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.