365 Commits

Author SHA1 Message Date
bachinger
291c95daa0 Accept page index 0 for getChildren() in MediaLibraryServiceLegacyStub
This is consistent with the new MediaSessionStub that accepts page index 0
and the JavaDoc of legacy and new service callbacks.

Issue: androidx/media#32
PiperOrigin-RevId: 431390454
(cherry picked from commit 9821dd282c05dde945d787b8c1d4259fbc22bfef)
2022-03-08 16:58:05 +00:00
christosts
1023b9d55e Start playback from notification
This change fixes two bugs where MediaSessionServe shows a notification
with the Play icon but tapping it will not start playback:
1. After playback ends: we need to seek to the beginning of the media
   item.
2. After adding media items to the player but not starting playback:
   We need to call Player.prepare() too.

PiperOrigin-RevId: 432469953
2022-03-04 17:52:46 +00:00
bachinger
88cedf010c Avoid NPE in onStartCommand when action factory isn't instantiated
PiperOrigin-RevId: 431969914
2022-03-03 12:15:34 +00:00
bachinger
9821dd282c Accept page index 0 for getChildren() in MediaLibraryServiceLegacyStub
This is consistent with the new MediaSessionStub that accepts page index 0
and the JavaDoc of legacy and new service callbacks.

Issue: androidx/media#32
PiperOrigin-RevId: 431390454
2022-03-01 09:43:55 +00:00
olly
bdc3af1416 Remove deprecated Player track methods
getCurrentTrackGroups and getCurrentTrackSelections are
retained for now, but moved from Player to ExoPlayer, to
ease the transition for some application code that currently
uses these methods.

PiperOrigin-RevId: 430036355
2022-02-22 10:35:04 +00:00
bachinger
bb7ee69870 Use service context in DefaultActionFactory
We need to use a Service to create the pending intents in the
`DefaultActionFactory`.

PiperOrigin-RevId: 429115746
2022-02-22 10:25:07 +00:00
christosts
71f21ccfa6 Create MediaNotification.Provider
Define MediaNotification.Provider so that apps can customize
notification UX. Move MediaNotificationManager's functionality
around notifications on DefaultMediaNotificationProvider

PiperOrigin-RevId: 428024699
2022-02-21 17:11:38 +00:00
tonihei
5896ec7b1c Update some text descriptions to ease translations.
Some strings didn't mention the context in which they are used
(for example as item in a list, or for accessibility). This makes it
harder for translators to choose the most appropriate translation and
grammar.

Also fix repeat and shuffle mode button accessibility descriptions to
indicate the action, not the current state.

PiperOrigin-RevId: 426924163
2022-02-21 17:04:07 +00:00
olly
be8f8776d4 Update final translations
PiperOrigin-RevId: 426870226
2022-02-21 16:56:37 +00:00
ibaker
8b8675331e Mark all public 'rarely used' IntDefs as only TYPE_USE
This is a breaking change if the annotation itself is in use in Kotlin
code. It's judged that the IntDefs in this commit are unlikely to be
referred to often in Kotlin code. This is because they're either:
- Related to esoteric parts of the library, or
- In a common part of the library but only returned from methods (and
  never passed to callback methods).

A follow-up change will fix the positions of existing usages to match
this new config.

#minor-release

PiperOrigin-RevId: 426410237
2022-02-21 16:56:37 +00:00
ibaker
31bc6d4909 Mark all non-public IntDefs as only TYPE_USE
This only changes IntDefs that cannot be used by apps because they're
either private or package-private.

A follow-up change will fix the positions of existing usages to match
this new config.

#minor-release

PiperOrigin-RevId: 426372273
2022-02-21 16:56:36 +00:00
ibaker
4621cedcd0 Mark some unreleased IntDefs as TYPE_USE only
The longer list of targets is only necessary for backwards
compatibility with existing Kotlin code that will stop compiling
if the position of the annotation becomes 'wrong' by marking it only
TYPE_USE. Since none of these IntDefs have been released (except in
media3 alpha1) we don't need to maintain this compatibility.

Also add a comment to all the places that *do* need the longer list of
targets, in order to explain why it's there and discourage copy-pasting
when defining new IntDefs in future.

Also fix some single-element arrays to remove the array notation.

#minor-release

PiperOrigin-RevId: 426108537
2022-02-21 16:56:36 +00:00
olly
8cdcb96c64 Update session translations
PiperOrigin-RevId: 425589473
2022-02-21 16:36:49 +00:00
bachinger
15995d3dc5 Use service context in DefaultActionFactory
We need to use a Service to create the pending intents in the
`DefaultActionFactory`.

PiperOrigin-RevId: 429115746
2022-02-17 11:52:24 +00:00
christosts
b59869ede3 Create BitmapLoader
Create BitmapLoader component for loading artwork
images. Add the SimpleBitmapLoader which fetches images
from HTTP/HTTPS endpoints. Integrate BitmapLoader in
DefaultMediaNotificationProvider.

PiperOrigin-RevId: 429010249
2022-02-17 11:52:23 +00:00
christosts
437e178ef8 Create MediaNotification.Provider
Define MediaNotification.Provider so that apps can customize
notification UX. Move MediaNotificationManager's functionality
around notifications on DefaultMediaNotificationProvider

PiperOrigin-RevId: 428024699
2022-02-17 10:30:01 +00:00
tonihei
1df5572dd2 Update some text descriptions to ease translations.
Some strings didn't mention the context in which they are used
(for example as item in a list, or for accessibility). This makes it
harder for translators to choose the most appropriate translation and
grammar.

Also fix repeat and shuffle mode button accessibility descriptions to
indicate the action, not the current state.

PiperOrigin-RevId: 426924163
2022-02-08 10:24:41 +00:00
olly
99f952aae5 Update final translations
PiperOrigin-RevId: 426870226
2022-02-07 11:45:15 +00:00
ibaker
01c814e2f0 Mark all public 'rarely used' IntDefs as only TYPE_USE
This is a breaking change if the annotation itself is in use in Kotlin
code. It's judged that the IntDefs in this commit are unlikely to be
referred to often in Kotlin code. This is because they're either:
- Related to esoteric parts of the library, or
- In a common part of the library but only returned from methods (and
  never passed to callback methods).

A follow-up change will fix the positions of existing usages to match
this new config.

#minor-release

PiperOrigin-RevId: 426410237
2022-02-07 10:47:50 +00:00
ibaker
8149ac8922 Mark all non-public IntDefs as only TYPE_USE
This only changes IntDefs that cannot be used by apps because they're
either private or package-private.

A follow-up change will fix the positions of existing usages to match
this new config.

#minor-release

PiperOrigin-RevId: 426372273
2022-02-04 14:51:52 +00:00
ibaker
92a6cc10a4 Mark some unreleased IntDefs as TYPE_USE only
The longer list of targets is only necessary for backwards
compatibility with existing Kotlin code that will stop compiling
if the position of the annotation becomes 'wrong' by marking it only
TYPE_USE. Since none of these IntDefs have been released (except in
media3 alpha1) we don't need to maintain this compatibility.

Also add a comment to all the places that *do* need the longer list of
targets, in order to explain why it's there and discourage copy-pasting
when defining new IntDefs in future.

Also fix some single-element arrays to remove the array notation.

#minor-release

PiperOrigin-RevId: 426108537
2022-02-04 09:38:55 +00:00
olly
3871396070 Update session translations
PiperOrigin-RevId: 425589473
2022-02-01 14:34:19 +00:00
christosts
a26d7b821c Rename MediaNotificationHandler to MediaNotificationManager
PiperOrigin-RevId: 425359015
2022-02-01 14:15:22 +00:00
olly
78411006df Fix some additional lint warnings
PiperOrigin-RevId: 424584225
2022-01-28 08:52:11 +00:00
olly
d2cc14a98b Fix some lint warnings
PiperOrigin-RevId: 424383900
2022-01-28 08:46:46 +00:00
olly
9a664d8279 Remove additional translations
PiperOrigin-RevId: 423852067
2022-01-25 19:19:37 +00:00
olly
f8de54e4a5 Replace use of AssertionError in non-test code
PiperOrigin-RevId: 423324890
2022-01-25 19:12:27 +00:00
bachinger
491ac8f066 Estimate content position when playWhenReady never has changed
This change closes an edge case when an app is connecting a controller to a session that is already playing. In such a case `MediaControllerImplBase.getContentPosition()` keeps returning the first estimation for every call until `playWhenReady` changes for the first time.

Reproduction: Launch the demo-session app and start audio playback. Put the activity to the background and then to the foreground again. Go to the playlist view and `PlayerActivity` without interrupting playback and try to seek in the timebar. The position is stuck and snaps back.
PiperOrigin-RevId: 422795360
2022-01-25 18:56:14 +00:00
jaewan
9f2f33657f Fix missing notification of session service release
PiperOrigin-RevId: 422352302
2022-01-25 18:39:54 +00:00
jaewan
86fdbd6f6b Only unsubscribe from specified parentId
PiperOrigin-RevId: 422331961
2022-01-25 18:35:46 +00:00
jaewan
3c8a2c4e2e Stop using vector drawable on Notification for API<21
This fixes flaky failure when posting notification,
although why it's not crashing 100% is unknown.

PiperOrigin-RevId: 422168452
2022-01-25 18:28:08 +00:00
jaewan
e95b15100b Use MediaController to control sessions
This is a small refactoring toward merging
MediaNotificationHandler and PlayerNotificationManager

In detail, this CL includes following changes:
  - Use MediaController to dispatch commands to sessions in
    MediaSessionService, rather than media key events.
  - Use MediaController to monitor changes in MediaSession's
    underlying Player, rather than ForegroundServiceEventCallback.
    Removed the callback interface as well.

PiperOrigin-RevId: 422049265
2022-01-25 18:25:46 +00:00
jaewan
7756d9823d Fix NPE in MediaController's constructor
MediaController tries to release itself when the binder to the
session becomes unavailable. However, if such thing happens while
connecting in the constructor, it causes NPE when accessing
MediaControllerImpl which is only initialized after it's
connected.

This fixes random failures in existing tests.

PiperOrigin-RevId: 421423381
2022-01-25 18:00:42 +00:00
olly
e06b15506c MediaSessionService: Add missing addSession call
PiperOrigin-RevId: 420285295
2022-01-11 13:36:23 +00:00
jaewan
bb81c4969d Fix missing notification of session release
A session may not notify its release back to the controller
when the controller is connecting while the session is releasing.
Here are issues in detail:
  - MediaSession doesn't respond to controller's connection
    request when it's released.
  - MediaSession discards incoming connection requests when it's
    released. The requests are only kept in the application
    looper, but the looper is cleared when the session is
    released.

This CL fixes the above issues, and fixes some flaky tests.

PiperOrigin-RevId: 419756158
2022-01-05 12:15:35 +00:00
jaewan
b440b0fc03 Take MediaSession for building notification
PiperOrigin-RevId: 418154077
2022-01-05 12:14:58 +00:00
christosts
036a28b292 MediaController: stop advancing content position when player is paused
MediaController.getContentPosition() estimates the content position
based on the last position info sent by the player and the elapsed
real-time since the position info was received. After calling
MediaController's play/pause/setPlayWhenReady, the position estimation
logic is still applying, therefore advancing the position until the
underlying player's actual position is received. This can make the
MediaController's content position to be out of sync with player's
actual content position.

With this change, MediaController stops making content position
estimations after any of play/pause/setPlayWhenReady is called and
until a new position info is received from the underlying player.

Tested manually with the the session demo app, pausing/resuming content
from the UI.

PiperOrigin-RevId: 418000800
2022-01-05 12:14:58 +00:00
ibaker
1c3cf6938e Add explicit protected keywords to fields in MediaControllerImplBase
The whole class is package-private, so this is a no-op, but it makes the
intent of the visibililty more clear.

PiperOrigin-RevId: 417377659
2022-01-05 10:36:39 +00:00
jaewan
df2e37acbe Utilize CommandButton for customizing Notification
PiperOrigin-RevId: 416421456
2022-01-05 10:19:09 +00:00
jaewan
8c837c6e2d Clean up resources
PiperOrigin-RevId: 415937814
2022-01-05 09:54:40 +00:00
jaewan
6bceec3246 Remove setters for showing actions in Notification
PiperOrigin-RevId: 414441471
2021-12-07 17:37:31 +00:00
olly
e765f7a8eb Further media3 session cleanup
* Remove casting getInstance and getCallback methods and just
  use member variables that have the more specific types. I
  didn't manage to get rid of casting completely; there are
  still one-off casts during construction. We should look at
  removing those in the future, but it's not completely
  trivial due to the way the Impl classes back-reference
  their wrapping classes.
* Move all callback invocations inside the Impl classes for
  consistency, and properly encapsulate the callbacks there.
  Sticking with the "OnHandler" naming convention for these
  methods, but we should probably tweak that in a subsequent
  change.
* Encapsulate MediaItemFiller in MediaSessionImpl.
* Some misc cleanup (e.g., converting anonymous inner classes
  to lambdas where possible).

PiperOrigin-RevId: 414401978
2021-12-07 17:37:31 +00:00
olly
e59e15d29d Flatten Library and Session service impls
PiperOrigin-RevId: 414396999
2021-12-07 17:37:31 +00:00
jaewan
21bbdb5871 Remove built-in support for stop() in Notification
PiperOrigin-RevId: 414321900
2021-12-07 17:37:31 +00:00
olly
b9f0592702 Remove interfaces that don't seem to serve a purpose
PiperOrigin-RevId: 413966081
2021-12-07 17:37:07 +00:00
olly
f4989f5de1 Forward callback invocations to MediaLibrarySessionImpl
This is required for correct subscription notifications, as per the
referenced bug. It also just seems better to plumb things this way
in general, rather than re-implementing the functionality in the stub.

PiperOrigin-RevId: 413963824
2021-12-07 17:37:07 +00:00
olly
41a2f9a6b3 Simplify threading for media3 session callbacks
This change removes the requirement that callback implementations
need to be able to handle two specific callbacks being called on
two different threads.

PiperOrigin-RevId: 413958545
2021-12-07 17:37:07 +00:00
bachinger
2a62a5ee30 Make setMediaItemFiller public in MediaSession.Builder
#minor-release
Issue: androidx/media#8
PiperOrigin-RevId: 412403132
2021-12-02 11:55:44 +00:00
ibaker
363c9a98ae Remove statically initialized SessionResult
SessionResult stores SystemClock.elapsedRealtime() into
this.completionTimeMs, so a statically initialized instance will have
a meaningless value.

PiperOrigin-RevId: 407865809
2021-11-09 10:10:10 +00:00
ibaker
05c7a30bd7 Fix test-only visibility of MediaController#timeDiffMs
PiperOrigin-RevId: 407787258
2021-11-09 10:10:10 +00:00