Media2
Share media contents and controls with other apps.
Latest Update Stable Release Release Candidate Beta Release Alpha Release
January 10, 2024 1.3.0 - - -

Declaring dependencies

To add a dependency on Media2, you must add the Google Maven repository to your project. Read Google's Maven repository for more information.

Add the dependencies for the artifacts you need in the build.gradle file for your app or module:

Groovy

dependencies {
    def media2_version = "1.3.0"

    // Interacting with MediaSessions
    implementation "androidx.media2:media2-session:$media2_version"
    // optional - UI widgets for VideoView and MediaControlView
    implementation "androidx.media2:media2-widget:$media2_version"
    // optional - Implementation of a SessionPlayer
    implementation "androidx.media2:media2-player:$media2_version"
}

Kotlin

dependencies {
    val media2_version = "1.3.0"

    // Interacting with MediaSessions
    implementation("androidx.media2:media2-session:$media2_version")
    // optional - UI widgets for VideoView and MediaControlView
    implementation("androidx.media2:media2-widget:$media2_version")
    // optional - Implementation of a SessionPlayer
    implementation("androidx.media2:media2-player:$media2_version")
}

For more information about dependencies, see Add Build Dependencies.

Feedback

Your feedback helps make Jetpack better. Let us know if you discover new issues or have ideas for improving this library. Please take a look at the existing issues in this library before you create a new one. You can add your vote to an existing issue by clicking the star button.

Create a new issue

See the Issue Tracker documentation for more information.

Version 1.3

Version 1.3.0

January 10, 2024

androidx.media2:media2-*:1.3.0 is released. Version 1.3.0 contains these commits.

Important changes since 1.2.0

  • androidx.media2 is now fully deprecated. Use androidx.media3 instead.

Version 1.3.0-rc01

December 13, 2023

androidx.media2:media2-*:1.3.0-rc01 is released with no changes from Media2 1.3.0-beta01. Version 1.3.0-rc01 contains these commits.

Version 1.3.0-beta01

November 29, 2023

androidx.media2:media2-*:1.3.0-beta01 is released with no changes from Media2 1.3.0-alpha01. Version 1.3.0-beta01 contains these commits.

Version 1.3.0-alpha01

November 15, 2023

androidx.media2:media2-*:1.3.0-alpha01 is released. Version 1.3.0-alpha01 contains these commits.

API Changes

  • androidx.media2 is now fully deprecated. Use androidx.media3 instead. (I53164)

Version 1.2.1

Version 1.2.1

February 9, 2022

androidx.media2:media2-*:1.2.1 is released. Version 1.2.1 contains these commits.

Bug Fixes

  • Fix check for custom Parcelables when targeting API 33.

Version 1.2.0

Version 1.2.0

September 15, 2021

androidx.media2:media2-*:1.2.0 is released. Version 1.2.0 contains these commits.

Important changes since 1.1.0

  • Support interoperability with AndroidX media of (prepare|play)From(MediaId|Uri|Search)
  • Added MEDIA_URI_PATH_SET_MEDIA_URI and MEDIA_URI_QUERY_URI in MediaConstants

Version 1.2.0-rc01

September 1, 2021

androidx.media2:media2-*:1.2.0-rc01 is released. Version 1.2.0-rc01 contains these commits.

Bug Fixes

Version 1.2.0-beta01

June 30, 2021

androidx.media2:media2-*:1.2.0-beta01 is released. Version 1.2.0-beta01 contains these commits.

New Features

  • Support interoperability with AndroidX media of (prepare|play)From(MediaId|Uri|Search)

API Changes

  • Added MEDIA_URI_PATH_SET_MEDIA_URI and MEDIA_URI_QUERY_URI in MediaConstants

Version 1.2.0-alpha01

April 21, 2021

androidx.media2:media2-*:1.2.0-alpha01 is released. Version 1.2.0-alpha01 contains these commits.

API Changes

Bug Fixes

  • Fix a deadlock issue caused by unnecessary synchronized blocks.
  • Reset the player when there are no playable items
  • Allow onCurrentMediaItemChanged to take null media item
  • Make notification updated when current media item is changed
  • Fix interop with controller compat right after session is created

Version 1.1.3

Version 1.1.3

April 21, 2021

androidx.media2:media2-*:1.1.3 is released. Version 1.1.3 contains these commits.

Bug Fixes

  • Fix a deadlock issue caused by unnecessary synchronized blocks.

Version 1.1.2

Version 1.1.2

January 27, 2021

androidx.media2:media2-*:1.1.2 is released. Version 1.1.2 contains these commits.

Bug Fixes

Version 1.1.1

Version 1.1.1

December 16, 2020

androidx.media2:media2-*:1.1.1 is released. Version 1.1.1 contains these commits.

Bug Fixes

  • Make the media notification be updated when the current media item is changed.

Version 1.1.0

Version 1.1.0

December 2, 2020

androidx.media2:media2-*:1.1.0 is released. Version 1.1.0 contains these commits.

Major changes since 1.0.0

  • Added more APIs for handling media tracks
  • Better support of interoperability with AndroidX media library
    • Added MediaSession#setMediaUri
    • Exposed MediaSessionCompat.Token via MediaSession#getSessionCompatToken()

Version 1.1.0-rc01

October 28, 2020

androidx.media2:media2-*:1.1.0-rc01 is released. Version 1.1.0-rc01 contains these commits.

  • Fixed an issue where MediaController notified callbacks while holding a lock, leading to potential deadlocks (I76c56
  • Fixed an issue where MediaSessionImplBase#isClosed() could crash when calling getCurrentControllerInfo() on a released MediaSessionCompat. (aosp/1423291]
  • Fixed an issue where media2 MediaSession did not set the active queue item id to PlaybackStateCompat (aosp/1421652)
  • Added BIND_INCLUDE_CAPABILITIES flag when binding to the service, which allows headless media applications to access the location if they have the permission. This is useful for Android Auto apps in particular. (aosp/1440731)

Version 1.1.0-beta01

September 16, 2020

androidx.media2:media2-*:1.1.0-beta01 is released. Version 1.1.0-beta01 contains these commits.

Bug Fixes

  • Reset current position when media item changes
  • Send metadata and buffering state when connected
  • Fix crash when sending large data between a session and a controller
  • Add <queries> to manifest for media and media2 for Android 11
  • Fix NPE for MediaController.getPlaylist()
  • Disable progress bar of MediaControlView when seek command is not allowed
  • Notify PlaybackStateCompat when a session’s current media item changed
  • Fix parceling of SessionPlayer.TrackInfo

Version 1.1.0-alpha01

June 24, 2020

androidx.media2:media2-*:1.1.0-alpha01 is released. Version 1.1.0-alpha01 contains these commits.

Bug Fixes

Version 1.0.3

Version 1.0.3

February 19, 2020

androidx.media2:media2-*:1.0.3 is released. Version 1.0.3 of media2-{common,player,session} contains these commits and Version 1.0.3 of media2-widget contains these commits

Bug Fixes

  • Fixed a NullPointerException when creating MediaController with a null callback
  • Fixed issue where onPlaylistChanged() was not being called after MediaPlayer.setMediaItem

Version 1.0.2

Version 1.0.2

February 5, 2020

androidx.media2:media2-*:1.0.2 is released. Version 1.0.2 of media2-{common,player,session} contains these commits and Version 1.0.2 of media2-widget contains these commits

Bug fixes

  • Fixed an IndexOutOfBoundsException in MediaPlayer#getSelectedTrack(). (aosp/987003)
  • Improved handling of the case where ExoPlayer calls getDuration() and media item doesn't exist (aosp/987484)
  • Fixed a bug where ExoPlayer would not throw an IllegalStateException when getDuration() is called in an IDLE state (aosp/987246)
  • Do not allow custom Parcelables for media2 (aosp/1091056)
  • Fixed an issue that caused hanging in close() (aosp/1096455)
  • MediaBrowser: Improved the handling of errors in subscribe() with MediaBrowserService (aosp/1158057)
  • Fixed a MediaController crash with the Framework MediaSession(aosp/1177663)
  • Don't notify session info via callbacks when the connection is made (aosp/1195030, b/142925848)
  • Fixed an issue where a SessionResult can be sent more than once unexpectedly from MediaController (aosp/1198634)
  • Fixed an issue where MediaController might send disallowed commands to MediaSession, so MediaSession now sends RESULT_ERROR_PERMISSION_DENIED (aosp/1204183)
  • Fixed a flaky issue with MediaControllerView#setPlayer (aosp/987004)

Version 1.0.1

Version 1.0.1

October 9, 2019

androidx.media2:media2-*:1.0.1 is released. Version 1.0.1 of androidx.media2:media2-{player, session}:1.0.1 contains these commits and Version 1.0.1 of androidx.media2:media2-widget:1.0.1contains these commits.

Bug fixes

  • Fixed a RuntimeException when a subclass of MediaItem is sent across the process (aosp/1098971)
  • Fixed an issue where MediaPlayer only calls onCurrentMediaItemChanged() once when playing a playlist
  • Fixed an issue where MediaPlayer could play a playlist with more than 2 items (aosp/1108440)
  • Fixed an issue where the player continues to play on SurfaceView, even though it is invisible
  • Fixed a VideoView playback issue that occurs when a call is made to setViewType before setPlayer

Version 1.0.0

September 5, 2019

androidx.media2:media2-*:1.0.0 is released. These are the commits included media2-{player, session}:1.0.0 and these are the commits included in media2-widget:1.0.0.

Major Features of Media2 1.0.0

Media2 is the next generation of following Media APIs: MediaSession, MediaController, MediaBrowser, MediaBrowserService, VideoView, and MediaControlView.

  • media2.player.MediaPlayer
    • APIs are mostly matched with android.media.MediaPlayer, and the underlying engine is ExoPlayer
    • Built-in audio focus and noise handling
    • Implements SessionPlayer
  • media2.session.MediaSession
    • Provides fine-grained permission controls
    • Supports custom layouts
    • Easy to use with SessionPlayer, such as androidx.media2.player.MediaPlayer
    • Interoperable with MediaControllerCompat
  • media2.session.MediaSessionService
    • A lightweight version of MediaLibraryService
    • Provides service lifecycle management for background playback
    • Interoperable with MediaControllerCompat and MediaBrowserServiceCompat
  • media2.session.MediaLibraryService
    • Supports better pagination for navigating media items or search results holding lots of items
    • Interoperable with MediaControllerCompat and MediaBrowserServiceCompat
  • media2.session.MediaController
    • Can connect to MediaSession, MediaSessionService, and MediaLibraryService
    • Interoperable with MediaSessionCompat and MediaBrowserServiceCompat
  • media2.session.MediaBrowser
    • Inherits MediaController
    • Can connect to MediaSession, MediaSessionService, and MediaLibraryService
    • Interoperable with MediaSessionCompat and MediaBrowserServiceCompat
  • media2.widget.VideoView
    • Contains all the functionality of android.widget.VideoView
    • Provides the switch between TextureView and SurfaceView
    • Can work together with MediaSession
  • media2.widget.MediaControlView
    • Better look and feel
    • Contains all the functionality of android.widget.MediaController
    • Provides subtitle track selection, playback speed selection, and full screen mode

Version 1.0.0-rc02

August 22, 2019

androidx.media2:media2-*:1.0.0-rc02 is released and the changes included in this version can be found here. This release includes androidx.media2:media2-widget:1.0.0-rc02 and the changes included in this version can be found here.

New features

  • setPlayer or setController are no longer allowed to be called via MediaControlView (MCV) when the MediaControlView belongs to a VideoView

Bug fixes

  • MediaControlView: The next and previous buttons are clickable only when there are next or previous media items
  • MediaControlView: Fixed a flaky NullPointerException when onAttachedToWindow() is called
  • Media2 Widget now handles the new media item’s metadata properly when the current media item changed

Media2-Widget Version 1.0.0-beta01

July 2, 2019

androidx.media2:media2-widget:1.0.0-beta01 is released. The commits included in this version can be found here.

New features

  • Background playback: Instead of creating player inside of VideoView, VideoView can take SessionPlayer or MediaController so that the app can move to background playback mode seamlessly.
  • Removed the dependency with media2-player library
  • Added onViewTypeChangedListener

API changes

  • Visibility change from public to protected:
    • VideoView.onMeasure(int, int)
    • VideoView.onAttachedToWindow()
    • VideoView.onDetachedFromWindow()
    • MediaControlView.onMeasure(int, int)
  • Removed:
    • VideoView.getSessionToken()
    • VideoView.setAudioAttributes(AudioAttributesCompat)
    • VideoView.setMedaItem(MediaItem)
    • MediaControlView.setSessionToken(SessionToken)
  • Added:
    • VideoView.setMediaController(MediaController)
    • VideoView.getMediaControlView()
    • VideoView.setMediaController(MediaController)
    • VideoView.setPlayer(SessionPlayer)
    • VideoView.setOnViewTypeChangedListener()
    • MediaControlView.setPlayer(SessionPlayer)
    • MediaControlView.setMediaController(MediaContoller)

Version 1.0.0-rc01

June 18, 2019

androidx.media2:media2-common:1.0.0-rc01, androidx.media2:media2-player:1.0.0-rc01, and androidx.media2:media2-session:1.0.0-rc01 is released. The commits included in this version can be found here.

API changes

  • Dependencies on ListenableFuture have been migrated back to Guava’s standalone implementation.

  • Note that if you have test targets that depend on the full Guava artifact, you may encounter a dependency resolution conflict when using certain versions of Android Gradle Plugin. If you encounter a Could not resolve all artifacts error involving ListenableFuture, you may temporarily work around the issue by adding android.dependency.useConstraints=false to your project’s build configuration. We are currently working on a permanent fix within Android Gradle Plugin to be released at a later date.

Version 1.0.0-beta02

June 5, 2019

androidx.media2:media2-common:1.0.0-beta02, androidx.media2:media2-player:1.0.0-beta02, and androidx.media2:media2-session:1.0.0-beta02 are released. The commits included in this version can be found here.

Bug fixes

  • Setting negative playback speed on androidx.media.player.MediaPlayer will return RESULT_ERROR_BAD_VALUE.
  • Replace Guava ListenableFuture with Jetpack implementation (aosp/968828)

Version 1.0.0-beta01

May 7, 2019

androidx.media2:media2-common:1.0.0-beta01, androidx.media2:media2-player:1.0.0-beta01 , and androidx.media2:media2-session:1.0.0-beta01 are released. The commits included in this version can be found here.

New features

  • Libraries are separated into 3 pieces: media2-common, media2-player, media2-session
  • Changed IllegalPointerException to NullPointerException for the null arguments which marked as @NonNull.

API changes

  • Introduced MediaController.Builder
  • Added setter methods for the optional fields of FileMediaItem.Builder
  • MediaController and MediaBrowser can send application’s connection hints to MediaSession, MediaSessionService or MediaLibraryService
  • Some methods are renamed to follow Android 10 Media2 APIs

Version 1.0.0-alpha04

December 17, 2018

API changes

  • Renamed the following classes:
    • MediaPlayer2MediaPlayer
    • MediaSession2MediaSession
    • MediaController2MediaController
    • MediaSessionService2MediaSessionService
    • MediaLibraryService2MediaLibraryService
    • MediaBrowser2MediaBrowser
    • MediaMetadata2MediaMetadata
    • Rating2Rating
    • SessionToken2SessionToken
    • SessionCommand2SessionCommand
    • SessionCommandGroup2SessionCommandGroup
  • Merged the following classes:
    • DataSourceDesc2 and MediaItem2 have been combined into MediaItem
    • MediaPlaylistAgent and MediaPlayerConnector have been combined into SessionPlayer
  • Added the following subclasses of Rating: HeartRating, PercentageRating, StarRating, and ThumbRating
  • Media2 now uses ListenableFuture for async methods