Skip to content

Commit 15ca81b

Browse files
author
Chris Bellew
committed
When finding an active connection, re-save the server to the master list of servers so that connection is used the next time around, and use the server from the master list if it is the server to be used in a voice query. Use media type when seeking (seems to be needed for Roku).
1 parent 9fbbfe5 commit 15ca81b

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,11 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve
529529
}
530530

531531
protected int getOrientation() {
532-
return getResources().getConfiguration().orientation;
532+
533+
try {
534+
return getResources().getConfiguration().orientation;
535+
} catch (Exception e) {}
536+
return Configuration.ORIENTATION_PORTRAIT;
533537
}
534538

535539
// The follow methods are defined in the PlexPlayerFragment and CastPlayerFragment subclasses

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
2626
@Override
2727
protected void doRewind() {
2828
if(position > -1) {
29-
client.seekTo((position * 1000) - 15000, null);
29+
client.seekTo((position * 1000) - 15000, nowPlayingMedia.isMusic() ? "music" : "video", null);
3030
}
3131
}
3232

3333
@Override
3434
protected void doForward() {
3535
if(position > -1) {
36-
client.seekTo((position * 1000) + 30000, null);
36+
client.seekTo((position * 1000) + 30000, nowPlayingMedia.isMusic() ? "music" : "video", null);
3737
}
3838
}
3939

@@ -63,7 +63,7 @@ protected void doPrevious() {
6363

6464
@Override
6565
public void onStopTrackingTouch(SeekBar _seekBar) {
66-
client.seekTo(_seekBar.getProgress()*1000, new PlexHttpResponseHandler() {
66+
client.seekTo(_seekBar.getProgress()*1000, nowPlayingMedia.isMusic() ? "music" : "video", new PlexHttpResponseHandler() {
6767
@Override
6868
public void onSuccess(PlexResponse response) {
6969
isSeeking = false;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public PlexClient[] newArray(int size) {
8080
}
8181
};
8282

83-
public void seekTo(int offset, PlexHttpResponseHandler responseHandler) {
84-
PlexHttpClient.get(String.format("http://%s:%s", address, port), String.format("player/playback/seekTo?commandID=0&offset=%s", offset), responseHandler);
83+
public void seekTo(int offset, String type, PlexHttpResponseHandler responseHandler) {
84+
PlexHttpClient.get(String.format("http://%s:%s", address, port), String.format("player/playback/seekTo?commandID=0&type=%s&offset=%s", type, offset), responseHandler);
8585
}
8686

8787
public void pause(PlexHttpResponseHandler responseHandler) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public void findServerConnection(final ActiveConnectionHandler activeConnectionH
181181
if(activeConnectionExpires != null && activeConnectionExpires.before(Calendar.getInstance())) {
182182
activeConnectionHandler.onSuccess(activeConnection);
183183
} else {
184-
Logger.d("[PlexServer] finding server connection for %s, current active connection expires %s, number of connections: %d", name, activeConnectionExpires, connections.size());
184+
Logger.d("[PlexServer] finding server connection for %s, current active connection expires: %s, number of connections: %d", name, activeConnectionExpires, connections.size());
185185
findServerConnection(0, activeConnectionHandler);
186186
}
187187
}
@@ -196,6 +196,8 @@ public void onFinish(int statusCode, boolean available) {
196196
activeConnection = connections.get(connectionIndex);
197197
activeConnectionExpires = Calendar.getInstance();
198198
activeConnectionExpires.set(Calendar.HOUR, 1);
199+
VoiceControlForPlexApplication.servers.put(name, PlexServer.this);
200+
VoiceControlForPlexApplication.getInstance().prefs.put(Preferences.SAVED_SERVERS, VoiceControlForPlexApplication.gsonWrite.toJson(VoiceControlForPlexApplication.servers));
199201
activeConnectionHandler.onSuccess(activeConnection);
200202
} else {
201203
int newConnectionIndex = connectionIndex + 1;

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,21 @@ private void startup() {
334334
// got a specified server and client from a shortcut
335335
Logger.d("Got hardcoded server and client from shortcut with %d music sections", specifiedServer.musicSections.size());
336336
plexmediaServers = new ConcurrentHashMap<>();
337-
plexmediaServers.put(specifiedServer.name, specifiedServer);
337+
// If the chosen server exists in the master list of servers, use that one as it will have the last time a connection scan was done
338+
if(VoiceControlForPlexApplication.servers.containsKey(specifiedServer.name))
339+
plexmediaServers.put(specifiedServer.name, VoiceControlForPlexApplication.servers.get(specifiedServer.name));
340+
else
341+
plexmediaServers.put(specifiedServer.name, specifiedServer);
338342
setClient();
339343
} else if(specifiedServer == null && defaultServer != null && !defaultServer.name.equals(getResources().getString(R.string.scan_all))) {
340344
// Use the server specified in the main settings
341345
Logger.d("Using server and client specified in main settings");
342346
plexmediaServers = new ConcurrentHashMap<>();
343-
plexmediaServers.put(defaultServer.name, defaultServer);
347+
// If the chosen server exists in the master list of servers, use that one as it will have the last time a connection scan was done
348+
if(VoiceControlForPlexApplication.servers.containsKey(defaultServer.name))
349+
plexmediaServers.put(defaultServer.name, VoiceControlForPlexApplication.servers.get(defaultServer.name));
350+
else
351+
plexmediaServers.put(defaultServer.name, defaultServer);
344352
setClient();
345353
} else {
346354
// Scan All was chosen
@@ -993,7 +1001,7 @@ private void seekTo(int offset) {
9931001
if(client.isCastClient) {
9941002
castPlayerManager.seekTo(offset / 1000);
9951003
} else {
996-
client.seekTo(offset, new PlexHttpResponseHandler() {
1004+
client.seekTo(offset, plexSubscription.getNowPlayingMedia().isMusic() ? "music" : "video", new PlexHttpResponseHandler() {
9971005
@Override
9981006
public void onSuccess(PlexResponse r) {
9991007
Boolean passed = true;

0 commit comments

Comments
 (0)