Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9e238eb6
authored
Dec 03, 2019
by
bachinger
Committed by
Oliver Woodman
Dec 06, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
MediaSessionConnector: Support ACTION_SET_CAPTIONING_ENABLED
PiperOrigin-RevId: 283546707
parent
ab016ebd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
3 deletions
RELEASENOTES.md
extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java
RELEASENOTES.md
View file @
9e238eb6
...
@@ -131,6 +131,8 @@
...
@@ -131,6 +131,8 @@
of the extension after this change, following the instructions in the
of the extension after this change, following the instructions in the
extension's readme.
extension's readme.
*
Opus extension: Update to use NDK r20.
*
Opus extension: Update to use NDK r20.
*
MediaSession extension: Make media session connector dispatch
`ACTION_SET_CAPTIONING_ENABLED`
.
*
GVR extension: This extension is now deprecated.
*
GVR extension: This extension is now deprecated.
*
Demo apps (TODO: update links to point to r2.11.0 tag):
*
Demo apps (TODO: update links to point to r2.11.0 tag):
*
Add
[
SurfaceControl demo app
](
https://github.com/google/ExoPlayer/tree/dev-v2/demos/surface
)
*
Add
[
SurfaceControl demo app
](
https://github.com/google/ExoPlayer/tree/dev-v2/demos/surface
)
...
...
extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java
View file @
9e238eb6
...
@@ -339,6 +339,21 @@ public final class MediaSessionConnector {
...
@@ -339,6 +339,21 @@ public final class MediaSessionConnector {
void
onSetRating
(
Player
player
,
RatingCompat
rating
,
Bundle
extras
);
void
onSetRating
(
Player
player
,
RatingCompat
rating
,
Bundle
extras
);
}
}
/** Handles requests for enabling or disabling captions. */
public
interface
CaptionCallback
extends
CommandReceiver
{
/** See {@link MediaSessionCompat.Callback#onSetCaptioningEnabled(boolean)}. */
void
onSetCaptioningEnabled
(
Player
player
,
boolean
enabled
);
/**
* Returns whether the media currently being played has captions.
*
* <p>This method is called each time the media session playback state needs to be updated and
* published upon a player state change.
*/
boolean
hasCaptions
(
Player
player
);
}
/** Handles a media button event. */
/** Handles a media button event. */
public
interface
MediaButtonEventHandler
{
public
interface
MediaButtonEventHandler
{
/**
/**
...
@@ -420,6 +435,7 @@ public final class MediaSessionConnector {
...
@@ -420,6 +435,7 @@ public final class MediaSessionConnector {
@Nullable
private
QueueNavigator
queueNavigator
;
@Nullable
private
QueueNavigator
queueNavigator
;
@Nullable
private
QueueEditor
queueEditor
;
@Nullable
private
QueueEditor
queueEditor
;
@Nullable
private
RatingCallback
ratingCallback
;
@Nullable
private
RatingCallback
ratingCallback
;
@Nullable
private
CaptionCallback
captionCallback
;
@Nullable
private
MediaButtonEventHandler
mediaButtonEventHandler
;
@Nullable
private
MediaButtonEventHandler
mediaButtonEventHandler
;
private
long
enabledPlaybackActions
;
private
long
enabledPlaybackActions
;
...
@@ -606,7 +622,7 @@ public final class MediaSessionConnector {
...
@@ -606,7 +622,7 @@ public final class MediaSessionConnector {
*
*
* @param ratingCallback The rating callback.
* @param ratingCallback The rating callback.
*/
*/
public
void
setRatingCallback
(
RatingCallback
ratingCallback
)
{
public
void
setRatingCallback
(
@Nullable
RatingCallback
ratingCallback
)
{
if
(
this
.
ratingCallback
!=
ratingCallback
)
{
if
(
this
.
ratingCallback
!=
ratingCallback
)
{
unregisterCommandReceiver
(
this
.
ratingCallback
);
unregisterCommandReceiver
(
this
.
ratingCallback
);
this
.
ratingCallback
=
ratingCallback
;
this
.
ratingCallback
=
ratingCallback
;
...
@@ -615,6 +631,19 @@ public final class MediaSessionConnector {
...
@@ -615,6 +631,19 @@ public final class MediaSessionConnector {
}
}
/**
/**
* Sets the {@link CaptionCallback} to handle requests to enable or disable captions.
*
* @param captionCallback The caption callback.
*/
public
void
setCaptionCallback
(
@Nullable
CaptionCallback
captionCallback
)
{
if
(
this
.
captionCallback
!=
captionCallback
)
{
unregisterCommandReceiver
(
this
.
captionCallback
);
this
.
captionCallback
=
captionCallback
;
registerCommandReceiver
(
this
.
captionCallback
);
}
}
/**
* Sets a custom error on the session.
* Sets a custom error on the session.
*
*
* <p>This sets the error code via {@link PlaybackStateCompat.Builder#setErrorMessage(int,
* <p>This sets the error code via {@link PlaybackStateCompat.Builder#setErrorMessage(int,
...
@@ -843,12 +872,14 @@ public final class MediaSessionConnector {
...
@@ -843,12 +872,14 @@ public final class MediaSessionConnector {
boolean
enableRewind
=
false
;
boolean
enableRewind
=
false
;
boolean
enableFastForward
=
false
;
boolean
enableFastForward
=
false
;
boolean
enableSetRating
=
false
;
boolean
enableSetRating
=
false
;
boolean
enableSetCaptioningEnabled
=
false
;
Timeline
timeline
=
player
.
getCurrentTimeline
();
Timeline
timeline
=
player
.
getCurrentTimeline
();
if
(!
timeline
.
isEmpty
()
&&
!
player
.
isPlayingAd
())
{
if
(!
timeline
.
isEmpty
()
&&
!
player
.
isPlayingAd
())
{
enableSeeking
=
player
.
isCurrentWindowSeekable
();
enableSeeking
=
player
.
isCurrentWindowSeekable
();
enableRewind
=
enableSeeking
&&
rewindMs
>
0
;
enableRewind
=
enableSeeking
&&
rewindMs
>
0
;
enableFastForward
=
enableSeeking
&&
fastForwardMs
>
0
;
enableFastForward
=
enableSeeking
&&
fastForwardMs
>
0
;
enableSetRating
=
true
;
enableSetRating
=
ratingCallback
!=
null
;
enableSetCaptioningEnabled
=
captionCallback
!=
null
&&
captionCallback
.
hasCaptions
(
player
);
}
}
long
playbackActions
=
BASE_PLAYBACK_ACTIONS
;
long
playbackActions
=
BASE_PLAYBACK_ACTIONS
;
...
@@ -868,9 +899,12 @@ public final class MediaSessionConnector {
...
@@ -868,9 +899,12 @@ public final class MediaSessionConnector {
actions
|=
actions
|=
(
QueueNavigator
.
ACTIONS
&
queueNavigator
.
getSupportedQueueNavigatorActions
(
player
));
(
QueueNavigator
.
ACTIONS
&
queueNavigator
.
getSupportedQueueNavigatorActions
(
player
));
}
}
if
(
ratingCallback
!=
null
&&
enableSetRating
)
{
if
(
enableSetRating
)
{
actions
|=
PlaybackStateCompat
.
ACTION_SET_RATING
;
actions
|=
PlaybackStateCompat
.
ACTION_SET_RATING
;
}
}
if
(
enableSetCaptioningEnabled
)
{
actions
|=
PlaybackStateCompat
.
ACTION_SET_CAPTIONING_ENABLED
;
}
return
actions
;
return
actions
;
}
}
...
@@ -903,6 +937,13 @@ public final class MediaSessionConnector {
...
@@ -903,6 +937,13 @@ public final class MediaSessionConnector {
@EnsuresNonNullIf
(
@EnsuresNonNullIf
(
result
=
true
,
result
=
true
,
expression
=
{
"player"
,
"captionCallback"
})
private
boolean
canDispatchSetCaptioningEnabled
()
{
return
player
!=
null
&&
captionCallback
!=
null
;
}
@EnsuresNonNullIf
(
result
=
true
,
expression
=
{
"player"
,
"queueEditor"
})
expression
=
{
"player"
,
"queueEditor"
})
private
boolean
canDispatchQueueEdit
()
{
private
boolean
canDispatchQueueEdit
()
{
return
player
!=
null
&&
queueEditor
!=
null
;
return
player
!=
null
&&
queueEditor
!=
null
;
...
@@ -1354,6 +1395,13 @@ public final class MediaSessionConnector {
...
@@ -1354,6 +1395,13 @@ public final class MediaSessionConnector {
}
}
@Override
@Override
public
void
onSetCaptioningEnabled
(
boolean
enabled
)
{
if
(
canDispatchSetCaptioningEnabled
())
{
captionCallback
.
onSetCaptioningEnabled
(
player
,
enabled
);
}
}
@Override
public
boolean
onMediaButtonEvent
(
Intent
mediaButtonEvent
)
{
public
boolean
onMediaButtonEvent
(
Intent
mediaButtonEvent
)
{
boolean
isHandled
=
boolean
isHandled
=
canDispatchMediaButtonEvent
()
canDispatchMediaButtonEvent
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment