Skip to content

Commit 5b910cc

Browse files
author
Chris Bellew
committed
Fixes for setting streams. Fixed finding server connection so the active connection is set to expire at the correct time. Always attempt to get transient token.
1 parent 144b892 commit 5b910cc

File tree

5 files changed

+47
-28
lines changed

5 files changed

+47
-28
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -773,8 +773,6 @@ public static QueryString getPlaybackQueryString(PlexMedia media,
773773
qs.add("port", connection.port);
774774
qs.add("address", connection.address);
775775

776-
if (resumePlayback && media.viewOffset != null)
777-
qs.add("viewOffset", media.viewOffset);
778776
if (transientToken != null)
779777
qs.add("token", transientToken);
780778
if (media.server.accessToken != null)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,12 @@ public void setStream(Stream stream) {
176176
} else if (stream.streamType == Stream.SUBTITLE) {
177177
qs.put("subtitleStreamID", stream.id);
178178
}
179-
Call<PlexResponse> call = service.setStreams(qs);
179+
Call<PlexResponse> call = service.setStreams(qs, "0", VoiceControlForPlexApplication.getInstance().getUUID());
180180
call.enqueue(new Callback<PlexResponse>() {
181181
@Override
182182
public void onResponse(Response<PlexResponse> response) {
183-
Logger.d("setStream response: %s", response.body().status);
183+
if(response.body() != null)
184+
Logger.d("setStream response: %s", response.body().status);
184185
}
185186

186187
@Override

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.simpleframework.xml.Root;
2020

21+
import java.text.SimpleDateFormat;
2122
import java.util.ArrayList;
2223
import java.util.Calendar;
2324
import java.util.List;
@@ -178,10 +179,14 @@ public PlexServer[] newArray(int size) {
178179
};
179180

180181
public void findServerConnection(final ActiveConnectionHandler activeConnectionHandler) {
181-
if(activeConnectionExpires != null && activeConnectionExpires.before(Calendar.getInstance())) {
182+
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEEE, MMMM d, yyyy 'at' h:mm:ss a");
183+
Logger.d("[PlexServer] finding server connection for %s, current active connection expires: %s, now: %s",
184+
name,
185+
simpleDateFormat.format(activeConnectionExpires.getTime()),
186+
simpleDateFormat.format(Calendar.getInstance().getTime()));
187+
if(activeConnectionExpires != null && !activeConnectionExpires.before(Calendar.getInstance())) {
182188
activeConnectionHandler.onSuccess(activeConnection);
183189
} else {
184-
Logger.d("[PlexServer] finding server connection for %s, current active connection expires: %s, number of connections: %d", name, activeConnectionExpires, connections.size());
185190
findServerConnection(0, activeConnectionHandler);
186191
}
187192
}
@@ -194,8 +199,9 @@ public void onFinish(int statusCode, boolean available) {
194199
if (available) {
195200
// This connection replied, so let's use it
196201
activeConnection = connections.get(connectionIndex);
202+
Logger.d("Found connection for %s: %s", name, activeConnection);
197203
activeConnectionExpires = Calendar.getInstance();
198-
activeConnectionExpires.set(Calendar.HOUR, 1);
204+
activeConnectionExpires.add(Calendar.HOUR_OF_DAY, 1);
199205
VoiceControlForPlexApplication.servers.put(name, PlexServer.this);
200206
VoiceControlForPlexApplication.getInstance().prefs.put(Preferences.SAVED_SERVERS, VoiceControlForPlexApplication.gsonWrite.toJson(VoiceControlForPlexApplication.servers));
201207
activeConnectionHandler.onSuccess(activeConnection);

mobile/src/main/java/com/atomjack/vcfp/net/PlexHttpClient.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Call<PlexResponse> adjustPlayback(@Path(value="which", encoded=true) String whic
9898

9999
@GET("/player/playback/seekTo")
100100
Call<PlexResponse> seekTo(@Query("offset") int offset,
101-
@Query("commandID") String commandId,
101+
@Query(PlexHeaders.commandID) String commandId,
102102
@retrofit.http.Header(PlexHeaders.XPlexClientIdentifier) String clientId);
103103

104104
@GET("/library/sections")
@@ -108,7 +108,9 @@ Call<PlexResponse> seekTo(@Query("offset") int offset,
108108
Call<MediaContainer> getResources(@Query(PlexHeaders.XPlexToken) String accessToken);
109109

110110
@GET("/player/playback/setStreams")
111-
Call<PlexResponse> setStreams(@QueryMap Map<String, String> options);
111+
Call<PlexResponse> setStreams(@QueryMap Map<String, String> options,
112+
@Query(PlexHeaders.commandID) String commandId,
113+
@retrofit.http.Header(PlexHeaders.XPlexClientIdentifier) String clientId);
112114

113115
@GET("/users/account.xml")
114116
Call<PlexUser> getPlexAccount(@retrofit.http.Header(PlexHeaders.XPlexToken) String authToken);
@@ -259,12 +261,20 @@ public void onFailure(int statusCode) {
259261
});
260262
}
261263

262-
public static void get(final PlexServer server, final String path, final PlexHttpMediaContainerHandler responseHandler) {
264+
public static void getDebug(final PlexServer server, final String path, final PlexHttpMediaContainerHandler responseHandler) {
265+
get(server, path, true, responseHandler);
266+
}
267+
268+
public static void get(final PlexServer server, final String path, final PlexHttpMediaContainerHandler responseHandler) {
269+
get(server, path, false, responseHandler);
270+
}
271+
272+
public static void get(final PlexServer server, final String path, final boolean debug, final PlexHttpMediaContainerHandler responseHandler) {
263273
server.findServerConnection(new ActiveConnectionHandler() {
264274
@Override
265275
public void onSuccess(Connection connection) {
266276

267-
PlexHttpService service = getService(connection.uri);
277+
PlexHttpService service = getService(connection.uri, debug);
268278
// Logger.d("using path %s %s", connection.uri, path.substring(1));
269279
Call<MediaContainer> call = service.getMediaContainer(path.substring(1), server.accessToken);
270280
call.enqueue(new Callback<MediaContainer>() {
@@ -431,8 +441,16 @@ public void onFailure(Throwable t) {
431441
});
432442
}
433443

444+
public static void getDebug(String baseHostname, String path, final PlexHttpResponseHandler responseHandler) {
445+
get(baseHostname, path, true, responseHandler);
446+
}
447+
434448
public static void get(String baseHostname, String path, final PlexHttpResponseHandler responseHandler) {
435-
PlexHttpService service = getService(baseHostname);
449+
get(baseHostname, path, false, responseHandler);
450+
}
451+
452+
public static void get(String baseHostname, String path, boolean debug, final PlexHttpResponseHandler responseHandler) {
453+
PlexHttpService service = getService(baseHostname, debug);
436454
Call<PlexResponse> call = service.getPlexResponse(VoiceControlForPlexApplication.getInstance().prefs.getUUID(),
437455
path.replaceFirst("^/", ""));
438456
call.enqueue(new Callback<PlexResponse>() {

mobile/src/main/java/com/atomjack/vcfp/services/PlexSearchService.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,23 +1203,19 @@ private void playMedia(final PlexMedia media) {
12031203
}
12041204

12051205
private void playMedia(final PlexMedia media, final PlexDirectory album) {
1206-
if(media.server.owned)
1207-
createPlayQueueAndPlayMedia(media, album, null);
1208-
else {
1209-
// TODO: switch this to the PlexServer method and verify
1210-
requestTransientAccessToken(media.server, new AfterTransientTokenRequest() {
1211-
@Override
1212-
public void success(String token) {
1213-
createPlayQueueAndPlayMedia(media, album, token);
1214-
}
1206+
// TODO: switch this to the PlexServer method and verify
1207+
requestTransientAccessToken(media.server, new AfterTransientTokenRequest() {
1208+
@Override
1209+
public void success(String token) {
1210+
createPlayQueueAndPlayMedia(media, album, token);
1211+
}
12151212

1216-
@Override
1217-
public void failure() {
1218-
// Just try to play without a transient token
1219-
createPlayQueueAndPlayMedia(media, album, null);
1220-
}
1221-
});
1222-
}
1213+
@Override
1214+
public void failure() {
1215+
// Just try to play without a transient token
1216+
createPlayQueueAndPlayMedia(media, album, null);
1217+
}
1218+
});
12231219
}
12241220

12251221
private void playAllFromArtist(final PlexDirectory artist) {

0 commit comments

Comments
 (0)