From 51a38c51917d8aa387948e681bc24bd9cd527998 Mon Sep 17 00:00:00 2001 From: jrfeng Date: Mon, 6 Jul 2020 09:15:20 +0800 Subject: [PATCH] modify PlayerClient - update docs - optimize connect logic --- .../main/java/snow/player/PlayerClient.java | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/player/src/main/java/snow/player/PlayerClient.java b/player/src/main/java/snow/player/PlayerClient.java index 42567595..62ab7370 100644 --- a/player/src/main/java/snow/player/PlayerClient.java +++ b/player/src/main/java/snow/player/PlayerClient.java @@ -110,9 +110,9 @@ public void onConnected() { if (mConnectCallback != null) { mConnectCallback.onConnected(true); - mConnectCallback = null; } } catch (RemoteException e) { + mMediaBrowser.disconnect(); onConnectionFailed(); } } @@ -123,7 +123,6 @@ public void onConnectionFailed() { if (mConnectCallback != null) { mConnectCallback.onConnected(false); - mConnectCallback = null; } } }, null); @@ -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); } /** @@ -1430,7 +1442,15 @@ public void removeOnRadioStationChangeListener(RadioStationPlayer.OnRadioStation } } + /** + * 用于监听播放器连接状态的回调接口。 + */ public interface OnConnectCallback { + /** + * 该方法会在连接成功或失败时调用。 + * + * @param success 是否连接成功,如果为 true,则表示连接成功,否则为 false + */ void onConnected(boolean success); }