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.
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. Useandroidx.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
andMEDIA_URI_QUERY_URI
inMediaConstants
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
- Fixed ANR when dismissing media notification (Ifdcc2, b/148011394)
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
andMEDIA_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
- Add support for (prepare|play)From(MediaId|Uri|Search) (I13475, b/176949057)
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
- Fixed NPE from VersionedParcelable (I1ec28, b/177060207)
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
viaMediaSession#getSessionCompatToken()
- Added
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 callinggetCurrentControllerInfo()
on a releasedMediaSessionCompat
. (aosp/1423291] - Fixed an issue where media2
MediaSession
did not set the active queue item id toPlaybackStateCompat
(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
- Fixed timing issue when updating metadata (I45567, b/143999611)
- SessionResult will preserve the MediaItem from PlayerResult (I927b0, b/154885520)
- Fixed a bug where
MediaController#setVolumeTo()
could change wrong stream volume. (I76870, b/151204736)
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 afterMediaPlayer.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
inMediaPlayer#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
whengetDuration()
is called in anIDLE
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()
withMediaBrowserService
(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.1
contains 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
beforesetPlayer
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
- APIs are mostly matched with
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
andMediaBrowserServiceCompat
- A lightweight version of
media2.session.MediaLibraryService
- Supports better pagination for navigating media items or search results holding lots of items
- Interoperable with
MediaControllerCompat
andMediaBrowserServiceCompat
media2.session.MediaController
- Can connect to
MediaSession
,MediaSessionService
, andMediaLibraryService
- Interoperable with
MediaSessionCompat
andMediaBrowserServiceCompat
- Can connect to
media2.session.MediaBrowser
- Inherits
MediaController
- Can connect to
MediaSession
,MediaSessionService
, andMediaLibraryService
- Interoperable with
MediaSessionCompat
andMediaBrowserServiceCompat
- Inherits
media2.widget.VideoView
- Contains all the functionality of
android.widget.VideoView
- Provides the switch between
TextureView
andSurfaceView
- Can work together with
MediaSession
- Contains all the functionality of
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
orsetController
are no longer allowed to be called viaMediaControlView
(MCV) when theMediaControlView
belongs to aVideoView
Bug fixes
MediaControlView
: The next and previous buttons are clickable only when there are next or previous media itemsMediaControlView
: Fixed a flakyNullPointerException
whenonAttachedToWindow()
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 involvingListenableFuture
, you may temporarily work around the issue by addingandroid.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
toNullPointerException
for the null arguments which marked as @NonNull.
API changes
- Introduced
MediaController.Builder
- Added setter methods for the optional fields of
FileMediaItem.Builder
MediaController
andMediaBrowser
can send application’s connection hints toMediaSession
,MediaSessionService
orMediaLibraryService
- Some methods are renamed to follow Android 10 Media2 APIs
Version 1.0.0-alpha04
December 17, 2018
API changes
- Renamed the following classes:
MediaPlayer2
→MediaPlayer
MediaSession2
→MediaSession
MediaController2
→MediaController
MediaSessionService2
→MediaSessionService
MediaLibraryService2
→MediaLibraryService
MediaBrowser2
→MediaBrowser
MediaMetadata2
→MediaMetadata
Rating2
→Rating
SessionToken2
→SessionToken
SessionCommand2
→SessionCommand
SessionCommandGroup2
→SessionCommandGroup
- Merged the following classes:
DataSourceDesc2
andMediaItem2
have been combined intoMediaItem
MediaPlaylistAgent
andMediaPlayerConnector
have been combined intoSessionPlayer
- Added the following subclasses of
Rating
:HeartRating
,PercentageRating
,StarRating
, andThumbRating
Media2
now usesListenableFuture
for async methods