public final class Playlist extends java.lang.Object implements java.lang.Iterable<MusicItem>, android.os.Parcelable
Playlist
对象是不可变的,且不包含重复的 MusicItem
对象,
并且最大尺寸为 MAX_SIZE
(1000)。如果往 Playlist
中添加的 MusicItem
数量超出了最大尺寸,则超出部分会被忽略。
关于 Playlist
的 “可编辑” 状态,在这里对其进行说明。在创建 Playlist
对象时,
你可能已经注意到构造器有一个 editable 参数,但 Playlist
本身是不可变的,它并未提供任何编辑方法,
你可能会对此存在疑惑。
实际上,Playlist
的 “可编辑” 状态是针对播放器而言的。如果 Playlist
是不可编辑的,
则所有通过 PlayerClient
修改播放列表的操作会被忽略。
也就是说,如果 Playlist
是不可编辑,则调用 PlayerClient
的以下方法时会被忽略:
限定符和类型 | 类和说明 |
---|---|
static class |
Playlist.Builder
Playlist 构建器。 |
限定符 | 构造器和说明 |
---|---|
protected |
Playlist(android.os.Parcel in) |
|
Playlist(java.lang.String name,
java.util.List<MusicItem> items,
boolean editable,
android.os.Bundle extra)
创建一个
Playlist 对象。 |
|
Playlist(java.lang.String name,
java.util.List<MusicItem> items,
int position,
boolean editable,
android.os.Bundle extra)
创建一个
Playlist 对象。 |
限定符和类型 | 方法和说明 |
---|---|
boolean |
contains(MusicItem musicItem)
如果当前播放队列包含指定的元素,则返回 true。
|
int |
describeContents() |
boolean |
equals(java.lang.Object obj)
不包含携带的
extra 数据 |
MusicItem |
get(int index)
返回当前播放队列中指定位置的元素。
|
java.util.List<MusicItem> |
getAllMusicItem()
获取当前播放队列中包含的所有 MusicItem 元素。
|
android.os.Bundle |
getExtra() |
java.lang.String |
getName()
获取播放列表的名称。
|
java.lang.String |
getToken()
获取播放列表的 Token。
|
int |
hashCode()
不包含携带的
extra 数据 |
int |
indexOf(MusicItem musicItem)
返回当前播放队列中第一次出现的指定元素的索引;如果当前播放队列不包含该元素,则返回 -1。
|
boolean |
isEditable()
播放列表是否是可编辑的。
|
boolean |
isEmpty()
如果当前播放队列在没有任何元素,则返回 true。
|
java.util.Iterator<MusicItem> |
iterator()
返回按适当顺序在当前播放队列的元素上进行迭代的迭代器。
|
int |
size()
返回当前播放队列中的元素数。
|
void |
writeToParcel(android.os.Parcel dest,
int flags) |
public static final int MAX_SIZE
public static final android.os.Parcelable.Creator<Playlist> CREATOR
public Playlist(@NonNull java.lang.String name, @NonNull java.util.List<MusicItem> items, boolean editable, @Nullable android.os.Bundle extra)
public Playlist(@NonNull java.lang.String name, @NonNull java.util.List<MusicItem> items, int position, boolean editable, @Nullable android.os.Bundle extra)
protected Playlist(android.os.Parcel in)
@NonNull public java.lang.String getName()
@NonNull public java.lang.String getToken()
Playlist
根据其包含的所有歌曲的 URI 自动生成。MusicItem.getUri()
,
MusicItemUtil.generateToken(List, MusicItemUtil.GetUriFunction)
public boolean isEditable()
Playlist
本身是不可变的,这里的 “可编辑” 状态是针对播放器而言的。如果 Playlist
是不可编辑的,则所有通过 PlayerClient
修改播放列表的操作会被忽略。
也就是说,如果 Playlist
是不可编辑,则 PlayerClient
的以下方法会被忽略:
public boolean contains(MusicItem musicItem)
public MusicItem get(int index) throws java.lang.IndexOutOfBoundsException
index
- 要返回的元素的索引。java.lang.IndexOutOfBoundsException
- 如果索引超出范围 (index < 0 || index >= size())public int indexOf(@NonNull MusicItem musicItem)
musicItem
- 要搜索的元素(不能为 null)public boolean isEmpty()
@NonNull public java.util.Iterator<MusicItem> iterator()
注意!由于 Playlist 被设计为是不可变的,因此不允许使用 Iterator#remove() 方法来删除元素。
iterator
在接口中 java.lang.Iterable<MusicItem>
public int size()
如果当前播放队列包含多于 Integer.MAX_VALUE 个元素,则返回 Integer.MAX_VALUE。
public java.util.List<MusicItem> getAllMusicItem()
如果当前播放队列为空,则返回一个空列表。
@Nullable public android.os.Bundle getExtra()
public boolean equals(@Nullable java.lang.Object obj)
extra
数据equals
在类中 java.lang.Object
public int hashCode()
extra
数据hashCode
在类中 java.lang.Object
public void writeToParcel(android.os.Parcel dest, int flags)
writeToParcel
在接口中 android.os.Parcelable
public int describeContents()
describeContents
在接口中 android.os.Parcelable