tonihei 0dc5ed19e2 Improve timestamp smoothing in AudioTrackPositionTracker
The position tracker has two different position sources,
getPlaybackHeadPosition and getTimestamp. Whenever we switch
between these sources, we smooth out the position differences
over a period of one second.

This has two problems:

 1. The smoothing duration is 1 sec regardless of the actual
    position difference. So for small differences, assuming
    the new timestamp is more correct, we needlessly keep
    the tracker with a position offset for longer. For large
    differences, the smoothing may result in an extremely
    large speedup (up to 5x in theory, for a max allowed diff
    of 5 seconds smoothed over a 1 second real time period).

    The solution to this issue is to adjust the smoothing
    period to the actual difference by using a maximum
    speedup/slowdown set to 10% at the moment. Smaller
    differences are corrected faster and larger differences
    are corrected in a slightly smoother way without speeding
    up drastically. We still need an upper bound though (set
    to 1 second difference) where plainly jumping to the correct
    position is likely a better user experience than having a lenghty
    smoothing.

 2. The smoothing is only applied when switching between position
    sources. That means any position drift or jump coming from the
    same source is always taken as it is without any smoothing. This
    is problematic for the getTimstamp-based position in particular
    as it is only sampled every 10 seconds.

    The solution to this problem is to entirely remove the condition
    that smoothing only happens when switching between position
    sources. Instead we can always check whether the position drift
    compared to the last known position is more than the maximum allowed
    speedup/slowdown of 10% and if so, start applying smoothing.

    This helps to smooth out the position progress at the start of
    playback and after resumption when we switch between the position
    sources and both sources are not super reliable yet and it also
    helps for unexpected jumps in the position of getTimestamp later
    on during playback.

PiperOrigin-RevId: 755348271
2025-05-06 06:36:10 -07:00
2025-02-18 02:41:26 -08:00
2025-04-11 04:36:13 -07:00
2022-03-01 09:34:07 +00:00
2022-03-01 09:34:07 +00:00
2021-11-09 10:09:26 +00:00

AndroidX Media

AndroidX Media is a collection of libraries for implementing media use cases on Android, including local playback (via ExoPlayer), video editing (via Transformer) and media sessions.

Documentation

Migration for existing ExoPlayer and MediaSession projects

You'll find a migration guide for existing ExoPlayer and MediaSession users on developer.android.com.

API stability

AndroidX Media releases provide API stability guarantees, ensuring that the API surface remains backwards compatible for the most commonly used APIs. APIs intended for more advanced use cases are marked as unstable. To use an unstable method or class without lint warnings, youll need to add the OptIn annotation before using it. For more information see the UnstableApi documentation.

Using the libraries

You can get the libraries from the Google Maven repository. It's also possible to clone this GitHub repository and depend on the modules locally.

From the Google Maven repository

1. Add module dependencies

The easiest way to get started using AndroidX Media is to add gradle dependencies on the libraries you need in the build.gradle.kts file of your app module.

For example, to depend on ExoPlayer with DASH playback support and UI components you can add dependencies on the modules like this:

implementation("androidx.media3:media3-exoplayer:1.X.X")
implementation("androidx.media3:media3-exoplayer-dash:1.X.X")
implementation("androidx.media3:media3-ui:1.X.X")

Or in Gradle Groovy DSL build.gradle:

implementation 'androidx.media3:media3-exoplayer:1.X.X'
implementation 'androidx.media3:media3-exoplayer-dash:1.X.X'
implementation 'androidx.media3:media3-ui:1.X.X'

where 1.X.X is your preferred version. All modules must be the same version.

Please see the AndroidX Media3 developer.android.com page for more information, including a full list of library modules.

This repository includes some modules that depend on external libraries that need to be built manually, and are not available from the Maven repository. Please see the individual READMEs under the libraries directory for more details.

2. Turn on Java 8 support

If not enabled already, you also need to turn on Java 8 support in all build.gradle.kts files depending on AndroidX Media, by adding the following to the android section:

compileOptions {
  targetCompatibility = JavaVersion.VERSION_1_8
}

Or in Gradle Groovy DSL build.gradle:

compileOptions {
  targetCompatibility JavaVersion.VERSION_1_8
}

Locally

Cloning the repository and depending on the modules locally is required when using some libraries. It's also a suitable approach if you want to make local changes, or if you want to use the main branch.

First, clone the repository into a local directory:

git clone https://github.com/androidx/media.git

Next, add the following to your project's settings.gradle.kts file, replacing path/to/media with the path to your local copy:

(gradle as ExtensionAware).extra["androidxMediaModulePrefix"] = "media3-"
apply(from = file("path/to/media/core_settings.gradle"))

Or in Gradle Groovy DSL settings.gradle:

gradle.ext.androidxMediaModulePrefix = 'media3-'
apply from: file("path/to/media/core_settings.gradle")

You should now see the AndroidX Media modules appear as part of your project. You can depend on them from build.gradle.kts as you would on any other local module, for example:

implementation(project(":media3-lib-exoplayer"))
implementation(project(":media3-lib-exoplayer-dash"))
implementation(project(":media3-lib-ui"))

Or in Gradle Groovy DSL build.gradle:

implementation project(':media3-lib-exoplayer')
implementation project(':media3-lib-exoplayer-dash')
implementation project(':media3-lib-ui')

MIDI module

By default the MIDI module is disabled as a local dependency, because it requires additional Maven repository config. If you want to use it as a local dependency, please configure the JitPack repository as described in the module README, and then enable building the module in your settings.gradle.kts file:

gradle.extra.apply {
  set("androidxMediaEnableMidiModule", true)
}

Or in Gradle Groovy DSL settings.gradle:

gradle.ext.androidxMediaEnableMidiModule = true

Developing AndroidX Media

Project branches

Development work happens on the main branch. Pull requests should normally be made to this branch.

The release branch holds the most recent stable release.

Using Android Studio

To develop AndroidX Media using Android Studio, simply open the project in the root directory of this repository.

Description
About Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
Readme Apache-2.0 760 MiB
Languages
Java 98.3%
Kotlin 0.6%
C++ 0.4%
GLSL 0.3%
PostScript 0.2%
Other 0.1%