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
85f3af88
authored
Jul 15, 2021
by
kimvde
Committed by
Oliver Woodman
Jul 15, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Use Player commands to enable UI buttons
PiperOrigin-RevId: 384910388
parent
08ac778a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
64 deletions
extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java
library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerControlView.java
library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java
library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java
extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java
View file @
85f3af88
...
@@ -16,6 +16,9 @@
...
@@ -16,6 +16,9 @@
package
com
.
google
.
android
.
exoplayer2
.
ext
.
mediasession
;
package
com
.
google
.
android
.
exoplayer2
.
ext
.
mediasession
;
import
static
androidx
.
media
.
utils
.
MediaConstants
.
PLAYBACK_STATE_EXTRAS_KEY_MEDIA_ID
;
import
static
androidx
.
media
.
utils
.
MediaConstants
.
PLAYBACK_STATE_EXTRAS_KEY_MEDIA_ID
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_BACK
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_FORWARD
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_IN_CURRENT_WINDOW
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_IS_PLAYING_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_IS_PLAYING_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_PLAYBACK_PARAMETERS_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_PLAYBACK_PARAMETERS_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_PLAYBACK_STATE_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_PLAYBACK_STATE_CHANGED
;
...
@@ -912,16 +915,16 @@ public final class MediaSessionConnector {
...
@@ -912,16 +915,16 @@ public final class MediaSessionConnector {
}
}
private
long
buildPlaybackActions
(
Player
player
)
{
private
long
buildPlaybackActions
(
Player
player
)
{
boolean
enableSeeking
=
false
;
boolean
enableSeeking
=
player
.
isCommandAvailable
(
COMMAND_SEEK_IN_CURRENT_WINDOW
);
boolean
enableRewind
=
false
;
boolean
enableRewind
=
boolean
enableFastForward
=
false
;
player
.
isCommandAvailable
(
COMMAND_SEEK_BACK
)
&&
controlDispatcher
.
isRewindEnabled
();
boolean
enableFastForward
=
player
.
isCommandAvailable
(
COMMAND_SEEK_FORWARD
)
&&
controlDispatcher
.
isFastForwardEnabled
();
boolean
enableSetRating
=
false
;
boolean
enableSetRating
=
false
;
boolean
enableSetCaptioningEnabled
=
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
();
enableRewind
=
enableSeeking
&&
controlDispatcher
.
isRewindEnabled
();
enableFastForward
=
enableSeeking
&&
controlDispatcher
.
isFastForwardEnabled
();
enableSetRating
=
ratingCallback
!=
null
;
enableSetRating
=
ratingCallback
!=
null
;
enableSetCaptioningEnabled
=
captionCallback
!=
null
&&
captionCallback
.
hasCaptions
(
player
);
enableSetCaptioningEnabled
=
captionCallback
!=
null
&&
captionCallback
.
hasCaptions
(
player
);
}
}
...
...
library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerControlView.java
View file @
85f3af88
...
@@ -15,9 +15,11 @@
...
@@ -15,9 +15,11 @@
*/
*/
package
com
.
google
.
android
.
exoplayer2
.
ui
;
package
com
.
google
.
android
.
exoplayer2
.
ui
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_BACK
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_FORWARD
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_IN_CURRENT_WINDOW
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_IN_CURRENT_WINDOW
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_TO_NEXT
_WINDOW
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_TO_NEXT
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_TO_PREVIOUS
_WINDOW
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_TO_PREVIOUS
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_IS_PLAYING_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_IS_PLAYING_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_PLAYBACK_STATE_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_PLAYBACK_STATE_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_PLAY_WHEN_READY_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_PLAY_WHEN_READY_CHANGED
;
...
@@ -869,21 +871,14 @@ public class PlayerControlView extends FrameLayout {
...
@@ -869,21 +871,14 @@ public class PlayerControlView extends FrameLayout {
boolean
enableFastForward
=
false
;
boolean
enableFastForward
=
false
;
boolean
enableNext
=
false
;
boolean
enableNext
=
false
;
if
(
player
!=
null
)
{
if
(
player
!=
null
)
{
Timeline
timeline
=
player
.
getCurrentTimeline
();
enableSeeking
=
player
.
isCommandAvailable
(
COMMAND_SEEK_IN_CURRENT_WINDOW
);
if
(!
timeline
.
isEmpty
()
&&
!
player
.
isPlayingAd
())
{
enablePrevious
=
player
.
isCommandAvailable
(
COMMAND_SEEK_TO_PREVIOUS
);
boolean
isSeekable
=
player
.
isCommandAvailable
(
COMMAND_SEEK_IN_CURRENT_WINDOW
);
enableRewind
=
timeline
.
getWindow
(
player
.
getCurrentWindowIndex
(),
window
);
player
.
isCommandAvailable
(
COMMAND_SEEK_BACK
)
&&
controlDispatcher
.
isRewindEnabled
();
enableSeeking
=
isSeekable
;
enableFastForward
=
enablePrevious
=
player
.
isCommandAvailable
(
COMMAND_SEEK_FORWARD
)
isSeekable
&&
controlDispatcher
.
isFastForwardEnabled
();
||
!
window
.
isLive
()
enableNext
=
player
.
isCommandAvailable
(
COMMAND_SEEK_TO_NEXT
);
||
player
.
isCommandAvailable
(
COMMAND_SEEK_TO_PREVIOUS_WINDOW
);
enableRewind
=
isSeekable
&&
controlDispatcher
.
isRewindEnabled
();
enableFastForward
=
isSeekable
&&
controlDispatcher
.
isFastForwardEnabled
();
enableNext
=
(
window
.
isLive
()
&&
window
.
isDynamic
)
||
player
.
isCommandAvailable
(
COMMAND_SEEK_TO_NEXT_WINDOW
);
}
}
}
updateButton
(
showPreviousButton
,
enablePrevious
,
previousButton
);
updateButton
(
showPreviousButton
,
enablePrevious
,
previousButton
);
...
...
library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java
View file @
85f3af88
...
@@ -15,9 +15,10 @@
...
@@ -15,9 +15,10 @@
*/
*/
package
com
.
google
.
android
.
exoplayer2
.
ui
;
package
com
.
google
.
android
.
exoplayer2
.
ui
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_IN_CURRENT_WINDOW
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_BACK
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_TO_NEXT_WINDOW
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_FORWARD
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_TO_PREVIOUS_WINDOW
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_TO_NEXT
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_TO_PREVIOUS
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_IS_PLAYING_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_IS_PLAYING_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_MEDIA_METADATA_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_MEDIA_METADATA_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_PLAYBACK_PARAMETERS_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_PLAYBACK_PARAMETERS_CHANGED
;
...
@@ -53,7 +54,6 @@ import com.google.android.exoplayer2.C;
...
@@ -53,7 +54,6 @@ import com.google.android.exoplayer2.C;
import
com.google.android.exoplayer2.ControlDispatcher
;
import
com.google.android.exoplayer2.ControlDispatcher
;
import
com.google.android.exoplayer2.DefaultControlDispatcher
;
import
com.google.android.exoplayer2.DefaultControlDispatcher
;
import
com.google.android.exoplayer2.Player
;
import
com.google.android.exoplayer2.Player
;
import
com.google.android.exoplayer2.Timeline
;
import
com.google.android.exoplayer2.util.NotificationUtil
;
import
com.google.android.exoplayer2.util.NotificationUtil
;
import
com.google.android.exoplayer2.util.Util
;
import
com.google.android.exoplayer2.util.Util
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.Documented
;
...
@@ -677,7 +677,6 @@ public class PlayerNotificationManager {
...
@@ -677,7 +677,6 @@ public class PlayerNotificationManager {
private
final
Map
<
String
,
NotificationCompat
.
Action
>
customActions
;
private
final
Map
<
String
,
NotificationCompat
.
Action
>
customActions
;
private
final
PendingIntent
dismissPendingIntent
;
private
final
PendingIntent
dismissPendingIntent
;
private
final
int
instanceId
;
private
final
int
instanceId
;
private
final
Timeline
.
Window
window
;
@Nullable
private
NotificationCompat
.
Builder
builder
;
@Nullable
private
NotificationCompat
.
Builder
builder
;
@Nullable
private
List
<
NotificationCompat
.
Action
>
builderActions
;
@Nullable
private
List
<
NotificationCompat
.
Action
>
builderActions
;
...
@@ -730,7 +729,6 @@ public class PlayerNotificationManager {
...
@@ -730,7 +729,6 @@ public class PlayerNotificationManager {
this
.
smallIconResourceId
=
smallIconResourceId
;
this
.
smallIconResourceId
=
smallIconResourceId
;
this
.
groupKey
=
groupKey
;
this
.
groupKey
=
groupKey
;
controlDispatcher
=
new
DefaultControlDispatcher
();
controlDispatcher
=
new
DefaultControlDispatcher
();
window
=
new
Timeline
.
Window
();
instanceId
=
instanceIdCounter
++;
instanceId
=
instanceIdCounter
++;
// This fails the nullness checker because handleMessage() is 'called' while `this` is still
// This fails the nullness checker because handleMessage() is 'called' while `this` is still
// @UnderInitialization. No tasks are scheduled on mainHandler before the constructor completes,
// @UnderInitialization. No tasks are scheduled on mainHandler before the constructor completes,
...
@@ -1291,24 +1289,12 @@ public class PlayerNotificationManager {
...
@@ -1291,24 +1289,12 @@ public class PlayerNotificationManager {
* action name is ignored.
* action name is ignored.
*/
*/
protected
List
<
String
>
getActions
(
Player
player
)
{
protected
List
<
String
>
getActions
(
Player
player
)
{
boolean
enablePrevious
=
false
;
boolean
enablePrevious
=
player
.
isCommandAvailable
(
COMMAND_SEEK_TO_PREVIOUS
);
boolean
enableRewind
=
false
;
boolean
enableRewind
=
boolean
enableFastForward
=
false
;
player
.
isCommandAvailable
(
COMMAND_SEEK_BACK
)
&&
controlDispatcher
.
isRewindEnabled
();
boolean
enableNext
=
false
;
boolean
enableFastForward
=
Timeline
timeline
=
player
.
getCurrentTimeline
();
player
.
isCommandAvailable
(
COMMAND_SEEK_FORWARD
)
&&
controlDispatcher
.
isFastForwardEnabled
();
if
(!
timeline
.
isEmpty
()
&&
!
player
.
isPlayingAd
())
{
boolean
enableNext
=
player
.
isCommandAvailable
(
COMMAND_SEEK_TO_NEXT
);
boolean
isSeekable
=
player
.
isCommandAvailable
(
COMMAND_SEEK_IN_CURRENT_WINDOW
);
timeline
.
getWindow
(
player
.
getCurrentWindowIndex
(),
window
);
enablePrevious
=
isSeekable
||
!
window
.
isLive
()
||
player
.
isCommandAvailable
(
COMMAND_SEEK_TO_PREVIOUS_WINDOW
);
enableRewind
=
isSeekable
&&
controlDispatcher
.
isRewindEnabled
();
enableFastForward
=
isSeekable
&&
controlDispatcher
.
isFastForwardEnabled
();
enableNext
=
(
window
.
isLive
()
&&
window
.
isDynamic
)
||
player
.
isCommandAvailable
(
COMMAND_SEEK_TO_NEXT_WINDOW
);
}
List
<
String
>
stringActions
=
new
ArrayList
<>();
List
<
String
>
stringActions
=
new
ArrayList
<>();
if
(
usePreviousAction
&&
enablePrevious
)
{
if
(
usePreviousAction
&&
enablePrevious
)
{
...
...
library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java
View file @
85f3af88
...
@@ -15,9 +15,11 @@
...
@@ -15,9 +15,11 @@
*/
*/
package
com
.
google
.
android
.
exoplayer2
.
ui
;
package
com
.
google
.
android
.
exoplayer2
.
ui
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_BACK
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_FORWARD
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_IN_CURRENT_WINDOW
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_IN_CURRENT_WINDOW
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_TO_NEXT
_WINDOW
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_TO_NEXT
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_TO_PREVIOUS
_WINDOW
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_TO_PREVIOUS
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_IS_PLAYING_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_IS_PLAYING_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_PLAYBACK_PARAMETERS_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_PLAYBACK_PARAMETERS_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_PLAYBACK_STATE_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_PLAYBACK_STATE_CHANGED
;
...
@@ -1131,21 +1133,14 @@ public class StyledPlayerControlView extends FrameLayout {
...
@@ -1131,21 +1133,14 @@ public class StyledPlayerControlView extends FrameLayout {
boolean
enableFastForward
=
false
;
boolean
enableFastForward
=
false
;
boolean
enableNext
=
false
;
boolean
enableNext
=
false
;
if
(
player
!=
null
)
{
if
(
player
!=
null
)
{
Timeline
timeline
=
player
.
getCurrentTimeline
();
enableSeeking
=
player
.
isCommandAvailable
(
COMMAND_SEEK_IN_CURRENT_WINDOW
);
if
(!
timeline
.
isEmpty
()
&&
!
player
.
isPlayingAd
())
{
enablePrevious
=
player
.
isCommandAvailable
(
COMMAND_SEEK_TO_PREVIOUS
);
boolean
isSeekable
=
player
.
isCommandAvailable
(
COMMAND_SEEK_IN_CURRENT_WINDOW
);
enableRewind
=
timeline
.
getWindow
(
player
.
getCurrentWindowIndex
(),
window
);
player
.
isCommandAvailable
(
COMMAND_SEEK_BACK
)
&&
controlDispatcher
.
isRewindEnabled
();
enableSeeking
=
isSeekable
;
enableFastForward
=
enablePrevious
=
player
.
isCommandAvailable
(
COMMAND_SEEK_FORWARD
)
isSeekable
&&
controlDispatcher
.
isFastForwardEnabled
();
||
!
window
.
isLive
()
enableNext
=
player
.
isCommandAvailable
(
COMMAND_SEEK_TO_NEXT
);
||
player
.
isCommandAvailable
(
COMMAND_SEEK_TO_PREVIOUS_WINDOW
);
enableRewind
=
isSeekable
&&
controlDispatcher
.
isRewindEnabled
();
enableFastForward
=
isSeekable
&&
controlDispatcher
.
isFastForwardEnabled
();
enableNext
=
(
window
.
isLive
()
&&
window
.
isDynamic
)
||
player
.
isCommandAvailable
(
COMMAND_SEEK_TO_NEXT_WINDOW
);
}
}
}
if
(
enableRewind
)
{
if
(
enableRewind
)
{
...
...
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