2573 Commits

Author SHA1 Message Date
shahddaghash
20ab1ea8e5 ShadowMediaCodecConfig: Replace "exotest" with "media3" in codec names
The "exotest" prefix was associated with decoders configured for ExoPlayer tests.
However, after adding encoder support to ShadowMediaCodecConfig and migrating transcoding tests to use it, changing the prefix to "media3" makes it more expressive.
Sump files were updated accordingly.

This is a non-functional change.

PiperOrigin-RevId: 751357719
2025-04-25 04:07:49 -07:00
tonihei
50345b03aa Fix memory leak caused by removing wrong period from List
MergingMediaSource started keeping references to all MediaPeriods
it ever created since 191bc094a5 as the cleanup step attempted
to remove the outer merged period from the list instead of the
inner period of child source.

Issue: androidx/media#2338
PiperOrigin-RevId: 750566825
2025-04-23 06:21:48 -07:00
tonihei
a7c897003c Fix bug where a MaskingMediaSource never throws prepare error
We suppressed the direct error throwing ability in <unknown commit>
to avoid throwing errors later in the playlist too early. This
logic got moved to MaskingMediaSource in <unknown commit>, but its
original purpose was no longer needed when the player stopped
calling this method directly in <unknown commit>.

This left a pending bug that any other usage of MaskingMediaSource
(e.g. within AdsMediaSource) no longer forwards source prepare
errors.

Issue: androidx/media#2337
PiperOrigin-RevId: 750537823
2025-04-23 04:13:30 -07:00
jbibik
ab6b0f6e10 [ui-compose] Eliminated race condition inside button state
A bug was introduced because it was unclear that button state creation and listener registration were not an atomic operation. This happens because the `LaunchedEffect` which starts the listen-to-Player-Events coroutine can be pre-empted with other side effects, including the ones that change something in the Player.

`remember*State` functions create some button state object and initialise it with the correct fresh values pulled out of the Player. The subscription to Player events with a registration of a Listener(via `*ButtonState.observe()`) is not immediate. It *returns* immediately, but is instead scheduled to happen *later*, although within the same Handler message. Other LaunchedEffects could have been scheduled earlier and could take place between the button state creation and listener subscription.

This is not a problem if no changes to the player happen, but if we miss the *relevant* player events, we might end up with a UI that is out of sync with reality (e.g. button enabled/disabled when it should be flipped, icons toggled the wrong way). The way to fix this is to pull the latest values out of the Player on demand upon starting to listen to Player events.

PiperOrigin-RevId: 750183793
2025-04-22 07:31:19 -07:00
michaelkatz
d3328456a7 Allow trailing whitespace in RTSP SessionDescription lines
This CL fixes the parser for the RTSP SessionDescription such that it will not choke if there is trailing whitespace in the lines.

PiperOrigin-RevId: 750158624
2025-04-22 05:53:56 -07:00
tonihei
0e0553d150 Remove leftover release notes line
The change in the demo app was part of 1.6.0 and we don't need to
document demo app changes.

PiperOrigin-RevId: 750120001
2025-04-22 03:15:55 -07:00
bachinger
d0833c4e7c Make HlsInterstitialsAdsLoader resumable
This allows the app to store the ad playback state and then
when starting again, allow them to resume with the same
ad playback state. This way, users don't have to watch the same
ads twice if/when playback was interrupted. For instance, when the
app was put into background and then is foregrounded again.

PiperOrigin-RevId: 748737832
2025-04-17 10:56:14 -07:00
bachinger
a64d51c909 Fix NullPointerException in MediaBrowserImplLegacy
PiperOrigin-RevId: 748312932
2025-04-16 09:05:55 -07:00
tonihei
5d540acbeb Make implementation of adLoadTimeoutRunnable safer
We currently start the timeout as soon as the player enters
the target ad, but that ad hasn't loaded yet (= at the point
where we actively start waiting for it). And then we try to
clear the timeout at various places that mean we are no longer
waiting for this ad. This is very error-prone though because
there are a lot of places in the AdTagLoader that change the
AdPlaybackState and could mark the ad as skipped, failed or
loaded.

A much less error-prone way of clearing the timeout is not
even try to find all places that may revert the wait condition
and instead just check if we are still waiting at the point
of executing the timeout message.

PiperOrigin-RevId: 748291720
2025-04-16 07:49:53 -07:00
aquilescanta
405365c228 Implement device volume adjustment in CastPlayer
Issue: androidx/media#2089
PiperOrigin-RevId: 747861812
2025-04-15 07:17:41 -07:00
tonihei
70e7121a51 Make some audio processors public
ChannelMappingAudioProcessor, TrimmingAudioProcessor and
ToFloatPcmAudioProcessor are currently package-private even
though they might be useful in custom audio processing chains
or custom version of audio sinks.

Issue: androidx/media#2339
PiperOrigin-RevId: 747857815
2025-04-15 07:03:04 -07:00
shahddaghash
07be60ed93 Add encoder support to ShadowMediaCodecConfig
This is a step towards unifying ShadowMediaCodecConfig structure to accommodate having both ExoPlayer and Transcoding codecs configuration.

This includes:
* Adding ability to configure encoders by calling `addEncoders(CodecInfo...)`
* A new factory method that takes specific encoders and decoders CodecInfos
* A new method `addCodecs(boolean, CodecConfig, CodecInfo...) that configures codecs with specified behavior by passing a `CodecConfig`.

This CL also includes migrating Transformer tests to ShadowMediaCodecConfig.

PiperOrigin-RevId: 747390451
2025-04-14 06:30:04 -07:00
bachinger
ed56ed22fb Don't enqueue ad periods that start after the end of the period
Issue: androidx/media#2215
PiperOrigin-RevId: 747376615
2025-04-14 05:41:31 -07:00
tonihei
3205811f23 Update release notes for 1.6.1
PiperOrigin-RevId: 747337479
2025-04-14 03:26:00 -07:00
tianyifeng
344f249511 Fix issue where ProgressiveMediaPeriod fails assertPrepared
In `PreloadMediaSource` we accesses the `MediaPeriod.getBufferedPositionUs()` when we receive `onContinueLoadingRequested()` from the period. For `ProgressiveMediaPeriod` which requires loading a portion of media file to get it prepared, there is a chance that it needs more than one round of `onContinueLoadingRequested()` -> `continueLoading()` to complete preparation, for example, when the  `setContinueLoadingIntervalBytes()` is small enough to not include the full information for preparation. Thus we should avoid `MediaPeriod.getBufferedPositionUs()` being called before period is prepared, as it will fail at `assertPrepared`.

Issue: androidx/media#2315

#cherrypick

PiperOrigin-RevId: 746490375
2025-04-11 09:34:57 -07:00
tonihei
9ca8540f85 Ensure media notification provider can be updated
Some interactions create a default notification provider if
no custom one is set yet (e.g. setForegroundServiceTimeoutMs).
This means a later call to setMediaNotificationProvider will
silently fail to apply the new provider.

This can be fixed by making the media notification provider
updatable.

Issue: androidx/media#2305
PiperOrigin-RevId: 746428193
2025-04-11 05:56:52 -07:00
bachinger
5f940af3df Always return empty timeline when wrapped player is empty
In `PlayerWrapper.getCurrentTimelineWithCommandCheck()` we
always return `new CurrentMediaItemOnlyTimeline(this)` in
case the wrapped player doesn't have `COMMAND_GET_TIMELINE`
available but has `COMMAND_GET_CURRENT_MEDIA_ITEM`. This is
emulating a single item timeline with a static window count
of 1 which isn't correct when the wrapped player is empty.

Instead, when the wrapped player is empty we need to return
an empty timeline to match the wrapped player.

Issue: androidx/media#2320
PiperOrigin-RevId: 746071237
2025-04-10 09:59:25 -07:00
tonihei
f672590b2d Remember explicit notification dismissal
Currently, a notification may be recreated even if a user dismissed
it as long as the standard conditions for a notification are true.

To avoid this effect, we plumb the dismissal event to the notification
controller, so that it can override its `shouldShowNotification`
decision. The plumbing sets an extra on the media key intent, which
the session forwards as a custom event to the media notification
controller if connected.

Issue: androidx/media#2302
PiperOrigin-RevId: 745989590
2025-04-10 05:38:58 -07:00
bachinger
1b3658e357 Adjust AGGREGATES_CALLBACKS_WITHIN_TIMEOUT_MS and make it configurable
PiperOrigin-RevId: 745585764
2025-04-09 07:47:12 -07:00
tonihei
f9617e1f8d Clear surface from previous player when assigning a new player
The surface must only be used by one player at a time. To ensure
that, we can keep a reference to the previously used player
and clear its surface reference before assigning to a new one.

Note that we do not need to clear the surface in onDispose
of a DisposableEffect because the lifecycle management of the
surface is moved to the Player and the Player takes care of
unregistering its surface reference as soon as the surface is
destroyed (which happens when the AndroidView element is no longer
is the Composable tree).

PiperOrigin-RevId: 745558414
2025-04-09 06:14:47 -07:00
tianyifeng
eae886fe28 Add Factory for SegmentDownloader implementations
PiperOrigin-RevId: 745530254
2025-04-09 04:33:27 -07:00
rohks
9182b413dc Ensure chunk duration is set in CmcdData for HLS media
Previously, encrypted media segments did not have the chunk duration set,
causing an assertion failure during `CmcdData` creation. With this change,
the chunk duration is always set, while `CmcdData` ensures it is applied
only for media chunks.

Issue: androidx/media#2312
PiperOrigin-RevId: 745196718
2025-04-08 10:21:36 -07:00
ibaker
83efd8eb66 Add ScrubbingModeParameters
This adds the option to disable certain track types during scrubbing,
with audio and metadata disabled by default.

The tracks are disabled by modifying the `TrackSelectionParameters`,
but in a way that is invisible to
`Player.getTrackSelectionParameters()` and
`Player.Listener.onTrackSelectionParametersChanged`. This allows us to
clearly reason about what should happen if
`Player.setTrackSelectionParameters(...)` is called during scrubbing
mode. The **side effects** of disabling the tracks are all visible
through `Player.Listener` and `AnalyticsListener` (renderer disabled,
decoder released, `onTracksChanged`, etc.).

PiperOrigin-RevId: 743961632
2025-04-04 08:58:44 -07:00
sheenachhabra
72bb474604 Add experimental prefix to setForce{Audio,Video}Track APIs
These APIs are likely to change/removed in near future.

PiperOrigin-RevId: 743899703
2025-04-04 04:57:56 -07:00
michaelkatz
8327a2a52d Do not enable offload scheduling while preparing next media
ExoPlayer disables sleeping for offload when the reading period advances and re-evaluates turning it back on when the playing period advances. For playlists of short items where the reading period could advance much further than the playing period, sleeping should still be disabled until the playing period advances to match the current reading period.

Issue: androidx/media#1920
PiperOrigin-RevId: 743503063
2025-04-03 04:15:15 -07:00
bachinger
d133300627 Make AdPlaybackState.withAdDurationsUs work with removed ad groups
The assertion is changed to check that the number of passed
in arrays of durations is always matching `adGroupCount`
according to the behavior of `withRemoveAdGroupCount(int)`.

Issue: androidx/media#2267
PiperOrigin-RevId: 743185176
2025-04-02 10:15:29 -07:00
tonihei
a1ed0d4ff6 Update PlayerSurface to directly use AndroidView
The proxy classes Android(Embedded)ExternalSurface just provide a
simple API surface around AndroidView wrapping SurfaceView and
TextureView respectively. However, this prevents accessing the
underlying views directly, which is needed for full lifecycle
tracking by the Player and to access surface size updates (which
are not available when the API is reduced to just `Surface`).

Instead of the proxy classes, we can directly use AndroidView from
PlayerSurface. This allows to call the proper Player APIs to set
SurfaceView or TextureView, so that the Player can keep track of
the view lifecycle and update its internal state and size tracking
accordingly. Because the player keeps tracks of the lifecycle,
none of the callback structure in Android(Embedded)ExternalSurface
is needed, nor are the additional setters for options that are
all default.

PiperOrigin-RevId: 743079058
2025-04-02 04:35:03 -07:00
ibaker
d315d90f7a Add scrubbing mode API to ExoPlayer
This initial version prevents incoming seeks from pre-empting
in-progress seeks, allowing more seeks to complete when the scrubber
bar is dragged quickly back and forth.

More scrubbing optimizations will be added in follow-up changes.

PiperOrigin-RevId: 743052527
2025-04-02 03:00:05 -07:00
tianyifeng
ce3754a740 Add PlaybackParameters.withPitch() method
Issue: androidx/media#2257
PiperOrigin-RevId: 742693410
2025-04-01 07:42:27 -07:00
sheenachhabra
2141d9ef9c Make forceAudioTrack flag mandatory when gap is at start
Earlier when gap is at the start of a sequence
it was automatically filled with silent audio.
Now setting forceAudioTrack flag is mandatory to
indicate that the gap at the start of a sequence
must be filled with silent audio.

PiperOrigin-RevId: 742625236
2025-04-01 03:40:41 -07:00
michaelkatz
a4f5f67d7e Fix media period mismatch during recoverable renderer error processing
If a recoverable renderer error occurred just before playing period transition(aka media item transition) then the player may enter a continuous loop of retrying to play the previous media item.

This was most easily reproduced in an audio offload scenario where init in offload mode always fails. In initializing the following media, the process would fail with recoverable error to try in non-offload mode. The player would try to recover with playing the previous media item. Most times it would skip to the next track but not always.

Issue: androidx/media#2229
PiperOrigin-RevId: 741213293
2025-03-27 11:03:49 -07:00
Copybara-Service
f2fa0f7b2a Merge pull request #2253 from nirb999:main
PiperOrigin-RevId: 741092998
2025-03-27 03:50:08 -07:00
ibaker
0d60c5bf25 MP4: Parse alternate_group and expose it in Format.metadata
Issue: androidx/media#2242
PiperOrigin-RevId: 740794206
2025-03-26 09:21:21 -07:00
Rohit Singh
916ffcfe5f Add RELEASENOTES entry 2025-03-26 14:12:55 +00:00
michaelkatz
a220b0cb5e Add support for RTSPT scheme in RtspMediaSource.Factory
If the `RtspMediaSource.Factory` is provided a `MediaItem` containing a uri with the scheme `rtspt`, then the factory will create its `RtspMediaSource` configured to use TCP.

Issue: androidx/media#1484
PiperOrigin-RevId: 740340604
2025-03-25 07:32:58 -07:00
tianyifeng
a1738f96f9 Add a Factory for DownloadHelper and deprecate forMediaItem() methods
PiperOrigin-RevId: 739909021
2025-03-24 06:03:24 -07:00
tonihei
a472300c7a Use getAchievableFrameRatesFor to find approximate SW codec limits
We currently assume SW codecs are capable of playing all resolutions
and frame rates up to their declared supported maximum values, even
though the are likely not able to keep up playback smoothly for higher
resolutions. For HW codecs we can check PerformancePoints to declare
them as EXCEEDS_CAPABILITIES if they technically support a format but
are not performant enough. We can do the same for SW codecs by
checking getAchievableFrameRatesFor.

PiperOrigin-RevId: 739253653
2025-03-21 11:57:55 -07:00
Copybara-Service
2d1bcc77be Merge pull request #2235 from MGaetan89:add_CastPlayer_playlistMetadata
PiperOrigin-RevId: 738455260
2025-03-19 10:38:33 -07:00
tonihei
a37e906a0a Update release notes for 1.6.0
PiperOrigin-RevId: 738443368
2025-03-19 10:09:46 -07:00
Marc Baechinger
1db0fe2d19 Add release notes 2025-03-19 15:49:00 +01:00
tonihei
06c0f5549e Exclude Xiaomi and OPPO devices from detached surface mode
Ideally, we'd find a more targeted exclusion as it may depend on
specific codecs. The current workaround should help with the
reported issues that are limited to Xiaomi and OPPO.

Issue: androidx/media#2059

#cherrypick

PiperOrigin-RevId: 738017969
2025-03-18 08:37:59 -07:00
tonihei
0991dbcd7d Update release notes for 1.6.0-rc02
PiperOrigin-RevId: 737986781
2025-03-18 06:51:36 -07:00
tonihei
eef678f263 Wait for first frame when using placeholder surface
We currently pretend to be ready when using a placeholder
surface irrespective of whether the renderer is actually
ready to immediately render when a surface is attached.

This causes issues in two ways:
 - Apps don't know when a player without a surface can be
   connected to a surface and immediately start playing
 - A paused player without a surface will use the 1 second
   default doSomeWork loop, causing any pending decoding
   to be extremely slow (see Issue: androidx/media#1973).

The fix is to let the placeholder surface case use the same
paths as the regular surface and with marking the first
frame as available as soon as the codec output buffer for it
is pending and ready for release.

PiperOrigin-RevId: 737942496
2025-03-18 03:49:52 -07:00
Googler
0c78bae111 Add API to set resolution that respects orientation
This method allows a single Presentation Effect to resize portrait and landscape videos to a fixed resolution, while maintaining their orientations.

PiperOrigin-RevId: 737652909
2025-03-17 09:58:56 -07:00
tonihei
ff0a359e93 Update release notes for 1.6.0-rc02
PiperOrigin-RevId: 737624189
2025-03-17 08:30:56 -07:00
tianyifeng
42b71c29e8 Loosen the condition for seeking to sync positions in a HLS stream
Previously we only enable `SeekParameter.*_SYNC` for HLS when `EXT-X-INDEPENDENT-SEGMENTS` is set in the playlist. However, this condition can actually be loosened. To seek in HLS, we need to download the segment in which the resolved seek position locates under any circumstance. If `SeekParameter.PREVIOUS_SYNC` or `SeekParameter.CLOSEST_SYNC` is passed, and that segment happens to start with sync samples, then the seek can be done quicker with that adjusted seek position. And if that segment doesn't start with sync samples, then the behaviour will be the same as we set the adjusted seek position to the exact original position. But we still cannot safely enable `SeekParameter.NEXT_SYNC` as it will potentially cause the seeking to miss more content than seeking to the exact position.

Issue: androidx/media#2209
PiperOrigin-RevId: 737580861
2025-03-17 05:43:45 -07:00
ibaker
8837ab2564 Add support for 32-bit FLAC files in the built-in FLAC extractor
Without this, 32-bit files fail to play with `Playback stuck buffering
and not loading`. With this change, playback works on devices where the
`MediaCodec` FLAC decoder supports 32-bit, and crashes on devices with a
`MediaCodec` FLAC decoder that does not support 32-bit.

A follow-up change will aim to transform the 'unsupported' case from a
crash into a report that the track format is not supported.

32-bit support was only fully incorporated into the spec when RFC 9639
was [published in December
2024](https://xiph.org/flac/2024/12/19/rfc-9639-published.html), and
it was been supported by `libflac` (for encode and decode) [since
September 2022](https://xiph.org/flac/2022/09/09/flac-1-4-0-released.html).
The original version of this `FlacExtractor` was written before either
of these, so only supported up to 24-bit.

Issue: androidx/media#2197
PiperOrigin-RevId: 737559285
2025-03-17 04:05:09 -07:00
tonihei
d37f05238a Check language/role flags before merging adaptation sets
The spec technically allows to mark adaptation sets with the switching
property if they allow seamless switching with non-overlapping
segments. This is typically only used for compatible content (e.g.
different codecs), but the spec allows it to be used for other
content as well (e.g. different languages, roles). ExoPlayer's concept
of a TrackGroup only allows formats with the same language and role
flags to be merged, so we should check that before merging.

Issue: androidx/media#2222

#cherrypick

PiperOrigin-RevId: 736564055
2025-03-13 10:54:17 -07:00
ivanbuper
6d00fe58b5 Remove deprecated BaseAudioProcessor in exoplayer module
`BaseAudioProcessor` was moved to `common` over two years ago.

PiperOrigin-RevId: 736179562
2025-03-12 10:27:24 -07:00
ibaker
99767c6e25 Use info from unseekable Xing frame when falling back to CBR seeking
This change uses the duration and byte count of the Xing frame, if
they're present, to estimate the bitrate of the stream. The seeking
will still be inaccurate (because we're doing CBR seeking in a VBR
stream), but it will be more accurate than basing the bitrate on the
first MP3 frame we read. It will also mean the duration reported is
accurate.

This change also ensures that if the Xing frame contains the number of
audio bytes but no ToC, the audio data length is still propagated into
the `XingSeeker` (and therefore into the `ConstantBitrateSeeker` too).

Issue: androidx/media#2194
PiperOrigin-RevId: 736100104
2025-03-12 05:50:35 -07:00