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
ffb7c466
authored
Mar 08, 2021
by
gyumin
Committed by
Ian Baker
Mar 12, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Implement addMediaItems(List) and clearMediaItems() in BasePlayer
PiperOrigin-RevId: 361487730
parent
c1dba81e
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
20 additions
and
47 deletions
extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastPlayer.java
library/common/src/main/java/com/google/android/exoplayer2/BasePlayer.java
library/common/src/main/java/com/google/android/exoplayer2/Player.java
library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java
library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java
testutils/src/main/java/com/google/android/exoplayer2/testutil/StubExoPlayer.java
extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastPlayer.java
View file @
ffb7c466
...
@@ -317,11 +317,6 @@ public final class CastPlayer extends BasePlayer {
...
@@ -317,11 +317,6 @@ public final class CastPlayer extends BasePlayer {
}
}
@Override
@Override
public
void
addMediaItems
(
List
<
MediaItem
>
mediaItems
)
{
addMediaItemsInternal
(
toMediaQueueItems
(
mediaItems
),
MediaQueueItem
.
INVALID_ITEM_ID
);
}
@Override
public
void
addMediaItems
(
int
index
,
List
<
MediaItem
>
mediaItems
)
{
public
void
addMediaItems
(
int
index
,
List
<
MediaItem
>
mediaItems
)
{
Assertions
.
checkArgument
(
index
>=
0
);
Assertions
.
checkArgument
(
index
>=
0
);
int
uid
=
MediaQueueItem
.
INVALID_ITEM_ID
;
int
uid
=
MediaQueueItem
.
INVALID_ITEM_ID
;
...
@@ -353,8 +348,8 @@ public final class CastPlayer extends BasePlayer {
...
@@ -353,8 +348,8 @@ public final class CastPlayer extends BasePlayer {
@Override
@Override
public
void
removeMediaItems
(
int
fromIndex
,
int
toIndex
)
{
public
void
removeMediaItems
(
int
fromIndex
,
int
toIndex
)
{
Assertions
.
checkArgument
(
Assertions
.
checkArgument
(
fromIndex
>=
0
&&
toIndex
>=
fromIndex
);
fromIndex
>=
0
&&
toIndex
>=
fromIndex
&&
toIndex
<=
currentTimeline
.
getWindowCount
());
toIndex
=
min
(
toIndex
,
currentTimeline
.
getWindowCount
());
if
(
fromIndex
==
toIndex
)
{
if
(
fromIndex
==
toIndex
)
{
// Do nothing.
// Do nothing.
return
;
return
;
...
@@ -367,11 +362,6 @@ public final class CastPlayer extends BasePlayer {
...
@@ -367,11 +362,6 @@ public final class CastPlayer extends BasePlayer {
}
}
@Override
@Override
public
void
clearMediaItems
()
{
removeMediaItems
(
/* fromIndex= */
0
,
/* toIndex= */
currentTimeline
.
getWindowCount
());
}
@Override
public
boolean
isCommandAvailable
(
@Command
int
command
)
{
public
boolean
isCommandAvailable
(
@Command
int
command
)
{
return
availableCommands
.
contains
(
command
);
return
availableCommands
.
contains
(
command
);
}
}
...
...
library/common/src/main/java/com/google/android/exoplayer2/BasePlayer.java
View file @
ffb7c466
...
@@ -60,6 +60,11 @@ public abstract class BasePlayer implements Player {
...
@@ -60,6 +60,11 @@ public abstract class BasePlayer implements Player {
}
}
@Override
@Override
public
final
void
addMediaItems
(
List
<
MediaItem
>
mediaItems
)
{
addMediaItems
(
/* index= */
Integer
.
MAX_VALUE
,
mediaItems
);
}
@Override
public
final
void
moveMediaItem
(
int
currentIndex
,
int
newIndex
)
{
public
final
void
moveMediaItem
(
int
currentIndex
,
int
newIndex
)
{
if
(
currentIndex
!=
newIndex
)
{
if
(
currentIndex
!=
newIndex
)
{
moveMediaItems
(
/* fromIndex= */
currentIndex
,
/* toIndex= */
currentIndex
+
1
,
newIndex
);
moveMediaItems
(
/* fromIndex= */
currentIndex
,
/* toIndex= */
currentIndex
+
1
,
newIndex
);
...
@@ -72,6 +77,11 @@ public abstract class BasePlayer implements Player {
...
@@ -72,6 +77,11 @@ public abstract class BasePlayer implements Player {
}
}
@Override
@Override
public
final
void
clearMediaItems
()
{
removeMediaItems
(
/* fromIndex= */
0
,
/* toIndex= */
Integer
.
MAX_VALUE
);
}
@Override
public
final
void
play
()
{
public
final
void
play
()
{
setPlayWhenReady
(
true
);
setPlayWhenReady
(
true
);
}
}
...
...
library/common/src/main/java/com/google/android/exoplayer2/Player.java
View file @
ffb7c466
...
@@ -1153,7 +1153,8 @@ public interface Player {
...
@@ -1153,7 +1153,8 @@ public interface Player {
/**
/**
* Adds a media item at the given index of the playlist.
* Adds a media item at the given index of the playlist.
*
*
* @param index The index at which to add the item.
* @param index The index at which to add the media item. If the index is larger than the size of
* the playlist, the media item is added to the end of the playlist.
* @param mediaItem The {@link MediaItem} to add.
* @param mediaItem The {@link MediaItem} to add.
*/
*/
void
addMediaItem
(
int
index
,
MediaItem
mediaItem
);
void
addMediaItem
(
int
index
,
MediaItem
mediaItem
);
...
@@ -1168,7 +1169,8 @@ public interface Player {
...
@@ -1168,7 +1169,8 @@ public interface Player {
/**
/**
* Adds a list of media items at the given index of the playlist.
* Adds a list of media items at the given index of the playlist.
*
*
* @param index The index at which to add the media items.
* @param index The index at which to add the media items. If the index is larger than the size of
* the playlist, the media items are added to the end of the playlist.
* @param mediaItems The {@link MediaItem MediaItems} to add.
* @param mediaItems The {@link MediaItem MediaItems} to add.
*/
*/
void
addMediaItems
(
int
index
,
List
<
MediaItem
>
mediaItems
);
void
addMediaItems
(
int
index
,
List
<
MediaItem
>
mediaItems
);
...
@@ -1204,7 +1206,8 @@ public interface Player {
...
@@ -1204,7 +1206,8 @@ public interface Player {
* Removes a range of media items from the playlist.
* Removes a range of media items from the playlist.
*
*
* @param fromIndex The index at which to start removing media items.
* @param fromIndex The index at which to start removing media items.
* @param toIndex The index of the first item to be kept (exclusive).
* @param toIndex The index of the first item to be kept (exclusive). If the index is larger than
* the size of the playlist, media items to the end of the playlist are removed.
*/
*/
void
removeMediaItems
(
int
fromIndex
,
int
toIndex
);
void
removeMediaItems
(
int
fromIndex
,
int
toIndex
);
...
...
library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java
View file @
ffb7c466
...
@@ -416,12 +416,8 @@ import java.util.List;
...
@@ -416,12 +416,8 @@ import java.util.List;
}
}
@Override
@Override
public
void
addMediaItems
(
List
<
MediaItem
>
mediaItems
)
{
addMediaItems
(
/* index= */
mediaSourceHolderSnapshots
.
size
(),
mediaItems
);
}
@Override
public
void
addMediaItems
(
int
index
,
List
<
MediaItem
>
mediaItems
)
{
public
void
addMediaItems
(
int
index
,
List
<
MediaItem
>
mediaItems
)
{
index
=
min
(
index
,
mediaSourceHolderSnapshots
.
size
());
addMediaSources
(
index
,
createMediaSources
(
mediaItems
));
addMediaSources
(
index
,
createMediaSources
(
mediaItems
));
}
}
...
@@ -464,6 +460,7 @@ import java.util.List;
...
@@ -464,6 +460,7 @@ import java.util.List;
@Override
@Override
public
void
removeMediaItems
(
int
fromIndex
,
int
toIndex
)
{
public
void
removeMediaItems
(
int
fromIndex
,
int
toIndex
)
{
toIndex
=
min
(
toIndex
,
mediaSourceHolderSnapshots
.
size
());
PlaybackInfo
playbackInfo
=
removeMediaItemsInternal
(
fromIndex
,
toIndex
);
PlaybackInfo
playbackInfo
=
removeMediaItemsInternal
(
fromIndex
,
toIndex
);
updatePlaybackInfo
(
updatePlaybackInfo
(
playbackInfo
,
playbackInfo
,
...
@@ -502,11 +499,6 @@ import java.util.List;
...
@@ -502,11 +499,6 @@ import java.util.List;
}
}
@Override
@Override
public
void
clearMediaItems
()
{
removeMediaItems
(
/* fromIndex= */
0
,
/* toIndex= */
mediaSourceHolderSnapshots
.
size
());
}
@Override
public
void
setShuffleOrder
(
ShuffleOrder
shuffleOrder
)
{
public
void
setShuffleOrder
(
ShuffleOrder
shuffleOrder
)
{
Timeline
timeline
=
createMaskingTimeline
();
Timeline
timeline
=
createMaskingTimeline
();
PlaybackInfo
newPlaybackInfo
=
PlaybackInfo
newPlaybackInfo
=
...
...
library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java
View file @
ffb7c466
...
@@ -1358,12 +1358,6 @@ public class SimpleExoPlayer extends BasePlayer
...
@@ -1358,12 +1358,6 @@ public class SimpleExoPlayer extends BasePlayer
}
}
@Override
@Override
public
void
addMediaItems
(
List
<
MediaItem
>
mediaItems
)
{
verifyApplicationThread
();
player
.
addMediaItems
(
mediaItems
);
}
@Override
public
void
addMediaItems
(
int
index
,
List
<
MediaItem
>
mediaItems
)
{
public
void
addMediaItems
(
int
index
,
List
<
MediaItem
>
mediaItems
)
{
verifyApplicationThread
();
verifyApplicationThread
();
player
.
addMediaItems
(
index
,
mediaItems
);
player
.
addMediaItems
(
index
,
mediaItems
);
...
@@ -1406,12 +1400,6 @@ public class SimpleExoPlayer extends BasePlayer
...
@@ -1406,12 +1400,6 @@ public class SimpleExoPlayer extends BasePlayer
}
}
@Override
@Override
public
void
clearMediaItems
()
{
verifyApplicationThread
();
player
.
clearMediaItems
();
}
@Override
public
void
setShuffleOrder
(
ShuffleOrder
shuffleOrder
)
{
public
void
setShuffleOrder
(
ShuffleOrder
shuffleOrder
)
{
verifyApplicationThread
();
verifyApplicationThread
();
player
.
setShuffleOrder
(
shuffleOrder
);
player
.
setShuffleOrder
(
shuffleOrder
);
...
...
testutils/src/main/java/com/google/android/exoplayer2/testutil/StubExoPlayer.java
View file @
ffb7c466
...
@@ -193,11 +193,6 @@ public abstract class StubExoPlayer extends BasePlayer implements ExoPlayer {
...
@@ -193,11 +193,6 @@ public abstract class StubExoPlayer extends BasePlayer implements ExoPlayer {
}
}
@Override
@Override
public
void
addMediaItems
(
List
<
MediaItem
>
mediaItems
)
{
throw
new
UnsupportedOperationException
();
}
@Override
public
void
addMediaItems
(
int
index
,
List
<
MediaItem
>
mediaItems
)
{
public
void
addMediaItems
(
int
index
,
List
<
MediaItem
>
mediaItems
)
{
throw
new
UnsupportedOperationException
();
throw
new
UnsupportedOperationException
();
}
}
...
@@ -233,11 +228,6 @@ public abstract class StubExoPlayer extends BasePlayer implements ExoPlayer {
...
@@ -233,11 +228,6 @@ public abstract class StubExoPlayer extends BasePlayer implements ExoPlayer {
}
}
@Override
@Override
public
void
clearMediaItems
()
{
throw
new
UnsupportedOperationException
();
}
@Override
public
boolean
isCommandAvailable
(
int
command
)
{
public
boolean
isCommandAvailable
(
int
command
)
{
throw
new
UnsupportedOperationException
();
throw
new
UnsupportedOperationException
();
}
}
...
...
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