Media2

Latest Update Current Stable Release Next Release Candidate Beta Release Alpha Release
October 9, 2019 1.0.1 - - -

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:

dependencies {
    def media2_version = "1.0.1"

    // 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.

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 Q 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