Skip to content

Commit

Permalink
modify PlayerClient
Browse files Browse the repository at this point in the history
- update docs
- optimize connect logic
  • Loading branch information
jrfeng committed Jul 6, 2020
1 parent eb54d76 commit 51a38c5
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions player/src/main/java/snow/player/PlayerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ public void onConnected() {

if (mConnectCallback != null) {
mConnectCallback.onConnected(true);
mConnectCallback = null;
}
} catch (RemoteException e) {
mMediaBrowser.disconnect();
onConnectionFailed();
}
}
Expand All @@ -123,7 +123,6 @@ public void onConnectionFailed() {

if (mConnectCallback != null) {
mConnectCallback.onConnected(false);
mConnectCallback = null;
}
}
}, null);
Expand Down Expand Up @@ -499,23 +498,36 @@ public PlaylistManager getPlaylistManager() {
/**
* 设置一个新的播放列表。
*
* @param playlist 播放列表(不能为 null)
* @param playlist 播放列表(不能为 null)
*/
public void setPlaylist(@NonNull Playlist playlist) {
setPlaylist(playlist, 0, false);
}

/**
* 设置一个新的播放列表。
*
* @param playlist 播放列表(不能为 null)
* @param position 播放列表中要播放的歌曲的位置
*/
public void setPlaylist(@NonNull Playlist playlist, int position) {
setPlaylist(playlist, position, false);
}

public void setPlaylist(@NonNull Playlist playlist, int position, boolean playOnPrepared) {
/**
* 设置一个新的播放列表。
*
* @param playlist 播放列表(不能为 null)
* @param position 播放列表中要播放的歌曲的位置
* @param play 是否立即播放 {@code position} 参数指定处的音乐
*/
public void setPlaylist(@NonNull Playlist playlist, int position, boolean play) {
Preconditions.checkNotNull(playlist);
if (!isConnected()) {
return;
}

mPlaylistManager.setPlaylist(playlist, position, playOnPrepared);
mPlaylistManager.setPlaylist(playlist, position, play);
}

/**
Expand Down Expand Up @@ -1430,7 +1442,15 @@ public void removeOnRadioStationChangeListener(RadioStationPlayer.OnRadioStation
}
}

/**
* 用于监听播放器连接状态的回调接口。
*/
public interface OnConnectCallback {
/**
* 该方法会在连接成功或失败时调用。
*
* @param success 是否连接成功,如果为 true,则表示连接成功,否则为 false
*/
void onConnected(boolean success);
}

Expand Down

0 comments on commit 51a38c5

Please sign in to comment.