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
699579fd
authored
Jul 09, 2021
by
kimvde
Committed by
Oliver Woodman
Jul 13, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add seekToNext method to Player
PiperOrigin-RevId: 383816880
parent
7e6d8223
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
84 additions
and
6 deletions
RELEASENOTES.md
library/common/src/main/java/com/google/android/exoplayer2/BasePlayer.java
library/common/src/main/java/com/google/android/exoplayer2/ForwardingPlayer.java
library/common/src/main/java/com/google/android/exoplayer2/Player.java
library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java
RELEASENOTES.md
View file @
699579fd
...
@@ -6,12 +6,11 @@
...
@@ -6,12 +6,11 @@
*
Add
`needsReconfiguration`
API to the
`MediaCodecAdapter`
interface.
*
Add
`needsReconfiguration`
API to the
`MediaCodecAdapter`
interface.
*
Add
`getSeekForwardIncrement`
,
`seekForward`
,
`getSeekBackIncrement`
*
Add
`getSeekForwardIncrement`
,
`seekForward`
,
`getSeekBackIncrement`
and
`seekBack`
methods to
`Player`
.
and
`seekBack`
methods to
`Player`
.
*
Add
`getMaxSeekToPreviousPosition`
and
`seekToPrevious`
methods to
*
Add
`getMaxSeekToPreviousPosition`
,
`seekToPrevious`
and
`seekToNext`
`Player`
.
methods to
`Player`
.
*
Add
`seekForward`
and
`seekBack`
methods to
`Player`
.
*
Rename
`Player`
commands
`COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM`
,
*
Rename
`Player`
commands
`COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM`
,
`COMMAND_SEEK_TO_NEXT_MEDIA_ITEM`
,
`COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM`
and
`COMMAND_SEEK_TO_NEXT_MEDIA_ITEM`
,
`COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM`
`COMMAND_SEEK_TO_MEDIA_ITEM`
to
`COMMAND_SEEK_IN_CURRENT_WINDOW`
,
and
`COMMAND_SEEK_TO_MEDIA_ITEM`
to
`COMMAND_SEEK_IN_CURRENT_WINDOW`
,
`COMMAND_SEEK_TO_NEXT_WINDOW`
,
`COMMAND_SEEK_TO_PREVIOUS_WINDOW`
and
`COMMAND_SEEK_TO_NEXT_WINDOW`
,
`COMMAND_SEEK_TO_PREVIOUS_WINDOW`
and
`COMMAND_SEEK_TO_WINDOW`
, respectively.
`COMMAND_SEEK_TO_WINDOW`
, respectively.
*
Make
`Player`
depend on the new
`PlaybackException`
class instead of
*
Make
`Player`
depend on the new
`PlaybackException`
class instead of
...
...
library/common/src/main/java/com/google/android/exoplayer2/BasePlayer.java
View file @
699579fd
...
@@ -176,6 +176,19 @@ public abstract class BasePlayer implements Player {
...
@@ -176,6 +176,19 @@ public abstract class BasePlayer implements Player {
}
}
@Override
@Override
public
final
void
seekToNext
()
{
Timeline
timeline
=
getCurrentTimeline
();
if
(
timeline
.
isEmpty
()
||
isPlayingAd
())
{
return
;
}
if
(
hasNext
())
{
next
();
}
else
if
(
isCurrentWindowLive
()
&&
isCurrentWindowDynamic
())
{
seekToDefaultPosition
();
}
}
@Override
public
final
void
setPlaybackSpeed
(
float
speed
)
{
public
final
void
setPlaybackSpeed
(
float
speed
)
{
setPlaybackParameters
(
getPlaybackParameters
().
withSpeed
(
speed
));
setPlaybackParameters
(
getPlaybackParameters
().
withSpeed
(
speed
));
}
}
...
...
library/common/src/main/java/com/google/android/exoplayer2/ForwardingPlayer.java
View file @
699579fd
...
@@ -298,6 +298,11 @@ public class ForwardingPlayer implements Player {
...
@@ -298,6 +298,11 @@ public class ForwardingPlayer implements Player {
}
}
@Override
@Override
public
void
seekToNext
()
{
player
.
seekToNext
();
}
@Override
public
void
setPlaybackParameters
(
PlaybackParameters
playbackParameters
)
{
public
void
setPlaybackParameters
(
PlaybackParameters
playbackParameters
)
{
player
.
setPlaybackParameters
(
playbackParameters
);
player
.
setPlaybackParameters
(
playbackParameters
);
}
}
...
...
library/common/src/main/java/com/google/android/exoplayer2/Player.java
View file @
699579fd
...
@@ -1716,6 +1716,20 @@ public interface Player {
...
@@ -1716,6 +1716,20 @@ public interface Player {
void
next
();
void
next
();
/**
/**
* Seeks to a later position in the current or next window (if available). More precisely:
*
* <ul>
* <li>If the timeline is empty or seeking is not possible, does nothing.
* <li>Otherwise, if {@link #hasNext() a next window exists}, seeks to the default position of
* the next window.
* <li>Otherwise, if the current window is {@link #isCurrentWindowLive() live} and has not
* ended, seeks to the live edge of the current window.
* <li>Otherwise, does nothing.
* </ul>
*/
void
seekToNext
();
/**
* Attempts to set the playback parameters. Passing {@link PlaybackParameters#DEFAULT} resets the
* Attempts to set the playback parameters. Passing {@link PlaybackParameters#DEFAULT} resets the
* player to the default, which means there is no speed or pitch adjustment.
* player to the default, which means there is no speed or pitch adjustment.
*
*
...
...
library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java
View file @
699579fd
...
@@ -10511,7 +10511,7 @@ public final class ExoPlayerTest {
...
@@ -10511,7 +10511,7 @@ public final class ExoPlayerTest {
}
}
@Test
@Test
public
void
seekToPrevious_
c
loseToStart_seeksToPreviousWindow
()
{
public
void
seekToPrevious_
withPreviousWindowAndC
loseToStart_seeksToPreviousWindow
()
{
ExoPlayer
player
=
new
TestExoPlayerBuilder
(
context
).
build
();
ExoPlayer
player
=
new
TestExoPlayerBuilder
(
context
).
build
();
player
.
addMediaSources
(
ImmutableList
.
of
(
new
FakeMediaSource
(),
new
FakeMediaSource
()));
player
.
addMediaSources
(
ImmutableList
.
of
(
new
FakeMediaSource
(),
new
FakeMediaSource
()));
player
.
seekTo
(
/* windowIndex= */
1
,
C
.
DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS
);
player
.
seekTo
(
/* windowIndex= */
1
,
C
.
DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS
);
...
@@ -10520,6 +10520,8 @@ public final class ExoPlayerTest {
...
@@ -10520,6 +10520,8 @@ public final class ExoPlayerTest {
assertThat
(
player
.
getCurrentWindowIndex
()).
isEqualTo
(
0
);
assertThat
(
player
.
getCurrentWindowIndex
()).
isEqualTo
(
0
);
assertThat
(
player
.
getCurrentPosition
()).
isEqualTo
(
0
);
assertThat
(
player
.
getCurrentPosition
()).
isEqualTo
(
0
);
player
.
release
();
}
}
@Test
@Test
...
@@ -10532,6 +10534,51 @@ public final class ExoPlayerTest {
...
@@ -10532,6 +10534,51 @@ public final class ExoPlayerTest {
assertThat
(
player
.
getCurrentWindowIndex
()).
isEqualTo
(
1
);
assertThat
(
player
.
getCurrentWindowIndex
()).
isEqualTo
(
1
);
assertThat
(
player
.
getCurrentPosition
()).
isEqualTo
(
0
);
assertThat
(
player
.
getCurrentPosition
()).
isEqualTo
(
0
);
player
.
release
();
}
@Test
public
void
seekToNext_withNextWindow_seeksToNextWindow
()
{
ExoPlayer
player
=
new
TestExoPlayerBuilder
(
context
).
build
();
player
.
addMediaSources
(
ImmutableList
.
of
(
new
FakeMediaSource
(),
new
FakeMediaSource
()));
player
.
seekToNext
();
assertThat
(
player
.
getCurrentWindowIndex
()).
isEqualTo
(
1
);
assertThat
(
player
.
getCurrentPosition
()).
isEqualTo
(
0
);
player
.
release
();
}
@Test
public
void
seekToNext_liveWindowWithoutNextWindow_seeksToLiveEdge
()
throws
Exception
{
ExoPlayer
player
=
new
TestExoPlayerBuilder
(
context
).
build
();
Timeline
timeline
=
new
FakeTimeline
(
new
TimelineWindowDefinition
(
/* periodCount= */
1
,
/* id= */
0
,
/* isSeekable= */
true
,
/* isDynamic= */
true
,
/* isLive= */
true
,
/* isPlaceholder= */
false
,
/* durationUs= */
1_000_000
,
/* defaultPositionUs= */
500_000
,
TimelineWindowDefinition
.
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US
,
AdPlaybackState
.
NONE
));
MediaSource
mediaSource
=
new
FakeMediaSource
(
timeline
);
player
.
setMediaSource
(
mediaSource
);
player
.
prepare
();
TestPlayerRunHelper
.
runUntilPlaybackState
(
player
,
Player
.
STATE_READY
);
player
.
seekTo
(
/* positionMs = */
0
);
player
.
seekToNext
();
assertThat
(
player
.
getCurrentWindowIndex
()).
isEqualTo
(
0
);
assertThat
(
player
.
getCurrentPosition
()).
isEqualTo
(
500
);
player
.
release
();
}
}
@Test
@Test
...
...
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