429 Commits

Author SHA1 Message Date
ibaker
2c7f2686b7 Remove stray parenthesis from MediaSession.ControllerInfo.toString()
#cherrypick

PiperOrigin-RevId: 651760391
2024-07-12 06:58:33 -07:00
ibaker
c64dacf3df Transform double-tap of HEADSETHOOK to skip-to-next
As reported in Issue: androidx/media#1493 we already use `HEADSETHOOK` to start
waiting for a double-tap, but we don't consider it for the second tap.

Similarly, we previously considered `PLAY` for the second tap, but not the first.
Only `HEADSETHOOK` and `PLAY_PAUSE` are
[documented](https://developer.android.com/reference/androidx/media3/session/MediaSession#media-key-events-mapping)
to transform double-tap to `seekToNext`. So this change removes the
`PLAY` detection from the second tap.

#cherrypick

PiperOrigin-RevId: 651017522
2024-07-10 07:52:18 -07:00
bachinger
06d61ffaaa Allow an app to decide to not start the service
Once a service is started as a foreground service, it must
be started into the foreground. This means an app can not
suppress a play command arriving from the `MediaButtonReceiver`
once the receiver has started the service.

This change adds a method to the `MediaButtonReceiver` that
allows app to suppress starting the service to not get into
this situation of wanting to suppress the play command after
the service is already started.

Issue: androidx/media#1528
PiperOrigin-RevId: 650280025
2024-07-08 09:44:30 -07:00
bachinger
70c063905c Improve automatic error replication for legacy browsers
This change extends the error replication to a given set of
error codes (not only authentication error), but only
replicates an error if the caller of the service `Callback`
is a legacy controller. It also makes error replication
configurable so that apps can opt-out and report errors
manually instead, or define the error codes for which
replication is enabled.

The change also removes the restriction of `sendError` only
being available for Media3 controllers. Instead, sending an
error to a legacy controller updates the platform playback
state in the same way as sending the error to the media
notification controller.

#cherrypick

PiperOrigin-RevId: 648399237
2024-07-01 09:47:25 -07:00
tianyifeng
6bf2461f80 Update translations
#cherrypick

PiperOrigin-RevId: 648385733
2024-07-01 09:02:21 -07:00
ktrajkovski
e4d4a776c3 Remove deprecated hasPreviousWindow() and hasPrevious() methods.
Use Player.hasPreviousMediaItem() and Player.seekToPreviousMediaItem() instead.

PiperOrigin-RevId: 647664991
2024-06-28 07:02:33 -07:00
ktrajkovski
47b1ca18ed Remove deprecated Player#hasPrevious() method.
Use Player#hasPreviousMediaItem() instead.

#cherrypick

PiperOrigin-RevId: 647336042
2024-06-27 09:04:21 -07:00
tonihei
1d26d1891e Clarify that onPlayWhenReadyChanged can be called again with new reason
Sometimes the reason for the current state may change. If we don't
report this again, users have no way of knowing that the reason
changed.

Also adjust ExoPlayerImpl and MediaControllerImplBase accordingly.
SimpleBasePlayer already adheres to this logic.

#cherrypick

PiperOrigin-RevId: 644970236
2024-06-20 03:58:05 -07:00
bachinger
6cc6444dd9 Use a localized fallback message for known error codes
In the case of a legacy session app providing an error
code different to `ERROR_UNKNOWN` without an error
message, a localized fallback message is provided
instead of ignoring the error.

#cherrypick

PiperOrigin-RevId: 644704680
2024-06-19 04:28:20 -07:00
bachinger
856d394c28 Allow session activity to be set per controller
#cherrypick

PiperOrigin-RevId: 644693533
2024-06-19 03:37:02 -07:00
kimvde
d27549d29a Skip 4K export test on Pixel 3a
PiperOrigin-RevId: 644659699
2024-06-19 01:18:05 -07:00
tonihei
cd2250b5fa Formatting fixes and additional plumbin in legacy controller 2024-06-14 17:47:03 +01:00
Gaëtan Muller
63103978be Make MediaControllerImplLegacy.getMaxSeekToPreviousPosition() return the correct value 2024-06-14 16:21:31 +01:00
bachinger
011ed909c0 Sync and map fatal and non-fatal errors from and to the legacy session
A fatal `PlaybackException` is mapped to a legacy playback state
in state `STATE_ERROR` with error code, message and extras. A
non-fatal error sent to controllers with `MediaSession.sendError`
is synced to the legacy session by setting error code and message
and merging the extras while preserving the rest of the state in
sync with the session player.

Vice versa, a `MediaController` connected to a legacy session receives
fatal errors through `Player.onPlayerErrorChanged()` and non-fatal errors
through `MediaController.Listener.onError()`.

Error codes are mapped in `LegacyConversions`. Values of error codes
in `@SessionError.ErrorCode` come from `@PlaybackExceptino.ErrorCode`
with the exception of `@SessionError.ERROR_IO` and
`@SessionError.ERROR_UNKNOWN`. These already exist in
`@PlaybackException.ErrorCode` and are mapped accordingly to avoid
semantic duplicates.

PiperOrigin-RevId: 642595517
2024-06-12 06:26:00 -07:00
ibaker
2456669398 Propagate media3 session extras to media1 PlaybackStateCompat
PiperOrigin-RevId: 642299178
2024-06-11 09:44:22 -07:00
ibaker
b145a96c79 Clean up unecessary zero-arg toBundle() methods
These are no longer needed now that the `Bundleable` interface has been
removed. Public methods are deprecated, package-private ones are
removed. Callers are migrated in both cases (except where tests
explicitly exist for the deprecated method).

PiperOrigin-RevId: 642294451
2024-06-11 09:28:23 -07:00
ibaker
f554c12099 Remove Bundleable type & Bundleable.Creator<Foo> CREATOR fields
This interface is not used in the library. Callers can use the
`Bundle toBundle()` and `static Foo fromBundle(Bundle)` methods
defined directly on each type instead.

PiperOrigin-RevId: 642271609
2024-06-11 08:05:32 -07:00
bachinger
efff1ee2f1 Add SessionError and use it in service results
This change adds `SessionError` and uses it in `SessionResult`
and `LibraryResult` to report errors to callers.

Constructors and factory method that used a simple `errorCode` to
construct error variants of `SessionResult` and `LibraryResult`
have been overloaded with a variant that uses a `SessionError`
instead. While these methods and constructors are supposed to be
deprecated, they aren't yet deprecated until the newly added
alternative is stabilized.

PiperOrigin-RevId: 642254336
2024-06-11 06:53:42 -07:00
tonihei
acb6a89ff6 Add MediaSession.Callback.onPlayerInteractionFinished
This callback is useful for advanced use cases that care about
which Player calls are batched together. It can be implemented
by triggering this new callback every time a batch of Player
interactions from a controller finished executing.

PiperOrigin-RevId: 642189491
2024-06-11 02:15:20 -07:00
ibaker
b1c6d9ff04 Mark PlayerWrapper as final
This package-private class isn't currently extended, so this change
makes it not possible to be extended in future.

PiperOrigin-RevId: 641270464
2024-06-07 09:23:56 -07:00
tonihei
9547828468 Add missing null check
PiperOrigin-RevId: 640555113
2024-06-05 09:45:28 -07:00
michaelkatz
0ed08a5204 Import string translations for session module
#minor-release

PiperOrigin-RevId: 638224207
2024-05-29 03:39:07 -07:00
tonihei
08006651fa Update session module registration
PiperOrigin-RevId: 636482934
2024-05-23 03:11:51 -07:00
tonihei
fb7cf154de Make getIconResIdForIconConstant public
This allows controller apps to map these constants to suitable
icons without creating a CommandButton instance first.

PiperOrigin-RevId: 636096841
2024-05-22 03:03:03 -07:00
ibaker
ed4820cb61 Remove @UnstableApi from package-private files
This annotation is only needed on public classes.

This change also removes the `/* package */` comment from some `public`
classes.

PiperOrigin-RevId: 633864544
2024-05-15 02:26:55 -07:00
bachinger
bf7b4e0d8c Reset platform playback state immediately after sending custom error
This change resets the error in the platform error state immediately
to make sure that the custom error is reflected only very briefly
and then gets back to the playback state that actually reflects the
player state.

Issue: androidx/media#543
PiperOrigin-RevId: 633626180
2024-05-14 10:18:59 -07:00
bachinger
84c0b6bcb1 Add MediaSession.sendError to send non-fatal error data to controllers
This allows to set custom error message for instance on Android
Auto/Automotive OS.

Issue: androidx/media#543
PiperOrigin-RevId: 633610089
2024-05-14 09:30:18 -07:00
bachinger
2c912aa697 Handle displayTitle and title in legacy conversions
When converting `MediaMetadata` to the legacy `MediaDescriptionCompat`
the selection and order of properties to use has been aligned with the
behavior of media1. This selection is relevant for users that use a
platform or legacy controller or browser. Before and up to the current
API version 34, this includes System UI, Android Auto/Automotive and
AVRCP (Bluetooth).

PiperOrigin-RevId: 630999535
2024-05-06 04:21:19 -07:00
bachinger
0e3b05c67d Add metadata field durationMs
PiperOrigin-RevId: 628038241
2024-04-25 05:05:42 -07:00
tonihei
d0d6ce52a5 Import androidx.media
This imports all the classes and resources needed by our code.

We still have the nominal dependency on the artifact as we need
to access the Parcelable CREATORs of MediaSessionCompat.Token,
MediaDescriptionCompat, RatingCompat and MediaBrowserCompat.MediaItem.

Mechanical import steps:
 - Put all files under a new 'legacy' package and change all import
   statements accordingly.
 - Reformat to adhere to Media3 java style guide
 - Remove all existing @RestrictTo annotations and replace them with
   top-level @RestrictTo(LIBRARY) on all classes in the new package.
 - Remove @NonNull annotations and fixed nullability test errors
 - Fix HTML javadoc build errors
 - Fix Lint errors (but not warnings)

The code still contains many lint warnings that will be fixed
separately.

PiperOrigin-RevId: 627999285
2024-04-25 01:56:23 -07:00
bachinger
4091303c7e Read device volume directly from binder with legacy session
PiperOrigin-RevId: 627328652
2024-04-23 03:31:33 -07:00
tonihei
e1c62df256 Remove media1 public API dependencies from session module
This is the preparation to import the media1 classes as
private copies into media3.

- Reword Javadoc to use @code instead of @link to media1 types. This
  avoids accidentally linking to the future internal types.
- Use fully qualified names for the converter methods to and from
  MediaSessionCompat.Token to ensure they keep the publicly available
  type.
- Add new public variable that is directly referenced from our code
  instead of referring the the media1 equivalent.
- Clean up tests that are using media1 types to make assertions on
  media3 fields and vice versa (mostly when using LegacyConversions
  in the test method). This also makes the tests more DAMP than DRY.
  (also moved LegacyConversionsTest to a unit test as it doesn't test
  cross-process communication)

PiperOrigin-RevId: 626000082
2024-04-18 05:33:10 -07:00
bachinger
fc1d60beb9 Do not set a duration for live streams
A live window with changing duration can't be properly
displayed in a media notification. The duration constantly
changes and creates a nervous jumping seekbar that is not
really useful.

This change sets the duration for live streams to `C.TIME_UNSET`
when publishing the player state to the platform session. This
way no duration is sent to the platform session which prevents
media controls from drawing a seekbar.

Issue: androidx/media#1256
PiperOrigin-RevId: 624112541
2024-04-12 03:14:41 -07:00
bachinger
617f9898c3 Add isPlaybackOngoing and stopMediaSessionService
This API additions help an app to implement the lifecycle of a MediaSessionService
properly and in consistency with the `MediaSessionService` being in the foreground
or not.

Not properly implementing `onTaskRemoved` is the main reason for crashes and
confusion. This change provides `MediaSessionService` with a default
implementation that avoids crashes of the service. This default implementation
uses the new API provided with this change just as an app can do.

Issue: androidx/media#1219
PiperOrigin-RevId: 621874838
2024-04-04 09:01:55 -07:00
tonihei
6e66885311 Add additional queue add/remove/next icons
PiperOrigin-RevId: 621529526
2024-04-03 08:26:11 -07:00
tofunmi
ef2314c404 Move bitmap decoding out of datasource util
PiperOrigin-RevId: 619139208
2024-03-26 04:10:38 -07:00
ibaker
fd268eed46 Remove unecessary re-setting of group from session Gradle files
These TODOs precede <unknown commit> when the group was set in the top-level
`build.gradle` file.

Issue: androidx/media#1215
PiperOrigin-RevId: 618835040
2024-03-25 07:33:05 -07:00
tonihei
87f4a3ca71 Add some clarifications around CommandButton.iconUri to Javadoc
PiperOrigin-RevId: 616775044
2024-03-18 03:43:36 -07:00
tonihei
0e42c8945f Automatically add icon drawables for icon constants
Having a default icon available allows apps to only specify the
icon constant without having to define an icon drawable themselves
as Media3 can fill in the icon resource for backwards compatibility.

The switch util method allows R8 to easily remove unused icons, so
having default icons won't affect APK size unless the constants are
used to set up the CommandButtons.

PiperOrigin-RevId: 614623909
2024-03-11 05:06:21 -07:00
tonihei
9abe9e2a97 Refine auto-update logic of CommandButton.isEnabled
We currently update this value for controllers to match the
availability of the associated command. This however makes it
impossible to mark a button as unavailable if the command is
available. This can be refined by only setting the 'enabled'
field to false if the command is not available, not the other
way round. And we should also enable the button by default as
disabling is the unusual case not many apps will use.

In addition, this change fixes missing update logic when the
player commands changed and it adds some additional test coverage
for all these cases.

PiperOrigin-RevId: 612881016
2024-03-05 10:08:17 -08:00
tonihei
8b59888766 Add missing icon constants for repeat/shuffle off
PiperOrigin-RevId: 612858065
2024-03-05 08:56:57 -08:00
ibaker
3a43bd7687 Fix some invalid javadoc references caught by a new JDK version
PiperOrigin-RevId: 612808322
2024-03-05 05:48:34 -08:00
tonihei
c79ac5ba21 Remove invalid command comparison
The removed check searched for a player command inside a list of
session commands, which is not allowed by the IntDef definition
and only worked because both types map to a Java int.

PiperOrigin-RevId: 612758442
2024-03-05 02:20:18 -08:00
tianyifeng
1bdc58de0b Avoid position jumping back when controller replaces the current item
When the controller replaces the current item, the masking position will be changed to the default position of the new item for a short while, before the correct position comes from the session. This will interrupt the current position fetched from the controller when the playback doesn't interrupted by the item replacing.

Issue: androidx/media#951

#minor-release

PiperOrigin-RevId: 611417539
2024-02-29 04:07:17 -08:00
Copybara-Service
fb7438378d Merge pull request #983 from MGaetan89:min_api_19
PiperOrigin-RevId: 607319987
2024-02-15 07:00:17 -08:00
bachinger
89571c0a92 Check whether the session activity pending intent is an activity
PiperOrigin-RevId: 606613694
2024-02-13 07:28:31 -08:00
Gaëtan Muller
973b717914 Remove unnecessary SDK_INT checks 2024-02-13 10:26:19 +00:00
tonihei
adc23e8e8b Add icon constants to CommandButton
These allow to set the icon in a standardized way without needing
custom bitmaps or resources. For now, this is just additional
information without backwards-compatible icons or implications.

The same value gets written to the platform session via a new
extras key that can be read and set from sessions not using Media3
yet.

PiperOrigin-RevId: 605670988
2024-02-09 10:37:12 -08:00
bachinger
c2273345c5 Add constructor that takes only a Context
#minor-release

PiperOrigin-RevId: 604659845
2024-02-06 08:47:03 -08:00
tonihei
ed5b7004b4 Replace or suppress deprecated usages
Many usages are needed to support other deprecations and some
can be replaced by the recommended direct alternative.

Also replace links to deprecated/redirected dev site

PiperOrigin-RevId: 601795998
2024-01-26 10:06:18 -08:00