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
38308488
authored
Jul 16, 2021
by
kimvde
Committed by
Ian Baker
Jul 20, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Use Player methods in DefaultControlDispatcher
PiperOrigin-RevId: 385118021
parent
f173ffa9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
43 deletions
RELEASENOTES.md
library/common/src/main/java/com/google/android/exoplayer2/DefaultControlDispatcher.java
library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java
RELEASENOTES.md
View file @
38308488
...
...
@@ -98,6 +98,8 @@
corresponding buttons can be disabled by using a
`ForwardingPlayer`
that removes
`COMMAND_SEEK_BACK`
and
`COMMAND_SEEK_FORWARD`
from the
available commands.
*
Update
`DefaultControlDispatcher`
`getRewindIncrementMs`
and
`getFastForwardIncrementMs`
to take the player as parameter.
*
Video:
*
Fix
`IncorrectContextUseViolation`
strict mode warning on Android 11
(
[
#8246
](
https://github.com/google/ExoPlayer/pull/8246
)
).
...
...
library/common/src/main/java/com/google/android/exoplayer2/DefaultControlDispatcher.java
View file @
38308488
...
...
@@ -21,19 +21,15 @@ import static java.lang.Math.min;
/** Default {@link ControlDispatcher}. */
public
class
DefaultControlDispatcher
implements
ControlDispatcher
{
/** The default fast forward increment, in milliseconds. */
public
static
final
int
DEFAULT_FAST_FORWARD_MS
=
15_000
;
/** The default rewind increment, in milliseconds. */
public
static
final
int
DEFAULT_REWIND_MS
=
5000
;
private
static
final
int
MAX_POSITION_FOR_SEEK_TO_PREVIOUS
=
3000
;
private
final
long
rewindIncrementMs
;
private
final
long
fastForwardIncrementMs
;
private
final
boolean
rewindAndFastForwardIncrementsSet
;
/** Creates an instance. */
public
DefaultControlDispatcher
()
{
this
(
DEFAULT_FAST_FORWARD_MS
,
DEFAULT_REWIND_MS
);
fastForwardIncrementMs
=
C
.
TIME_UNSET
;
rewindIncrementMs
=
C
.
TIME_UNSET
;
rewindAndFastForwardIncrementsSet
=
false
;
}
/**
...
...
@@ -47,6 +43,7 @@ public class DefaultControlDispatcher implements ControlDispatcher {
public
DefaultControlDispatcher
(
long
fastForwardIncrementMs
,
long
rewindIncrementMs
)
{
this
.
fastForwardIncrementMs
=
fastForwardIncrementMs
;
this
.
rewindIncrementMs
=
rewindIncrementMs
;
rewindAndFastForwardIncrementsSet
=
true
;
}
@Override
...
...
@@ -69,39 +66,21 @@ public class DefaultControlDispatcher implements ControlDispatcher {
@Override
public
boolean
dispatchPrevious
(
Player
player
)
{
Timeline
timeline
=
player
.
getCurrentTimeline
();
if
(
timeline
.
isEmpty
()
||
player
.
isPlayingAd
())
{
return
true
;
}
boolean
isUnseekableLiveStream
=
player
.
isCurrentWindowLive
()
&&
!
player
.
isCurrentWindowSeekable
();
if
(
player
.
hasPreviousWindow
()
&&
(
player
.
getCurrentPosition
()
<=
MAX_POSITION_FOR_SEEK_TO_PREVIOUS
||
isUnseekableLiveStream
))
{
player
.
seekToPreviousWindow
();
}
else
if
(!
isUnseekableLiveStream
)
{
player
.
seekTo
(
/* positionMs= */
0
);
}
player
.
seekToPrevious
();
return
true
;
}
@Override
public
boolean
dispatchNext
(
Player
player
)
{
Timeline
timeline
=
player
.
getCurrentTimeline
();
if
(
timeline
.
isEmpty
()
||
player
.
isPlayingAd
())
{
return
true
;
}
if
(
player
.
hasNextWindow
())
{
player
.
seekToNextWindow
();
}
else
if
(
player
.
isCurrentWindowLive
()
&&
player
.
isCurrentWindowDynamic
())
{
player
.
seekToDefaultPosition
();
}
player
.
seekToNext
();
return
true
;
}
@Override
public
boolean
dispatchRewind
(
Player
player
)
{
if
(
isRewindEnabled
()
&&
player
.
isCurrentWindowSeekable
())
{
if
(!
rewindAndFastForwardIncrementsSet
)
{
player
.
seekBack
();
}
else
if
(
isRewindEnabled
()
&&
player
.
isCurrentWindowSeekable
())
{
seekToOffset
(
player
,
-
rewindIncrementMs
);
}
return
true
;
...
...
@@ -109,7 +88,9 @@ public class DefaultControlDispatcher implements ControlDispatcher {
@Override
public
boolean
dispatchFastForward
(
Player
player
)
{
if
(
isFastForwardEnabled
()
&&
player
.
isCurrentWindowSeekable
())
{
if
(!
rewindAndFastForwardIncrementsSet
)
{
player
.
seekForward
();
}
else
if
(
isFastForwardEnabled
()
&&
player
.
isCurrentWindowSeekable
())
{
seekToOffset
(
player
,
fastForwardIncrementMs
);
}
return
true
;
...
...
@@ -142,22 +123,24 @@ public class DefaultControlDispatcher implements ControlDispatcher {
@Override
public
boolean
isRewindEnabled
()
{
return
rewindIncrementMs
>
0
;
return
!
rewindAndFastForwardIncrementsSet
||
rewindIncrementMs
>
0
;
}
@Override
public
boolean
isFastForwardEnabled
()
{
return
fastForwardIncrementMs
>
0
;
return
!
rewindAndFastForwardIncrementsSet
||
fastForwardIncrementMs
>
0
;
}
/** Returns the rewind increment in milliseconds. */
public
long
getRewindIncrementMs
()
{
return
rewind
IncrementMs
;
public
long
getRewindIncrementMs
(
Player
player
)
{
return
rewind
AndFastForwardIncrementsSet
?
rewindIncrementMs
:
player
.
getSeekBackIncrement
()
;
}
/** Returns the fast forward increment in milliseconds. */
public
long
getFastForwardIncrementMs
()
{
return
fastForwardIncrementMs
;
public
long
getFastForwardIncrementMs
(
Player
player
)
{
return
rewindAndFastForwardIncrementsSet
?
fastForwardIncrementMs
:
player
.
getSeekForwardIncrement
();
}
// Internal methods.
...
...
library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java
View file @
38308488
...
...
@@ -26,6 +26,8 @@ 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_POSITION_DISCONTINUITY
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_REPEAT_MODE_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_SEEK_BACK_INCREMENT_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_SEEK_FORWARD_INCREMENT_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_SHUFFLE_MODE_ENABLED_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_TIMELINE_CHANGED
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
EVENT_TRACKS_CHANGED
;
...
...
@@ -1142,8 +1144,8 @@ public class StyledPlayerControlView extends FrameLayout {
private
void
updateRewindButton
()
{
long
rewindMs
=
controlDispatcher
instanceof
DefaultControlDispatcher
?
((
DefaultControlDispatcher
)
controlDispatcher
).
getRewindIncrementMs
()
controlDispatcher
instanceof
DefaultControlDispatcher
&&
player
!=
null
?
((
DefaultControlDispatcher
)
controlDispatcher
).
getRewindIncrementMs
(
player
)
:
C
.
DEFAULT_SEEK_BACK_INCREMENT_MS
;
int
rewindSec
=
(
int
)
(
rewindMs
/
1_000
);
if
(
rewindButtonTextView
!=
null
)
{
...
...
@@ -1158,8 +1160,8 @@ public class StyledPlayerControlView extends FrameLayout {
private
void
updateFastForwardButton
()
{
long
fastForwardMs
=
controlDispatcher
instanceof
DefaultControlDispatcher
?
((
DefaultControlDispatcher
)
controlDispatcher
).
getFastForwardIncrementMs
()
controlDispatcher
instanceof
DefaultControlDispatcher
&&
player
!=
null
?
((
DefaultControlDispatcher
)
controlDispatcher
).
getFastForwardIncrementMs
(
player
)
:
C
.
DEFAULT_SEEK_FORWARD_INCREMENT_MS
;
int
fastForwardSec
=
(
int
)
(
fastForwardMs
/
1_000
);
if
(
fastForwardButtonTextView
!=
null
)
{
...
...
@@ -1756,7 +1758,9 @@ public class StyledPlayerControlView extends FrameLayout {
EVENT_REPEAT_MODE_CHANGED
,
EVENT_SHUFFLE_MODE_ENABLED_CHANGED
,
EVENT_POSITION_DISCONTINUITY
,
EVENT_TIMELINE_CHANGED
))
{
EVENT_TIMELINE_CHANGED
,
EVENT_SEEK_BACK_INCREMENT_CHANGED
,
EVENT_SEEK_FORWARD_INCREMENT_CHANGED
))
{
updateNavigation
();
}
if
(
events
.
containsAny
(
EVENT_POSITION_DISCONTINUITY
,
EVENT_TIMELINE_CHANGED
))
{
...
...
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