public class PlayerClient extends java.lang.Object implements Player, PlayerManager, PlaylistManager, PlaylistEditor, SleepTimer
限定符和类型 | 类和说明 |
---|---|
static interface |
PlayerClient.OnAudioSessionChangeListener
用于监听播放器的 audio session id 改变事件。
|
static interface |
PlayerClient.OnConnectCallback
用于监听播放器是否连接成功。
|
static interface |
PlayerClient.OnConnectStateChangeListener
用于监听 PlayerClient 的连接成功与断开连接事件。
|
static interface |
PlayerClient.OnPlaybackStateChangeListener
用于监听播放器播放状态的改变。
|
Player.OnBufferedProgressChangeListener, Player.OnPlayingMusicItemChangeListener, Player.OnPlaylistChangeListener, Player.OnPlayModeChangeListener, Player.OnPrepareListener, Player.OnRepeatListener, Player.OnSeekCompleteListener, Player.OnSpeedChangeListener, Player.OnStalledChangeListener
PlaylistManager.Callback
SleepTimer.OnStateChangeListener, SleepTimer.TimeoutAction
限定符和类型 | 方法和说明 |
---|---|
void |
addOnAudioSessionChangeListener(androidx.lifecycle.LifecycleOwner owner,
PlayerClient.OnAudioSessionChangeListener listener)
监听播放器的 audio session id
如果监听器已添加,则忽略本次调用。
|
void |
addOnAudioSessionChangeListener(PlayerClient.OnAudioSessionChangeListener listener)
添加一个 audio session id 监听器。
|
void |
addOnBufferedProgressChangeListener(androidx.lifecycle.LifecycleOwner owner,
Player.OnBufferedProgressChangeListener listener)
添加一个缓存进度监听器。
|
void |
addOnBufferedProgressChangeListener(Player.OnBufferedProgressChangeListener listener)
添加一个缓存进度监听器。
|
void |
addOnConnectStateChangeListener(androidx.lifecycle.LifecycleOwner owner,
PlayerClient.OnConnectStateChangeListener listener)
添加一个
PlayerClient.OnConnectStateChangeListener 监听器用来监听 PlayerClient 的连接成功与断开连接事件。 |
void |
addOnConnectStateChangeListener(PlayerClient.OnConnectStateChangeListener listener)
添加一个监听器用来监听 PlayerClient 连接断开事件。
|
void |
addOnPlaybackStateChangeListener(androidx.lifecycle.LifecycleOwner owner,
Player.OnPlaybackStateChangeListener listener)
添加一个播放器播放状态监听器。
|
void |
addOnPlaybackStateChangeListener(androidx.lifecycle.LifecycleOwner owner,
PlayerClient.OnPlaybackStateChangeListener listener)
监听播放器状态。
|
void |
addOnPlaybackStateChangeListener(Player.OnPlaybackStateChangeListener listener)
添加一个播放器播放状态监听器。
|
void |
addOnPlaybackStateChangeListener(PlayerClient.OnPlaybackStateChangeListener listener)
监听播放器状态。
|
void |
addOnPlayingMusicItemChangeListener(androidx.lifecycle.LifecycleOwner owner,
Player.OnPlayingMusicItemChangeListener listener)
添加一个监听当前播放的 MusicItem 改变事件的监听器。
|
void |
addOnPlayingMusicItemChangeListener(Player.OnPlayingMusicItemChangeListener listener)
添加一个监听当前播放的 MusicItem 改变事件的监听器。
|
void |
addOnPlaylistChangeListener(androidx.lifecycle.LifecycleOwner owner,
Player.OnPlaylistChangeListener listener)
添加一个用于监听播放列表改变事件的监听器。
|
void |
addOnPlaylistChangeListener(Player.OnPlaylistChangeListener listener)
添加一个用于监听播放列表改变事件的监听器。
|
void |
addOnPlayModeChangeListener(androidx.lifecycle.LifecycleOwner owner,
Player.OnPlayModeChangeListener listener)
添加一个用于监听播放模式改变的监听器。
|
void |
addOnPlayModeChangeListener(Player.OnPlayModeChangeListener listener)
添加一个用于监听播放模式改变的监听器。
|
void |
addOnPrepareListener(androidx.lifecycle.LifecycleOwner owner,
Player.OnPrepareListener listener)
添加一个播放器准备(prepare)状态监听器。
|
void |
addOnPrepareListener(Player.OnPrepareListener listener)
添加一个播放器准备(prepare)状态监听器。
|
void |
addOnRepeatListener(androidx.lifecycle.LifecycleOwner owner,
Player.OnRepeatListener listener)
添加一个
Player.OnRepeatListener 监听器。 |
void |
addOnRepeatListener(Player.OnRepeatListener listener)
添加一个
Player.OnRepeatListener 监听器。 |
void |
addOnSeekCompleteListener(androidx.lifecycle.LifecycleOwner owner,
Player.OnSeekCompleteListener listener)
添加一个用于监听播放器播放进度调整完毕事件的监听器。
|
void |
addOnSeekCompleteListener(Player.OnSeekCompleteListener listener)
添加一个用于监听播放器播放进度调整完毕事件的监听器。
|
void |
addOnSleepTimerStateChangeListener(androidx.lifecycle.LifecycleOwner owner,
SleepTimer.OnStateChangeListener listener)
监听睡眠定时器的状态。
|
void |
addOnSleepTimerStateChangeListener(SleepTimer.OnStateChangeListener listener)
监听睡眠定时器的状态。
|
void |
addOnSpeedChangeListener(androidx.lifecycle.LifecycleOwner owner,
Player.OnSpeedChangeListener listener)
添加一个用于监听播放速度改变的监听器。
|
void |
addOnSpeedChangeListener(Player.OnSpeedChangeListener listener)
添加一个用于监听播放速度改变的监听器。
|
void |
addOnStalledChangeListener(androidx.lifecycle.LifecycleOwner owner,
Player.OnStalledChangeListener listener)
添加一个 stalled 状态监听器。
|
void |
addOnStalledChangeListener(Player.OnStalledChangeListener listener)
添加一个 stalled 状态监听器。
|
void |
appendMusicItem(MusicItem musicItem)
往播放列表的末尾添加一首歌曲。
|
void |
cancelSleepTimer()
取消睡眠定时器。
|
void |
connect()
连接播放器。
|
void |
connect(PlayerClient.OnConnectCallback callback)
连接播放器
|
void |
disconnect()
断开与播放器的连接。
|
void |
fastForward()
快进。
|
android.os.Bundle |
getAudioEffectConfig()
获取音频特效的配置。
|
int |
getAudioSessionId()
获取 audio session id。
|
int |
getBufferedProgress()
获取当前的缓存进度。
|
int |
getErrorCode()
获取错误码。
|
java.lang.String |
getErrorMessage()
获取错误信息。
|
long |
getLastModified()
获取最后一次修改播放列表的时间。
|
android.support.v4.media.session.MediaControllerCompat |
getMediaController()
获取
MediaControllerCompat 对象。 |
PlaybackState |
getPlaybackState()
获取当前播放状态。
|
MusicItem |
getPlayingMusicItem()
获取当前正在播放的音乐。
|
int |
getPlayingMusicItemDuration()
获取当前正在播放的音乐的持续时间。
|
void |
getPlaylist(PlaylistManager.Callback callback)
以异步的方式获取播放队列。
|
PlaylistManager |
getPlaylistManager()
获取当前 PlayerController 的 PlaylistManager 对象。
|
java.lang.String |
getPlaylistName()
获取播放列表的名称。
|
int |
getPlaylistSize()
获取当前播放队列的大小。
|
java.lang.String |
getPlaylistToken()
获取播放列表的 Token
|
PlayMode |
getPlayMode()
获取当前播放模式。
|
int |
getPlayPosition()
获取当前播放列表的播放位置。
|
int |
getPlayProgress()
获取播放进度(单位:毫秒)。
|
long |
getPlayProgressUpdateTime()
获取播放进度的更新时间。
|
long |
getSleepTimerElapsedTime()
获取睡眠定时器已经走过的时间。
|
long |
getSleepTimerStartedTime()
获取睡眠定时器的启动时间。
|
long |
getSleepTimerTime()
获取睡眠定时器的定时时间。
|
SoundQuality |
getSoundQuality()
获取当前播放器的首选音质。
|
float |
getSpeed()
获取播放速度。
|
SleepTimer.TimeoutAction |
getTimeoutAction()
获取睡眠定时器的时间到时要执行的操作。
|
void |
insertMusicItem(int position,
MusicItem musicItem)
往列表中插入了一首新的歌曲。
|
boolean |
isAudioEffectEnabled()
是否已启用音频特效。
|
boolean |
isAutoConnect()
是否已经启用自动连接。
|
boolean |
isConnected()
判断播放器是否已连接。
|
boolean |
isError()
播放器是否发生了错误。
|
boolean |
isForbidSeek()
判断是否禁用了所有的 seek 操作。
|
boolean |
isIgnoreAudioFocus()
是否忽略音频焦点。
|
boolean |
isLooping()
是否单曲循环播放。
|
boolean |
isOnlyWifiNetwork()
是否只允许使用 Wifi 网络(默认为 false)。
|
boolean |
isPlaying()
播放器当前是否处于
PlaybackState.PLAYING 状态。 |
boolean |
isPlaylistEditable()
播放列表是否是可编辑的。
|
boolean |
isPrepared()
播放器是否准备完毕。
|
boolean |
isPreparing()
播放器是否正在准备中。
|
boolean |
isSleepTimerStarted()
查询睡眠定时器是否已启动。
|
boolean |
isStalled()
当前播放器是否处于 stalled 状态。
|
void |
moveMusicItem(int fromPosition,
int toPosition)
移动播放列表中某首歌曲的位置。
|
static PlayerClient |
newInstance(android.content.Context context,
java.lang.Class<? extends PlayerService> playerService)
创建一个 PlayerClient 对象。
|
void |
pause()
暂停播放。
|
void |
play()
开始播放。
|
void |
playPause()
播放/暂停。
|
void |
playPause(int position)
播放或暂停播放列表中指定索引处的音乐。
|
void |
removeMusicItem(int position)
移除播放列表中指定位置的歌曲。
|
void |
removeMusicItem(MusicItem musicItem)
从播放列表中移除了指定歌曲。
|
void |
removeOnAudioSessionChangeListener(PlayerClient.OnAudioSessionChangeListener listener)
移除 audio session id 监听器。
|
void |
removeOnBufferedProgressChangeListener(Player.OnBufferedProgressChangeListener listener)
移除缓存进度监听器。
|
void |
removeOnConnectStateChangeListener(PlayerClient.OnConnectStateChangeListener listener)
移除已添加的
PlayerClient.OnConnectStateChangeListener 监听器对象。 |
void |
removeOnPlaybackStateChangeListener(Player.OnPlaybackStateChangeListener listener)
移除播放器播放状态监听器。
|
void |
removeOnPlaybackStateChangeListener(PlayerClient.OnPlaybackStateChangeListener listener)
移除播放器状态监听器。
|
void |
removeOnPlayingMusicItemChangeListener(Player.OnPlayingMusicItemChangeListener listener)
移除当前播放的 MusicItem 改变事件监听器
|
void |
removeOnPlaylistChangeListener(Player.OnPlaylistChangeListener listener)
移除用于监听播放列表改变事件的监听器。
|
void |
removeOnPlayModeChangeListener(Player.OnPlayModeChangeListener listener)
移除一个用于监听播放模式改变的监听器。
|
void |
removeOnPrepareListener(Player.OnPrepareListener listener)
移除一个播放器准备(prepare)状态监听器。
|
void |
removeOnRepeatListener(Player.OnRepeatListener listener)
异常已注册的
Player.OnRepeatListener 监听器。 |
void |
removeOnSeekCompleteListener(Player.OnSeekCompleteListener listener)
移除用于监听播放器播放进度调整完毕的监听器。
|
void |
removeOnSleepTimerStateChangeListener(SleepTimer.OnStateChangeListener listener)
移除已注册的睡眠定时器状态监听器。
|
void |
removeOnSpeedChangeListener(Player.OnSpeedChangeListener listener)
移除一个用于监听播放模式改变的监听器。
|
void |
removeOnStalledChangeListener(Player.OnStalledChangeListener listener)
移除 stalled 状态监听器。
|
void |
rewind()
快退。
|
void |
seekTo(int progress)
调整音乐播放进度(单位:毫秒)。
|
void |
sendCustomAction(java.lang.String action,
android.os.Bundle args)
发送自定义动作。
|
void |
setAudioEffectConfig(android.os.Bundle config)
修改音频特效的配置。
|
void |
setAudioEffectEnabled(boolean enabled)
设置是否启用音频特效(如:均衡器)(默认为 false)。
|
void |
setAutoConnect(boolean autoConnect)
设置是否启用自动连接功能。
|
void |
setIgnoreAudioFocus(boolean ignoreAudioFocus)
设置是否忽略音频焦点。
|
void |
setNextPlay(MusicItem musicItem)
设置 “下一次播放” 的歌曲。
|
void |
setOnlyWifiNetwork(boolean onlyWifiNetwork)
设置是否只允许在 WiFi 网络下播放音乐(默认为 false)。
|
void |
setPlaylist(Playlist playlist)
设置一个新的播放列表。
|
void |
setPlaylist(Playlist playlist,
boolean play)
设置一个新的播放列表。
|
void |
setPlaylist(Playlist playlist,
int position,
boolean play)
设置一个新的播放列表。
|
void |
setPlayMode(PlayMode playMode)
设置播放模式。
|
void |
setSoundQuality(SoundQuality soundQuality)
设置播放器的首选音质(默认为
SoundQuality.STANDARD )。 |
void |
setSpeed(float speed)
设置播放速度。
|
void |
shutdown()
关闭播放器。
|
void |
skipToNext()
下一曲。
|
void |
skipToPosition(int position)
播放 position 处的音乐,如果播放列表中 position 处的音乐是当前正在播放的音乐,则忽略本次调用。
|
void |
skipToPrevious()
上一曲。
|
void |
startSleepTimer(long time)
启动睡眠定时器。
|
void |
startSleepTimer(long time,
SleepTimer.TimeoutAction action)
启动睡眠定时器。
|
void |
stop()
停止播放。
|
public static PlayerClient newInstance(@NonNull android.content.Context context, @NonNull java.lang.Class<? extends PlayerService> playerService)
context
- Context 对象,不能为 nullplayerService
- PlayerService 或者其子类的 Class 对象,不能为 nullpublic void connect()
public void connect(PlayerClient.OnConnectCallback callback)
callback
- 回调接口,用于接收连接结果public void disconnect()
断开连接后,可以调用 connect()
或者 connect(OnConnectCallback)
方法再次进行连接。
public boolean isConnected()
public void setAutoConnect(boolean autoConnect)
PlayerClient
类实现了 Player
接口与 PlaylistEditor
接口。
如果启用了 PlayerClient
的自动连接功能,那么在调用定义在 Player
接口与
PlaylistEditor
接口中的方法时,如果 PlayerClient
还没有连接到 PlayerService
,
或者连接已断开,则 PlayerClient
会尝试自动建立连接,并且会在连接成功后再去执行对应的方法。
autoConnect
- 是否启用自动连接功能,为 true 时启用自动连接,为 false 时不启用。Player
,
PlaylistEditor
public boolean isAutoConnect()
public void addOnConnectStateChangeListener(@NonNull PlayerClient.OnConnectStateChangeListener listener)
listener
- 要添加的事件监听器,如果已添加,则会忽略本次调用public void addOnConnectStateChangeListener(@NonNull androidx.lifecycle.LifecycleOwner owner, @NonNull PlayerClient.OnConnectStateChangeListener listener)
PlayerClient.OnConnectStateChangeListener
监听器用来监听 PlayerClient
的连接成功与断开连接事件。owner
- LifecycleOwner 对象。监听器会在该 LifecycleOwner 对象销毁时自动注销,避免内存泄露listener
- 要添加的事件监听器,如果已添加,则会忽略本次调用public void removeOnConnectStateChangeListener(PlayerClient.OnConnectStateChangeListener listener)
PlayerClient.OnConnectStateChangeListener
监听器对象。listener
- 要移除的监听器@Nullable public android.support.v4.media.session.MediaControllerCompat getMediaController()
MediaControllerCompat
对象。MediaControllerCompat
对象,如果还没有建立连接(isConnected()
返回
false
),那么该方法可能会返回 nullpublic void sendCustomAction(@NonNull java.lang.String action, @Nullable android.os.Bundle args)
你可以通过覆盖 PlayerService.onCustomAction(String, Bundle)
方法来响应自定义动作。
action
- 自定义动作的名称,不能为 nullargs
- 要携带的额外参数,可为 nullpublic void setSoundQuality(@NonNull SoundQuality soundQuality)
SoundQuality.STANDARD
)。
该方法只在连接到播放器后(isConnected()
返回 true)才有效。
setSoundQuality
在接口中 PlayerManager
soundQuality
- 要设置的音质,不能为 nullSoundQuality.STANDARD
,
SoundQuality.LOW
,
SoundQuality.HIGH
,
SoundQuality.SUPER
,
getSoundQuality()
public void setAudioEffectConfig(@NonNull android.os.Bundle config)
setAudioEffectConfig
在接口中 PlayerManager
config
- 要设置的音频特效配置,不能为 nullpublic void setAudioEffectEnabled(boolean enabled)
该方法只在连接到播放器后(isConnected()
返回 true)才有效。
setAudioEffectEnabled
在接口中 PlayerManager
enabled
- 是否启用音频特效isAudioEffectEnabled()
public void setOnlyWifiNetwork(boolean onlyWifiNetwork)
该方法只在连接到播放器后(isConnected()
返回 true)才有效。
setOnlyWifiNetwork
在接口中 PlayerManager
onlyWifiNetwork
- 是否只允许在 WiFi 网络下播放音乐isOnlyWifiNetwork()
public void setIgnoreAudioFocus(boolean ignoreAudioFocus)
setIgnoreAudioFocus
在接口中 PlayerManager
ignoreAudioFocus
- 是否忽略音频焦点。如果为 true,则播放器会忽略音频焦点的获取与丢失。public SoundQuality getSoundQuality()
@NonNull public android.os.Bundle getAudioEffectConfig()
为了确保返回正确的值,请在连接成功后再调用该方法。
public boolean isAudioEffectEnabled()
public boolean isOnlyWifiNetwork()
public boolean isIgnoreAudioFocus()
public void shutdown()
调用该方法后,后台的播放器会自动关闭,并断开所有客户端的连接。如果客户端仅仅只需要断开与播放器的连接,
使用 disconnect()
方法即可。
shutdown
在接口中 PlayerManager
disconnect()
public PlaylistManager getPlaylistManager()
注意!只允许在播放器已连接(isConnected()
返回 true)时,才允许使用 PlaylistManager
修改播放队列。当然,即使未连接,使用 PlaylistManager 访问播放队列还是允许的。
public void setPlaylist(@NonNull Playlist playlist)
playlist
- 播放列表(不能为 null)public void setPlaylist(@NonNull Playlist playlist, boolean play)
playlist
- 播放列表(不能为 null)play
- 是否立即播放列表中的音乐public void setPlaylist(@NonNull Playlist playlist, int position, boolean play) throws java.lang.IllegalArgumentException
setPlaylist
在接口中 PlaylistEditor
playlist
- 播放列表(不能为 null)position
- 播放列表中要播放的歌曲的位置play
- 是否立即播放 position
参数指定处的音乐java.lang.IllegalArgumentException
- 如果 position 的值小于 0,则抛出该异常public void getPlaylist(@NonNull PlaylistManager.Callback callback)
PlaylistManager
getPlaylist
在接口中 PlaylistManager
public long getLastModified()
PlaylistManager
这个时间是 System.currentTimeMillis()
getLastModified
在接口中 PlaylistManager
@NonNull public java.lang.String getPlaylistName()
PlaylistManager
getPlaylistName
在接口中 PlaylistManager
public int getPlaylistSize()
PlaylistManager
这是个轻量级操作,可在 UI 线程上直接运行。
getPlaylistSize
在接口中 PlaylistManager
@NonNull public java.lang.String getPlaylistToken()
PlaylistManager
getPlaylistToken
在接口中 PlaylistManager
public boolean isPlaylistEditable()
PlaylistManager
isPlaylistEditable
在接口中 PlaylistManager
public int getPlayProgress()
public long getPlayProgressUpdateTime()
public boolean isLooping()
PlayMode.LOOP
时返回 true,否则返回 false@Nullable public MusicItem getPlayingMusicItem()
public int getPlayingMusicItemDuration()
public PlaybackState getPlaybackState()
PlaybackState
public int getAudioSessionId()
public int getBufferedProgress()
public boolean isPlaying()
PlaybackState.PLAYING
状态。PlaybackState.PLAYING
状态则返回 true,否则返回 falsepublic boolean isStalled()
stalled 状态用于表示当前缓冲区是否有足够的数据继续播放,如果缓冲区没有足够的数据支撑继续播放,则该 方法会返回 true,如果缓冲区有足够的数据可以继续播放,则返回 false。
public boolean isPreparing()
public boolean isPrepared()
public boolean isError()
public int getErrorCode()
ErrorCode.NO_ERROR
ErrorCode
public java.lang.String getErrorMessage()
isError()
,
getErrorCode()
public PlayMode getPlayMode()
public float getSpeed()
public int getPlayPosition()
public boolean isSleepTimerStarted()
public long getSleepTimerTime()
该方法的返回值只在睡眠定时器启动(isSleepTimerStarted()
返回 true)时才有意义。
isSleepTimerStarted()
返回 true)时才有意义。public long getSleepTimerStartedTime()
这个时间是基于 SystemClock.elapsedRealtime()
的,且该方法的返回值只在睡眠定时器启动
(isSleepTimerStarted()
返回 true)时才有意义。
使用当前的 SystemClock.elapsedRealtime()
减去这个时间,即可知道睡眠定时器已经走过的时间。
isSleepTimerStarted()
返回 true)时才有意义。getSleepTimerElapsedTime()
public long getSleepTimerElapsedTime()
该方法的返回值只在睡眠定时器启动(isSleepTimerStarted()
返回 true)时才有意义。
@NonNull public SleepTimer.TimeoutAction getTimeoutAction()
该方法的返回值只在睡眠定时器启动(isSleepTimerStarted()
返回 true)时才有意义。
SleepTimer.TimeoutAction.PAUSE
)public void skipToNext()
该方法只在连接到播放器后(isConnected()
返回 true)才有效。
skipToNext
在接口中 Player
public void skipToPrevious()
该方法只在连接到播放器后(isConnected()
返回 true)才有效。
skipToPrevious
在接口中 Player
public void skipToPosition(int position) throws java.lang.IllegalArgumentException
该方法只在连接到播放器后(isConnected()
返回 true)才有效。
skipToPosition
在接口中 Player
position
- 要播放的音乐的 position 值(从 0 开始计算)。java.lang.IllegalArgumentException
- 如果 position 值小于 0,则会抛出该异常。public void playPause(int position) throws java.lang.IllegalArgumentException
该方法只在连接到播放器后(isConnected()
返回 true)才有效。
public void setPlayMode(@NonNull PlayMode playMode)
该方法只在连接到播放器后(isConnected()
返回 true)才有效。
setPlayMode
在接口中 Player
playMode
- 播放模式PlayMode
public void setSpeed(float speed)
public void play()
该方法只在连接到播放器后(isConnected()
返回 true)才有效。
public void pause()
该方法只在连接到播放器后(isConnected()
返回 true)才有效。
public void stop()
该方法只在连接到播放器后(isConnected()
返回 true)才有效。
public void playPause()
该方法只在连接到播放器后(isConnected()
返回 true)才有效。
public void seekTo(int progress)
该方法只在连接到播放器后(isConnected()
返回 true)才有效。
public boolean isForbidSeek()
默认为 false,如果该方法返回 true,则会同时禁用 seekTo、fastForward、rewind 操作。
public void fastForward()
该方法只在连接到播放器后(isConnected()
返回 true)才有效。
fastForward
在接口中 Player
public void rewind()
该方法只在连接到播放器后(isConnected()
返回 true)才有效。
public void startSleepTimer(long time) throws java.lang.IllegalArgumentException
time
- 睡眠时间(单位:毫秒)。播放器会在经过 time 时间后暂停播放。java.lang.IllegalArgumentException
- 如果定时时间小于 0,则抛出该异常public void startSleepTimer(long time, @NonNull SleepTimer.TimeoutAction action) throws java.lang.IllegalArgumentException
startSleepTimer
在接口中 SleepTimer
time
- 睡眠时间(单位:毫秒)。播放器会在经过 time 时间后暂停播放。action
- 定时器的的时间到时要执行的操作。java.lang.IllegalArgumentException
- 如果定时时间小于 0,则抛出该异常public void cancelSleepTimer()
cancelSleepTimer
在接口中 SleepTimer
public void addOnPlaybackStateChangeListener(@NonNull Player.OnPlaybackStateChangeListener listener)
如果监听器已添加,则忽略本次调用。
listener
- 播放器播放状态监听器Player.OnPlaybackStateChangeListener
public void addOnPlaybackStateChangeListener(@NonNull androidx.lifecycle.LifecycleOwner owner, @NonNull Player.OnPlaybackStateChangeListener listener)
如果监听器已添加,则忽略本次调用。
事件监听器会在 LifecycleOwner 销毁时自动注销,以避免发生内容泄露。
owner
- LifecycleOwner 对象listener
- 播放器播放状态监听器Player.OnPlaybackStateChangeListener
public void removeOnPlaybackStateChangeListener(Player.OnPlaybackStateChangeListener listener)
listener
- 要移除的监听器。public void addOnPrepareListener(@NonNull Player.OnPrepareListener listener)
listener
- 如果监听器已存在,则忽略本次添加public void addOnPrepareListener(@NonNull androidx.lifecycle.LifecycleOwner owner, @NonNull Player.OnPrepareListener listener)
事件监听器会在 LifecycleOwner 销毁时自动注销,以避免发生内容泄露。
owner
- LifecycleOwner 对象listener
- 如果监听器已存在,则忽略本次添加public void removeOnPrepareListener(Player.OnPrepareListener listener)
listener
- 要移除的监听器public void addOnStalledChangeListener(@NonNull Player.OnStalledChangeListener listener)
如果监听器已添加,则忽略本次调用。
listener
- 要添加的监听器Player.OnStalledChangeListener
public void addOnStalledChangeListener(@NonNull androidx.lifecycle.LifecycleOwner owner, @NonNull Player.OnStalledChangeListener listener)
如果监听器已添加,则忽略本次调用。
事件监听器会在 LifecycleOwner 销毁时自动注销,以避免发生内容泄露。
listener
- 要添加的监听器Player.OnStalledChangeListener
public void removeOnStalledChangeListener(Player.OnStalledChangeListener listener)
listener
- 要移除的监听器。public void addOnBufferedProgressChangeListener(@NonNull Player.OnBufferedProgressChangeListener listener)
如果监听器已添加,则忽略本次调用。
listener
- 要添加的监听器Player.OnBufferedProgressChangeListener
public void addOnBufferedProgressChangeListener(@NonNull androidx.lifecycle.LifecycleOwner owner, @NonNull Player.OnBufferedProgressChangeListener listener)
如果监听器已添加,则忽略本次调用。
事件监听器会在 LifecycleOwner 销毁时自动注销,以避免发生内容泄露。
owner
- LifecycleOwner 对象listener
- 要添加的监听器public void removeOnBufferedProgressChangeListener(Player.OnBufferedProgressChangeListener listener)
listener
- 要移除的监听器public void addOnPlayingMusicItemChangeListener(@NonNull Player.OnPlayingMusicItemChangeListener listener)
如果监听器已添加,则忽略本次调用。
listener
- 要添加的监听器Player.OnPlayingMusicItemChangeListener
public void addOnPlayingMusicItemChangeListener(@NonNull androidx.lifecycle.LifecycleOwner owner, @NonNull Player.OnPlayingMusicItemChangeListener listener)
如果监听器已添加,则忽略本次调用。
事件监听器会在 LifecycleOwner 销毁时自动注销,以避免发生内容泄露。
listener
- 要添加的监听器Player.OnPlayingMusicItemChangeListener
public void removeOnPlayingMusicItemChangeListener(Player.OnPlayingMusicItemChangeListener listener)
listener
- 要移除的监听器public void addOnSeekCompleteListener(@NonNull Player.OnSeekCompleteListener listener)
如果监听器已添加,则忽略本次调用。
listener
- 要添加的监听器Player.OnSeekCompleteListener
public void addOnSeekCompleteListener(@NonNull androidx.lifecycle.LifecycleOwner owner, @NonNull Player.OnSeekCompleteListener listener)
如果监听器已添加,则忽略本次调用。
事件监听器会在 LifecycleOwner 销毁时自动注销,以避免发生内容泄露。
listener
- 要添加的监听器Player.OnSeekCompleteListener
public void removeOnSeekCompleteListener(Player.OnSeekCompleteListener listener)
listener
- 要移除的监听器public void addOnPlaylistChangeListener(@NonNull Player.OnPlaylistChangeListener listener)
如果监听器已添加,则忽略本次调用。
listener
- 要添加的监听器Player.OnPlaylistChangeListener
public void addOnPlaylistChangeListener(@NonNull androidx.lifecycle.LifecycleOwner owner, @NonNull Player.OnPlaylistChangeListener listener)
如果监听器已添加,则忽略本次调用。
事件监听器会在 LifecycleOwner 销毁时自动注销,以避免发生内容泄露。
listener
- 要添加的监听器Player.OnPlaylistChangeListener
public void removeOnPlaylistChangeListener(Player.OnPlaylistChangeListener listener)
listener
- 要移除的监听器public void addOnPlayModeChangeListener(@NonNull Player.OnPlayModeChangeListener listener)
如果监听器已添加,则忽略本次调用。
listener
- 要添加的监听器Player.OnPlayModeChangeListener
public void addOnPlayModeChangeListener(@NonNull androidx.lifecycle.LifecycleOwner owner, @NonNull Player.OnPlayModeChangeListener listener)
如果监听器已添加,则忽略本次调用。
事件监听器会在 LifecycleOwner 销毁时自动注销,以避免发生内容泄露。
listener
- 要添加的监听器Player.OnPlayModeChangeListener
public void removeOnPlayModeChangeListener(Player.OnPlayModeChangeListener listener)
listener
- 要移除的事件监听器public void addOnSpeedChangeListener(@NonNull Player.OnSpeedChangeListener listener)
如果监听器已添加,则忽略本次调用。
listener
- 要添加的监听器,不能为 nullpublic void addOnSpeedChangeListener(@NonNull androidx.lifecycle.LifecycleOwner owner, @NonNull Player.OnSpeedChangeListener listener)
如果监听器已添加,则忽略本次调用。
事件监听器会在 LifecycleOwner 销毁时自动注销,以避免发生内容泄露。
listener
- 要添加的监听器,不能为 nullpublic void removeOnSpeedChangeListener(Player.OnSpeedChangeListener listener)
listener
- 要移除的事件监听器public void addOnPlaybackStateChangeListener(@NonNull PlayerClient.OnPlaybackStateChangeListener listener)
如果监听器已添加,则忽略本次调用。
listener
- 要添加的监听器public void addOnPlaybackStateChangeListener(@NonNull androidx.lifecycle.LifecycleOwner owner, @NonNull PlayerClient.OnPlaybackStateChangeListener listener)
如果监听器已添加,则忽略本次调用。
事件监听器会在 LifecycleOwner 销毁时自动注销,以避免发生内容泄露。
listener
- 要添加的监听器public void removeOnPlaybackStateChangeListener(PlayerClient.OnPlaybackStateChangeListener listener)
listener
- 要移除的监听器public void addOnAudioSessionChangeListener(@NonNull PlayerClient.OnAudioSessionChangeListener listener)
如果监听器已添加,则忽略本次调用。
listener
- 要添加的监听器public void addOnAudioSessionChangeListener(@NonNull androidx.lifecycle.LifecycleOwner owner, @NonNull PlayerClient.OnAudioSessionChangeListener listener)
如果监听器已添加,则忽略本次调用。
事件监听器会在 LifecycleOwner 销毁时自动注销,以避免发生内容泄露。
listener
- 要添加的监听器public void removeOnAudioSessionChangeListener(PlayerClient.OnAudioSessionChangeListener listener)
listener
- 要移除的监听器public void addOnSleepTimerStateChangeListener(@NonNull SleepTimer.OnStateChangeListener listener)
如果监听器已添加,则忽略本次调用。
listener
- 要添加的监听器public void addOnSleepTimerStateChangeListener(@NonNull androidx.lifecycle.LifecycleOwner owner, @NonNull SleepTimer.OnStateChangeListener listener)
如果监听器已添加,则忽略本次调用。
事件监听器会在 LifecycleOwner 销毁时自动注销,以避免发生内容泄露。
listener
- 要添加的监听器public void removeOnSleepTimerStateChangeListener(SleepTimer.OnStateChangeListener listener)
listener
- 要移除的监听器public void addOnRepeatListener(@NonNull Player.OnRepeatListener listener)
Player.OnRepeatListener
监听器。
如果监听器已添加,则忽略本次调用。
listener
- 要添加的监听器,不能为 nullpublic void addOnRepeatListener(@NonNull androidx.lifecycle.LifecycleOwner owner, @NonNull Player.OnRepeatListener listener)
listener
- 要添加的监听器,不能为 nullpublic void removeOnRepeatListener(Player.OnRepeatListener listener)
Player.OnRepeatListener
监听器。public void insertMusicItem(int position, @NonNull MusicItem musicItem) throws java.lang.IllegalArgumentException
如果播放列表中已包含指定歌曲,则会将它移动到 position 位置,如果不存在,则会将歌曲插入到 position 位置。
insertMusicItem
在接口中 PlaylistEditor
position
- 歌曲插入的位置musicItem
- 要插入的歌曲,不能为 nulljava.lang.IllegalArgumentException
- 如果 position 的值小于 0,则抛出该异常public void appendMusicItem(@NonNull MusicItem musicItem)
PlaylistEditor
如果播放列表中已包含指定歌曲,则会将它移动到播放列表的末尾位置,如果不存在,则会将歌曲添加到播放列表的末尾。
appendMusicItem
在接口中 PlaylistEditor
musicItem
- 要添加播放列表末尾的歌曲,不能为 nullpublic void moveMusicItem(int fromPosition, int toPosition) throws java.lang.IndexOutOfBoundsException
moveMusicItem
在接口中 PlaylistEditor
fromPosition
- 歌曲在列表中的位置toPosition
- 歌曲要移动到的位置。如果 toPosition == fromPosition
,则会忽略本次调用java.lang.IndexOutOfBoundsException
- 如果 fromPosition 或者 toPosition 超出播放列表索引的范围,则抛出该异常public void removeMusicItem(@NonNull MusicItem musicItem)
PlaylistEditor
removeMusicItem
在接口中 PlaylistEditor
musicItem
- 要移除的歌曲。如果播放列表中不包含该歌曲,则忽略本次调用public void removeMusicItem(int position)
PlaylistEditor
removeMusicItem
在接口中 PlaylistEditor
position
- 要移除的歌曲的位置public void setNextPlay(@NonNull MusicItem musicItem)
PlaylistEditor
setNextPlay
在接口中 PlaylistEditor
musicItem
- 要设定为 “下一次播放” 的歌曲,如果歌曲已存在播放列表中,则会移动到 “下一曲播放” 的位
置,如果歌曲不存在,则插入到 “下一曲播放” 位置