Skip to content

Commit 651e68a

Browse files
author
Chris Bellew
committed
When stopping playback, need to compare clients properly to determine if we should unsubscribe from the client we just got done playing to.
1 parent 137b309 commit 651e68a

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,12 +412,13 @@ public void onStateChanged(PlexMedia media, PlayerState state) {
412412
handler.removeCallbacks(autoDisconnectPlayerTimer);
413413
if(playerFragment != null && playerFragment.isVisible()) {
414414
if(state == PlayerState.STOPPED) {
415-
logger.d("onStopped");
416415
VoiceControlForPlexApplication.getInstance().cancelNotification();
417416
switchToMainFragment();
418-
if(plexSubscription.isSubscribed() && plexSubscription.getClient() != gsonRead.fromJson(prefs.get(Preferences.CLIENT, ""), PlexClient.class))
417+
// We've stopped, so if we're still subscribed and the client we stopped playing to is different from the default client, unsubscribe, since
418+
// the main screen UI says it is ready to cast to the default client, not the client we just got finished playing to.
419+
if(plexSubscription.isSubscribed() && !plexSubscription.getClient().equals(gsonRead.fromJson(prefs.get(Preferences.CLIENT, ""), PlexClient.class)))
419420
plexSubscription.unsubscribe();
420-
if(castPlayerManager.isSubscribed() && castPlayerManager.getClient() != gsonRead.fromJson(prefs.get(Preferences.CLIENT, ""), PlexClient.class))
421+
if(castPlayerManager.isSubscribed() && !castPlayerManager.getClient().equals(gsonRead.fromJson(prefs.get(Preferences.CLIENT, ""), PlexClient.class)))
421422
castPlayerManager.unsubscribe();
422423
} else {
423424
playerFragment.setState(state);

mobile/src/main/java/com/atomjack/vcfp/model/PlexClient.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public static PlexClient getLocalPlaybackClient() {
4747
client.isLocalClient = true;
4848
client.name = VoiceControlForPlexApplication.getInstance().getString(R.string.this_device);
4949
client.product = VoiceControlForPlexApplication.getInstance().getString(R.string.app_name);
50+
client.machineIdentifier = VoiceControlForPlexApplication.getInstance().getUUID();
5051
return client;
5152
}
5253

mobile/src/main/java/com/atomjack/vcfp/model/PlexDevice.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,29 @@ public PlexDevice() {
4040
}
4141

4242

43+
@Override
44+
public boolean equals(Object o) {
45+
if(this == o)
46+
return true;
47+
if(o == null)
48+
return false;
49+
if(getClass() != o.getClass())
50+
return false;
51+
PlexDevice other = (PlexDevice)o;
52+
if(machineIdentifier == null) {
53+
if (other.machineIdentifier != null)
54+
return false;
55+
} else if(!machineIdentifier.equals(other.machineIdentifier))
56+
return false;
57+
return true;
58+
}
4359

60+
@Override
61+
public int hashCode() {
62+
final int prime = 67;
63+
int result = 1;
64+
result = prime * result + ((machineIdentifier == null) ? 0 : machineIdentifier.hashCode());
65+
return result;
66+
}
4467

4568
}

0 commit comments

Comments
 (0)