Skip to content

Commit cf87d21

Browse files
author
Chris Bellew
committed
Don't resubscribe to chromecast unless we're not already subscribed. Only update the play/pause/spinner buttons if the state has changed.
1 parent 000e15e commit cf87d21

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

mobile/src/main/java/com/atomjack/vcfp/CastPlayerManager.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.support.v7.media.MediaRouter;
55

66
import com.atomjack.shared.Logger;
7+
import com.atomjack.shared.NewLogger;
78
import com.atomjack.shared.PlayerState;
89
import com.atomjack.shared.Preferences;
910
import com.atomjack.vcfp.interfaces.ActiveConnectionHandler;
@@ -30,6 +31,7 @@
3031
import java.util.concurrent.ConcurrentHashMap;
3132

3233
public class CastPlayerManager {
34+
private NewLogger logger;
3335
private PlexMedia nowPlayingMedia;
3436
private ArrayList<? extends PlexMedia> nowPlayingPlaylist;
3537

@@ -128,6 +130,7 @@ public CastPlayerManager(Context context) {
128130
mContext = context;
129131
plexSessionId = VoiceControlForPlexApplication.generateRandomString();
130132
setCastConsumer();
133+
logger = new NewLogger(this);
131134
}
132135

133136
public void setContext(Context context) {
@@ -384,7 +387,7 @@ public void onDataMessageReceived(String message) {
384387
if(obj.has("currentState"))
385388
currentState = PlayerState.getState(obj.getString("currentState"));
386389
if(listener != null)
387-
listener.onTimeUpdate(currentState, obj.getInt("currentTime"));
390+
listener.onTimeUpdate(currentState, position);
388391
} else if(obj.has("event") && obj.getString("event").equals(RECEIVER_EVENTS.PLAYLIST_ADVANCE) && obj.has("media") && obj.has("type")) {
389392
Logger.d("[CastPlayerManager] playlistAdvance");
390393
if(obj.getString("type").equals(PARAMS.MEDIA_TYPE_VIDEO))
@@ -394,7 +397,6 @@ public void onDataMessageReceived(String message) {
394397
if(listener != null)
395398
listener.onMediaChanged(nowPlayingMedia, PlayerState.PLAYING);
396399
} else if(obj.has("event") && obj.getString("event").equals(RECEIVER_EVENTS.GET_PLAYBACK_STATE) && obj.has("state")) {
397-
Logger.d("Got playback state back: %s", obj.getString("state"));
398400
PlayerState oldState = currentState;
399401
currentState = PlayerState.getState(obj.getString("state"));
400402
if(obj.has("media") && obj.has("type") && obj.has("client")) {

mobile/src/main/java/com/atomjack/vcfp/activities/MainActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ protected void onCreate(Bundle savedInstanceState) {
317317
subscribed = true;
318318
VoiceControlForPlexApplication.getInstance().localClientSubscription.subscribed = true;
319319
} else if (client.isCastClient) {
320-
castPlayerManager.subscribe(client, !castPlayerManager.isSubscribed());
320+
if(!castPlayerManager.isSubscribed())
321+
castPlayerManager.subscribe(client, !castPlayerManager.isSubscribed());
321322
} else {
322323
plexSubscription.subscribe(client, !plexSubscription.isSubscribed());
323324
}

mobile/src/main/java/com/atomjack/vcfp/fragments/PlayerFragment.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -651,17 +651,19 @@ public void onStartTrackingTouch(SeekBar seekBar) {
651651
}
652652

653653
public void setState(PlayerState newState) {
654-
currentState = newState;
655-
if(playPauseSpinner != null && playButton != null && pauseButton != null) {
656-
playPauseSpinner.setVisibility(View.INVISIBLE);
657-
playButton.setVisibility(View.INVISIBLE);
658-
pauseButton.setVisibility(View.INVISIBLE);
659-
if (currentState == PlayerState.PAUSED) {
660-
playButton.setVisibility(View.VISIBLE);
661-
} else if (currentState == PlayerState.PLAYING) {
662-
pauseButton.setVisibility(View.VISIBLE);
663-
} else {
664-
playPauseSpinner.setVisibility(View.VISIBLE);
654+
if(currentState != newState) {
655+
currentState = newState;
656+
if (playPauseSpinner != null && playButton != null && pauseButton != null) {
657+
playPauseSpinner.setVisibility(View.INVISIBLE);
658+
playButton.setVisibility(View.INVISIBLE);
659+
pauseButton.setVisibility(View.INVISIBLE);
660+
if (currentState == PlayerState.PAUSED) {
661+
playButton.setVisibility(View.VISIBLE);
662+
} else if (currentState == PlayerState.PLAYING) {
663+
pauseButton.setVisibility(View.VISIBLE);
664+
} else {
665+
playPauseSpinner.setVisibility(View.VISIBLE);
666+
}
665667
}
666668
}
667669
}

0 commit comments

Comments
 (0)