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
b8b9a641
authored
Jan 12, 2021
by
Oliver Woodman
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge pull request #8412 from h6ah4i:media2-move-playlist-item
PiperOrigin-RevId: 351305387
parents
de0e1e51
d522dbaf
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
61 additions
and
0 deletions
extensions/media2/src/androidTest/java/com/google/android/exoplayer2/ext/media2/SessionPlayerConnectorTest.java
extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/PlayerCommandQueue.java
extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/PlayerWrapper.java
extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/SessionCallback.java
extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/SessionPlayerConnector.java
extensions/media2/src/androidTest/java/com/google/android/exoplayer2/ext/media2/SessionPlayerConnectorTest.java
View file @
b8b9a641
...
...
@@ -931,6 +931,38 @@ public class SessionPlayerConnectorTest {
assertThat
(
onPlaylistChangedLatch
.
getCount
()).
isEqualTo
(
1
);
}
@Test
@LargeTest
@SdkSuppress
(
minSdkVersion
=
Build
.
VERSION_CODES
.
KITKAT
)
public
void
movePlaylistItem_calledOnlyOnce_notifiesPlaylistChangeOnlyOnce
()
throws
Exception
{
List
<
MediaItem
>
playlist
=
new
ArrayList
<>();
playlist
.
add
(
TestUtils
.
createMediaItem
(
R
.
raw
.
video_1
));
playlist
.
add
(
TestUtils
.
createMediaItem
(
R
.
raw
.
video_2
));
playlist
.
add
(
TestUtils
.
createMediaItem
(
R
.
raw
.
video_3
));
assertPlayerResultSuccess
(
sessionPlayerConnector
.
setPlaylist
(
playlist
,
/* metadata= */
null
));
assertPlayerResultSuccess
(
sessionPlayerConnector
.
prepare
());
CountDownLatch
onPlaylistChangedLatch
=
new
CountDownLatch
(
2
);
int
moveFromIndex
=
0
;
int
moveToIndex
=
2
;
playlist
.
add
(
moveToIndex
,
playlist
.
remove
(
moveFromIndex
));
sessionPlayerConnector
.
registerPlayerCallback
(
executor
,
new
SessionPlayer
.
PlayerCallback
()
{
@Override
public
void
onPlaylistChanged
(
SessionPlayer
player
,
@Nullable
List
<
MediaItem
>
list
,
@Nullable
MediaMetadata
metadata
)
{
assertThat
(
list
).
isEqualTo
(
playlist
);
onPlaylistChangedLatch
.
countDown
();
}
});
sessionPlayerConnector
.
movePlaylistItem
(
moveFromIndex
,
moveToIndex
);
assertThat
(
onPlaylistChangedLatch
.
await
(
PLAYLIST_CHANGE_WAIT_TIME_MS
,
MILLISECONDS
)).
isFalse
();
assertThat
(
onPlaylistChangedLatch
.
getCount
()).
isEqualTo
(
1
);
}
// TODO(b/168860979): De-flake and re-enable.
@Ignore
@Test
...
...
extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/PlayerCommandQueue.java
View file @
b8b9a641
...
...
@@ -97,6 +97,9 @@ import java.util.concurrent.Callable;
/** Command code for {@link SessionPlayer#removePlaylistItem(int)} */
public
static
final
int
COMMAND_CODE_PLAYER_REMOVE_PLAYLIST_ITEM
=
16
;
/** Command code for {@link SessionPlayer#movePlaylistItem(int, int)} */
public
static
final
int
COMMAND_CODE_PLAYER_MOVE_PLAYLIST_ITEM
=
17
;
/** List of session commands whose result would be set after the command is finished. */
@Documented
@Retention
(
RetentionPolicy
.
SOURCE
)
...
...
@@ -119,6 +122,7 @@ import java.util.concurrent.Callable;
COMMAND_CODE_PLAYER_SET_PLAYLIST
,
COMMAND_CODE_PLAYER_ADD_PLAYLIST_ITEM
,
COMMAND_CODE_PLAYER_REMOVE_PLAYLIST_ITEM
,
COMMAND_CODE_PLAYER_MOVE_PLAYLIST_ITEM
,
})
public
@interface
CommandCode
{}
...
...
extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/PlayerWrapper.java
View file @
b8b9a641
...
...
@@ -223,6 +223,19 @@ import java.util.List;
return
true
;
}
public
boolean
movePlaylistItem
(
@IntRange
(
from
=
0
)
int
fromIndex
,
@IntRange
(
from
=
0
)
int
toIndex
)
{
int
itemCount
=
player
.
getMediaItemCount
();
if
(!(
fromIndex
<
itemCount
&&
toIndex
<
itemCount
))
{
return
false
;
}
if
(
fromIndex
==
toIndex
)
{
return
true
;
}
player
.
moveMediaItem
(
fromIndex
,
toIndex
);
return
true
;
}
public
boolean
skipToPreviousPlaylistItem
()
{
Timeline
timeline
=
player
.
getCurrentTimeline
();
Assertions
.
checkState
(!
timeline
.
isEmpty
());
...
...
extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/SessionCallback.java
View file @
b8b9a641
...
...
@@ -227,6 +227,7 @@ import java.util.concurrent.TimeoutException;
}
build
.
addAllPredefinedCommands
(
SessionCommand
.
COMMAND_VERSION_1
);
build
.
addCommand
(
new
SessionCommand
(
SessionCommand
.
COMMAND_CODE_PLAYER_MOVE_PLAYLIST_ITEM
));
// TODO(internal b/142848015): Use removeCommand(int) when it's added.
if
(
mediaItemProvider
==
null
)
{
build
.
removeCommand
(
new
SessionCommand
(
SessionCommand
.
COMMAND_CODE_PLAYER_SET_MEDIA_ITEM
));
...
...
extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/SessionPlayerConnector.java
View file @
b8b9a641
...
...
@@ -325,6 +325,17 @@ public final class SessionPlayerConnector extends SessionPlayer {
}
@Override
public
ListenableFuture
<
PlayerResult
>
movePlaylistItem
(
int
fromIndex
,
int
toIndex
)
{
Assertions
.
checkArgument
(
fromIndex
>=
0
);
Assertions
.
checkArgument
(
toIndex
>=
0
);
ListenableFuture
<
PlayerResult
>
result
=
playerCommandQueue
.
addCommand
(
PlayerCommandQueue
.
COMMAND_CODE_PLAYER_MOVE_PLAYLIST_ITEM
,
/* command= */
()
->
player
.
movePlaylistItem
(
fromIndex
,
toIndex
));
return
result
;
}
@Override
public
ListenableFuture
<
PlayerResult
>
skipToPreviousPlaylistItem
()
{
ListenableFuture
<
PlayerResult
>
result
=
playerCommandQueue
.
addCommand
(
...
...
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