14953 Commits

Author SHA1 Message Date
ibaker
1e97da9472 Enable RTL support in the demo app
We might as well keep this enabled by default, rather than having to
manually toggle it on to investigate RTL issues like Issue: androidx/media#227.

PiperOrigin-RevId: 497159744
(cherry picked from commit 010c6b96e74979370f139f8126c176ea7b279313)
2023-01-25 18:29:35 +00:00
ibaker
ee72778a42 Fix order of playback controls in RTL layout
Issue: androidx/media#227

#minor-release

PiperOrigin-RevId: 497159283
(cherry picked from commit 8313af1677507fb0cc51d53e81bf930f1a954c87)
2023-01-25 18:29:35 +00:00
rohks
9b11686ef6 Optimise bundling for AdPlaybackState using AdPlaybackState.NONE
Did not do this optimisation for `AdPlaybackState.AdGroup` as its length is zero for `AdPlaybackState` with no ads.

No need to pass default values while fetching keys, which we always set in `AdPlaybackState.AdGroup.toBundle()`.

PiperOrigin-RevId: 496995048
(cherry picked from commit f2eac2df711cad579f3042568a24c1f51a119428)
2023-01-25 18:29:35 +00:00
rohks
e4fa94abe3 Check MediaMetadata bundle to verify keys are skipped
Added another check in test to make sure we don't add keys to bundle for fields with `null` values.

PiperOrigin-RevId: 496948705
(cherry picked from commit 890fd0a9fb135e938dc465d936b24065c65dbb98)
2023-01-25 18:29:35 +00:00
bachinger
0417dbae78 Bump IMA SDK version to 3.29.0
Issue: google/ExoPlayer#10845
PiperOrigin-RevId: 496947392
(cherry picked from commit 8ed515880a0b6c05b766e868e2ef931b886925cc)
2023-01-25 18:29:35 +00:00
bachinger
a212bc9bb1 Update migration script
Issue: google/ExoPlayer#10854
PiperOrigin-RevId: 496922055
(cherry picked from commit 8e9f83867b5c9536488cf74f06c4cf2535ef848f)
2023-01-25 18:29:35 +00:00
ibaker
3cb0195c18 Fix recursive loop when registering controller visibility listeners
There are two overloads of this method due to a type 'rename' from
`PlayerControlView.VisibilityListener` to
`PlayerView.ControllerVisibilityListener`. Currently when you call one
overload it passes `null` to the other one (to clear the other listener).
Unfortunately this results in it clearing itself, because it receives
a null call back!

This change tweaks the documentation to clarify that the 'other'
listener is only cleared if you pass a non-null listener in. This solves
the recursive problem, and allows the 'legacy' visibility listener to be
successfully registered.

Issue: androidx/media#229

#minor-release

PiperOrigin-RevId: 496876397
(cherry picked from commit 37fd65a8e51ddba92584109217114d9f2c2f009d)
2023-01-25 18:29:35 +00:00
tonihei
7afdc9edae Add error messages to correctness assertions in SimpleBasePlayer
Users of this class may run into these assertions when creating the
State and they need to check the source code to understand why
the State is invalid. Adding error messages to all our correctness
assertions helps to understand the root cause more easily.

PiperOrigin-RevId: 496875109
(cherry picked from commit b7e887a58dff7615926f8002ee3210b3071c5537)
2023-01-25 18:29:35 +00:00
ibaker
de203fe084 Document the relationship between Player methods and available commands
#minor-release

PiperOrigin-RevId: 496668378
(cherry picked from commit 54e79689e925a2a18bc02522d4f7f73dcfb35d83)
2023-01-25 18:29:35 +00:00
ibaker
730f3a3a64 Clarify some Player command and method javadoc
#minor-release

PiperOrigin-RevId: 496661152
(cherry picked from commit f47ad3c2d097a557bd2222a5b104e7867aef585d)
2023-01-25 18:29:35 +00:00
ibaker
beeb6e7eed Fix Dackka error due to param name mismatch
https://developer.android.com/reference/androidx/leanback/media/PlayerAdapter#seekTo(long)

#minor-release

PiperOrigin-RevId: 496378709
(cherry picked from commit d2a3d8f6fabb6d22ac28a76379725d0915344cba)
2023-01-25 18:29:35 +00:00
ibaker
65daec3596 Remove ellipsis from Player javadoc
PiperOrigin-RevId: 496377192
(cherry picked from commit 844428ea329754118b8c0a2d58373415f539d725)
2023-01-25 18:29:35 +00:00
tonihei
2c17c6ef04 Add playlist and seek operations to SimpleBasePlayer
These are the remaining setter operations. They all share the same
logic that handles playlist and/or position changes. The logic to
create the placeholder state is mostly copied from ExoPlayerImpl's
maskTimelineAndPosition and getPeriodPositonUsAfterTimelineChanged.

PiperOrigin-RevId: 496364712
(cherry picked from commit 09d37641d1ef3b8cf26dc39cfcd317ebe3ef5c79)
2023-01-25 18:29:35 +00:00
tonihei
0ab7c752d7 Check if codec still exists before handling tunneling events
The tunneling callbacks are sent via Handler messages and may be
handled after the codec/surface was changed or released.

We already guard against the codec/surface change condition by
creating a new listener and verifying that the current callback
happens for the correct listener instance, but we don't guard
against a released codec yet.

PiperOrigin-RevId: 495882353
(cherry picked from commit 5e23b8bfd5a9a9542c2ab8d23ae51c1689d8ff51)
2023-01-25 18:29:34 +00:00
tonihei
f1784862e0 Clarify behavior for out-of-bounds indices and align implementations
Some Player methods operate relative to existing indices in the
playlist (add,remove,move,seek). As these operations may be issued
from a place with a stale playlist (e.g. a controller that sends
a command while the playlist is changing), we have to handle out-
of-bounds indices gracefully. In most cases this is already
documented and implemented correctly. However, some cases are not
documented and the existing player implementations don't handle
these cases consistently (or in some cases not even correctly).

PiperOrigin-RevId: 495856295
(cherry picked from commit a1c0b10482baffc3721561446ee4bb788d8a1231)
2023-01-25 18:29:34 +00:00
rohks
4b7a005340 Rename EMPTY_MEDIA_ITEM to PLACEHOLDER_MEDIA_ITEM
The `MediaItem` instances in the following cases are not actually empty but acts as a placeholder. `EMPTY_MEDIA_ITEM` can also be confused with `MediaItem.EMPTY`.

PiperOrigin-RevId: 495843012
(cherry picked from commit 74559b4a188e476378f3f0df908598ce763d909a)
2023-01-25 18:29:34 +00:00
bachinger
5ff90692b6 Use theme when loading drawables on API 21+
Issue: androidx/media#220
PiperOrigin-RevId: 495642588
(cherry picked from commit 33f8f406929c739e98bbea475b3609beb7db2b5f)
2023-01-25 18:29:34 +00:00
rohks
b9fd7fd431 Remove parameters with null values from bundle in MediaMetadata
Improves the time taken to construct `playerInfo` from its bundle from ~450 ms to ~400 ms. Each `MediaItem` inside `Timeline.Window` contains `MediaMetadata` and hence is a good candidate for bundling optimisations. There already exists a test to check all parameters for null values when unset.

PiperOrigin-RevId: 495614719
(cherry picked from commit 8dea624c980ff65aece63c6aeecdeef894470231)
2023-01-25 18:29:34 +00:00
tonihei
8e2692dc9c Allow unset index and position values + remove period index
This simplifies some position tracking needs for an app implementing
SimpleBasePlayer.
 - The period index can always be derived from the media item index
   and the position. So there is no need to set it separately.
 - The media item index can be left unset in the State in case the app
   doesn't care about the value or wants to set it the default start
   index (e.g. while the playlist is still empty where UNSET is
   different from zero).
 - Similarly, we should allow to set the content position (and buffered
   position) to C.TIME_UNSET to let the app ignore it or indicate the
   default position explictly.

PiperOrigin-RevId: 495352633
(cherry picked from commit 91557ac9d4eaf83e68f563373541dc8e12043e00)
2023-01-25 18:29:34 +00:00
tonihei
0e921d1a7a Clear one-off events from state as soon as they are triggered.
This ensures they are not accidentally triggered again when
the state is rebuilt with a buildUpon method.

PiperOrigin-RevId: 495280711
(cherry picked from commit fa5aaf958d616d831d50fdaceb02d3ff3cbad0fa)
2023-01-25 18:29:34 +00:00
rohks
951fea231d Remove parameters with default values from bundle in MediaItem
This improves the time taken to construct PlayerInfo from bundle from ~600ms to ~450ms.

PiperOrigin-RevId: 495055355
(cherry picked from commit 7de47fe2a1493da1b0720ddeb357052d2b1dc5bb)
2023-01-25 18:29:34 +00:00
rohks
aa2158d5c8 Document the reason for defining private method defaultIfNull
PiperOrigin-RevId: 495004732
(cherry picked from commit c3ca71fda738772dccc5a5e07293c884d2194f0a)
2023-01-25 18:29:34 +00:00
tonihei
47b811e3b9 Reset isLoading when calling SimpleBasePlayer.stop/release
isLoading is not allowed to be true when IDLE, so we have to set to
false when stopping in case it was set to true before.

PiperOrigin-RevId: 494975405
(cherry picked from commit e4f0b73aa325d096b493bd646c63bc6a4bf5880b)
2023-01-25 18:29:34 +00:00
tonihei
b9365f5563 Forward seek command details to seekTo method in BasePlayer
BasePlayer simplifies implementations by handling all the various
seek methods and forwarding to a single method that can then be
implemented by subclasses. However, this loses the information about
the concrete entry point used for seeking, which is relevant when
the subclass wants to verify or filter by Player.Command. This
can be improved by adding the command as a new parameter. Since
we have to change the method anyway, we can also incorporate the
boolean flag about whether the current item is repeated to avoid
the separate method.

PiperOrigin-RevId: 494948094
(cherry picked from commit 6e0f1f10b3666e6c2c74fc5a154dec3f0e03fecb)
2023-01-25 18:29:34 +00:00
tonihei
3dfbfd3f05 Clarify and correct allowed multi-threading for some Player methods
Some Player methods like getting the Looper and adding listeners
were always allowed to be called from any thread, but this is
undocumented. This change makes the threading rules of these
methods more explicit.

Removing listeners was never meant to be called from another thread
and we also don't support it safely because final callbacks may
be triggered from the wrong thread. To find potential issues, we
can assert the correct thread when releasing listeners.

Finally, there is a potential race condition when calling addListener
from a different thread at the same time as release, which may lead to
a registered listener that could receive callbacks after the player is
released.

PiperOrigin-RevId: 493843981
(cherry picked from commit e9364b0f6e1a104de9cf4393daab521edc4eccf4)
2023-01-25 18:29:34 +00:00
tonihei
45664162d9 Remove debug timeout multiplier.
It looks like this was added accidentally in <unknown commit>.

PiperOrigin-RevId: 493834134
(cherry picked from commit f8e4e1765f3bc956e1e6e9eb17d72cb6c152282c)
2023-01-25 18:29:34 +00:00
tonihei
a599289bdc Replace MediaMetadata folderType by isBrowsable
The folder type has a mix of information about the item. It shows
whether the item is browsable (type != FOLDER_TYPE_NONE) and
which Bluetooth folder type to set for legacy session information.

It's a lot clearer to split this into a boolean isBrowsable and
use the existing mediaType to map back to the bluetooth folder type
where required.

folderType is not marked as deprecated yet as this would be an API
change, which will be done later.

PiperOrigin-RevId: 493544589
(cherry picked from commit 9d059352cff0a75f0f9c4e37010bbfa2fc6079fd)
2023-01-25 18:29:34 +00:00
tonihei
a65d9e956d Support release in SimpleBasePlayer
This adds support for the release handling. To align with the
established behavior in ExoPlayer, the player can only call
listeners from within the release methods (and not afterwards)
and automatically enforces an IDLE state (without listener call)
in case getters of the player are used after release.

PiperOrigin-RevId: 493543958
(cherry picked from commit 3a66c28d4f0fc6bbd7af3f5846a5645aa3ccf778)
2023-01-25 18:29:34 +00:00
ibaker
d2d45dbe17 Add javadoc links to README files
Fix some other link titles and destinations spotted along the way.

#minor-release

PiperOrigin-RevId: 493276172
(cherry picked from commit c006575d4306f9bfad9c6f27d964fab00a6e1718)
2023-01-25 18:29:34 +00:00
tonihei
5fd6ce5e2e Fix threading of onFallbackApplied callback
The callback is currently triggered on the ExoPlayer playback thread
instead of the app thread that added the listener.

PiperOrigin-RevId: 492474405
(cherry picked from commit f3fc4fb9735a4b67a3740b3796495017eb5c978c)
2023-01-25 18:29:03 +00:00
ibaker
fec7b1b575 Fix ExoPlayerTest to use C.TIME_UNSET instead of C.POSITION_UNSET
This inconsistency was exposed by an upcoming change to deprecate
`POSITION_UNSET` in favour of `INDEX_UNSET` because position is an
ambiguous term between 'byte offset' and 'media position', as shown
here.

PiperOrigin-RevId: 492470241
(cherry picked from commit 2f8cf947c71db6be9459492117fe95b1a8bc7178)
2023-01-25 17:39:48 +00:00
ibaker
e342b70e93 Fix TextRenderer exception when a subtitle file contains no cues
Discovered while investigating Issue: google/ExoPlayer#10823

Example stack trace with the previous code (I added the index value for
debugging):

```
playerFailed [eventTime=44.07, mediaPos=44.01, window=0, period=0, errorCode=ERROR_CODE_FAILED_RUNTIME_CHECK
  androidx.media3.exoplayer.ExoPlaybackException: Unexpected runtime error
      at androidx.media3.exoplayer.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:635)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loopOnce(Looper.java:202)
      at android.os.Looper.loop(Looper.java:291)
      at android.os.HandlerThread.run(HandlerThread.java:67)
  Caused by: java.lang.IllegalArgumentException: index=-1
      at androidx.media3.common.util.Assertions.checkArgument(Assertions.java:55)
      at androidx.media3.extractor.text.webvtt.WebvttSubtitle.getEventTime(WebvttSubtitle.java:62)
      at androidx.media3.extractor.text.SubtitleOutputBuffer.getEventTime(SubtitleOutputBuffer.java:56)
      at androidx.media3.exoplayer.text.TextRenderer.getCurrentEventTimeUs(TextRenderer.java:435)
      at androidx.media3.exoplayer.text.TextRenderer.render(TextRenderer.java:268)
      at androidx.media3.exoplayer.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:1008)
      at androidx.media3.exoplayer.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:509)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loopOnce(Looper.java:202)
      at android.os.Looper.loop(Looper.java:291)
      at android.os.HandlerThread.run(HandlerThread.java:67)
]
```

#minor-release

PiperOrigin-RevId: 492464180
(cherry picked from commit 5f6fde4d2a90d78a8d58430c88d7dc12849fe163)
2023-01-25 17:39:48 +00:00
michaelkatz
d0691aad6d Removed ExoPlayer specific states from SimpleBasePlayer
PiperOrigin-RevId: 492443147
(cherry picked from commit 08f6fe172732f8a3327746f249888368c39265bc)
2023-01-25 17:39:48 +00:00
ibaker
05151bafd0 Split SubripDecoder and ParsableByteArray tests
In some cases we split a test method, and in other cases we just add
line breaks to make the separation between arrange/act/assert more
clear.

PiperOrigin-RevId: 492182769
(cherry picked from commit 02fa8aa784b518f0ffad5c44da6eec1a94def4ee)
2023-01-25 17:39:48 +00:00
Ian Baker
eb51ad57f9 Merge pull request #10750 from Stronger197:subrip_utf_16
PiperOrigin-RevId: 492164739
(cherry picked from commit 496cfa420d7dd23fb5913c9ecf7b0b1e04cc65ff)
2023-01-25 17:39:48 +00:00
tonihei
2bfced9bbc Add support for most setters in SimpleBasePlayer
This adds the forwarding logic for most setters in SimpleExoPlayer
in the same style as the existing logic for setPlayWhenReady.

This change doesn't implement the setters for modifying media items,
seeking and releasing yet as they require additional handling that
goes beyond the repeated implementation pattern in this change.

PiperOrigin-RevId: 492124399
(cherry picked from commit e598a17b3628e1179fa4219ca3212407fb3fdeb1)
2023-01-25 17:39:48 +00:00
tonihei
8ec46cd4dc Add media type to MediaMetadata
This helps to denote what type of content or folder the metadata
describes.

PiperOrigin-RevId: 492123690
(cherry picked from commit 1ac72de551a07d37c3b80d96028463244407a5b4)
2023-01-25 17:39:48 +00:00
rohks
8246587b00 Parse and set bitrates in Ac3Reader
PiperOrigin-RevId: 492003800
(cherry picked from commit 5f73984823b943d750f41519d431ad3b12dada65)
2023-01-25 17:39:48 +00:00
tonihei
2921cb76c5 Rename SimpleBasePlayer.PlaylistItem to MediaItemData
This better matches the terminology we use elsewhere in the Player
interface, where items inside the playlist are referred to as
"media item" and only the entire list is called "playlist".

PiperOrigin-RevId: 491882849
(cherry picked from commit 6c467590d0fdc27dd5afeefe479c3d4414483de5)
2023-01-25 17:39:48 +00:00
christosts
d7923785a7 Use audio bitrate to calculate AudioTrack min buffer in passthrough
Use the bitrate of the audio format (when available) in
DefaultAudioSink.AudioTrackBufferSizeProvider.getBufferSizeInBytes() to
calculate accurate buffer sizes for direct (passthrough) playbacks.

#minor-release

PiperOrigin-RevId: 491628530
(cherry picked from commit e219ac21ae604f182769d69f6f590191a92100d0)
2023-01-25 17:39:48 +00:00
tonihei
b6477ddddd Add configuration to support OPUS offload
To support OPUS offload, we need to provide a few configuration values
that are currently not set due to the lack of devices supporting
OPUS offload.

PiperOrigin-RevId: 491613716
(cherry picked from commit 4cf877b81428021c4eb2dfa1a743178f280aceb5)
2023-01-25 17:39:48 +00:00
bachinger
69ded0f28c Bump cast sdk version and remove workaround for live duration
The fix for b/171657375 (internal) has been shipped with 21.1.0 already (see https://developers.google.com/cast/docs/release-notes#august-8,-2022).

PiperOrigin-RevId: 491583727
(cherry picked from commit 04f031d16805a6d6786d135f77d0f6e79c77c8f7)
2023-01-25 17:39:48 +00:00
Rohit Singh
44d12a5070 Merge pull request #10776 from dongvanhung:feature/add_support_clear_download_manager_helpers
PiperOrigin-RevId: 491336828
(cherry picked from commit 3a7f940f41e278cde88c29201191229ed7d39e49)
2023-01-25 17:39:48 +00:00
ibaker
70a55ef7e9 Remove impossible UnsupportedEncodingException from Id3Decoder
The list of charsets is already hard-coded, and using `Charset` types
ensures they will all be present at run-time, hence we will never
encounter an 'unsupported' charset.

PiperOrigin-RevId: 491324466
(cherry picked from commit 043546a03475356764cf8b754bd0fff87a0c6e1a)
2023-01-25 17:39:48 +00:00
ibaker
50e686ea58 Split up Id3DecoderTest methods
It's clearer if each test method follows the Arrange/Act/Assert pattern

PiperOrigin-RevId: 491299379
(cherry picked from commit bf77290fbe78aa25698c1a7082b2a18cd7f1b06c)
2023-01-25 17:39:48 +00:00
Rohit Singh
cbc2547043 Merge pull request #10799 from OxygenCobalt:id3v2-multi-value
PiperOrigin-RevId: 491289028
(cherry picked from commit c827e46c3db2691b1b5fed57fa5b67890331aa85)
2023-01-25 17:39:48 +00:00
tonihei
83b7f8085c Ensure messages sent on a dead thread don't block FakeClock execution
FakeClock keeps an internal list of messages to be executed to
ensure deterministic serialization. The next message from the list
is triggered by a separate helper message sent to the real Handler.
However, if the target HandlerThread is no longer alive (e.g. when
it quit itself during the message execution), this helper
message is never executed and the entire message execution chain
is stuck forever.

This can be solved by checking the return values of Hander.post or
Handler.sendMessage, which are false if the message won't be
delivered. If the messages are not delivered, we can unblock the
chain by marking the message as complete and triggering the next
one.

PiperOrigin-RevId: 491275031
(cherry picked from commit 2977bef872d7f3a1611fd6e8a45931388ea21c9f)
2023-01-25 17:39:47 +00:00
ibaker
a68ab5f334 Clean up javadoc on Metadata.Entry.populateMediaMetadata
Remove self-links, and remove section that is documenting internal
ordering behaviour of
[`SimpleBasePlayer.getCombinedMediaMetadata`](bb270c62cf/library/common/src/main/java/com/google/android/exoplayer2/SimpleBasePlayer.java (L1770))
rather than anything specifically about this method.

#minor-release

PiperOrigin-RevId: 490923719
(cherry picked from commit ed8c196e2eb36eefef9952d255cb6355807b9e9f)
2023-01-25 17:39:47 +00:00
tonihei
0fb501ed6d Remove flakiness from DefaultAnalyticsCollectorTest
Our FakeClock generally makes sure that playback tests are fully
deterministic. However, this fails if the test uses blocking waits
with clock.onThreadBlocked and where relevant Handlers are created
without using the clock.

To fix the flakiness, we can make the following adjustments:
 - Use TestExoPlayerBuilder instead of legacy ExoPlayerTestRunner
   to avoid onThreadBlocked calls. This also makes the tests more
   readable.
 - Use clock to create Handler for FakeVideoRenderer and
   FakeAudioRenderer. Ideally, this should be passed through
   RenderersFactory, but it's too disruptive given this is a
   public API.
 - Use clock for MediaSourceList and MediaPeriodQueue update
   handler.

PiperOrigin-RevId: 490907495
(cherry picked from commit 7d62943bcd149eecce77cb44e4f867128ca374d3)
2023-01-25 17:39:47 +00:00
rohks
7e733aa2df Convert bitrates to bps before setting it
Format expects the values of `averageBitrate` and `peakBitrate` in bps and the value fetched from AC3SpecificBox and EC3SpecificBox is in kbps.

PiperOrigin-RevId: 490756581
(cherry picked from commit 67955e0ce331481bcb3fd94c9ffb9632f27eae6e)
2023-01-25 17:39:47 +00:00