Skip to content

Commit 5de953f

Browse files
author
Chris Bellew
committed
Account for OpenPHT returning incorrect Timeline with state of playing after music playback is stopped. Since a new piece of media is fetched, onPlayStarted should not be called if a new stopped Timeline has been received before the previous incorrect Timeline is finished processing. Also added way to compare two instances of PlexMedia by key.
1 parent b1be2e3 commit 5de953f

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

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

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

66
import com.atomjack.shared.Logger;
7+
import com.atomjack.shared.NewLogger;
78
import com.atomjack.shared.PlayerState;
89
import com.atomjack.shared.model.Timeline;
910
import com.atomjack.vcfp.interfaces.PlexMediaHandler;
@@ -41,6 +42,7 @@
4142
import java.util.regex.Pattern;
4243

4344
public class PlexSubscription {
45+
private NewLogger logger;
4446
private static final int SUBSCRIBE_INTERVAL = 30000; // Send subscribe message every 30 seconds to keep us alive
4547

4648
private static Serializer serial = new Persister();
@@ -74,6 +76,7 @@ public class PlexSubscription {
7476

7577
public PlexSubscription() {
7678
mHandler = new Handler();
79+
logger = new NewLogger(this);
7780
}
7881

7982
public void setListener(PlexSubscriptionListener _listener) {
@@ -472,13 +475,15 @@ public void onSuccess(MediaContainer playlistMediaContainer) {
472475
if(media != null) {
473476
if(nowPlayingMedia != null) // if we're already playing media, this new media we found is different, so notify the listener
474477
listener.onMediaChanged(media, PlayerState.getState(timeline));
475-
else
478+
else if(currentState != PlayerState.STOPPED){ // edge case where we receive a new timeline with a state of stopped after this one, but before this one has finished processing
476479
listener.onPlayStarted(media, nowPlayingPlaylist, PlayerState.getState(timeline));
480+
}
477481
} else {
478482
// TODO: Handle not finding any media?
479483
}
480484
nowPlayingMedia = media;
481-
VoiceControlForPlexApplication.getInstance().setNotification(mClient, currentState, nowPlayingMedia, nowPlayingPlaylist);
485+
if(currentState != PlayerState.STOPPED)
486+
VoiceControlForPlexApplication.getInstance().setNotification(mClient, currentState, nowPlayingMedia, nowPlayingPlaylist);
482487
}
483488

484489
@Override

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,13 @@ protected void onResume() {
715715
}
716716
}
717717

718+
// If we get unsubscribed from the notification, and the app isn't visible, the next time we show up the app will think it's still subscribed, so we have to set the UI to be unsubbed
719+
if(!isSubscribed()) {
720+
switchToMainFragment();
721+
setCastIconInactive();
722+
prefs.remove(Preferences.SUBSCRIBED_CLIENT);
723+
}
724+
718725
if(musicPlayerIsBound)
719726
bindMusicPlayerService();
720727
if(musicPlayerFragment != null && musicPlayerFragment.isVisible())

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,5 +320,17 @@ public String getImageKey(IMAGE_KEY imageKey) {
320320
}
321321
}
322322

323+
@Override
324+
public boolean equals(Object o) {
325+
return key.equals(((PlexMedia)o).key);
326+
}
327+
328+
@Override
329+
public int hashCode() {
330+
final int prime = 37;
331+
int result = 1;
332+
result = prime * result + ((key == null) ? 0 : key.hashCode());
333+
return result;
334+
}
323335
}
324336

0 commit comments

Comments
 (0)