Skip to content

Commit 15505a9

Browse files
author
Chris Bellew
committed
If a client is specified in the spoken query, scan for clients before proceeding, in case the client specified was not running when clients were scanned for in the GUI.
1 parent 9ce82e2 commit 15505a9

File tree

4 files changed

+47
-12
lines changed

4 files changed

+47
-12
lines changed

Voice Control For Plex/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.atomjack.vcfp"
4-
android:versionCode="17"
5-
android:versionName="1.8.2" >
4+
android:versionCode="18"
5+
android:versionName="1.8.3" >
66

77
<uses-permission android:name="com.mohammadag.googlesearchapi.permission.ACCESS_GGOGLE_SEARCH_API" />
88
<uses-permission android:name="android.permission.INTERNET" />

Voice Control For Plex/src/main/java/com/atomjack/vcfp/PlexSearchService.java

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public class PlexSearchService extends Service {
5959
private List<PlexTrack> tracks = new ArrayList<PlexTrack>();
6060
private List<PlexDirectory> albums = new ArrayList<PlexDirectory>();
6161

62+
private boolean didClientScan = false;
63+
6264
private ArrayList<String> queries;
6365
// Will be set to true after we scan for servers, so we don't have to do it again on the next query
6466
private boolean didServerScan = false;
@@ -90,13 +92,25 @@ public int onStartCommand(Intent intent, int flags, int startId) {
9092
}
9193

9294
if(intent.getAction() != null && intent.getAction().equals(VoiceControlForPlexApplication.Intent.GDMRECEIVE)) {
93-
// We just scanned for servers and are returning from that, so set the servers we found
94-
// and then figure out which client to play to
95-
Logger.d("Got back from scanning for servers.");
96-
videoPlayed = false;
97-
plexmediaServers = VoiceControlForPlexApplication.servers;
98-
didServerScan = true;
99-
setClient();
95+
if(intent.getStringExtra(VoiceControlForPlexApplication.Intent.SCAN_TYPE).equals("server")) {
96+
// We just scanned for servers and are returning from that, so set the servers we found
97+
// and then figure out which client to play to
98+
Logger.d("Got back from scanning for servers.");
99+
videoPlayed = false;
100+
plexmediaServers = VoiceControlForPlexApplication.servers;
101+
didServerScan = true;
102+
setClient();
103+
} else if(intent.getStringExtra(VoiceControlForPlexApplication.Intent.SCAN_TYPE).equals("client")) {
104+
// Got back from client scan, so set didClientScan to true so we don't do this again, and save the clients we got, then continue
105+
didClientScan = true;
106+
ArrayList<PlexClient> cs = intent.getParcelableArrayListExtra(VoiceControlForPlexApplication.Intent.EXTRA_CLIENTS);
107+
VoiceControlForPlexApplication.clients = new HashMap<String, PlexClient>();
108+
for(PlexClient c : cs) {
109+
VoiceControlForPlexApplication.clients.put(c.name, c);
110+
}
111+
clients = (HashMap)VoiceControlForPlexApplication.clients;
112+
startup();
113+
}
100114
} else {
101115
queryText = null;
102116
client = null;
@@ -183,6 +197,23 @@ public IBinder onBind(Intent intent) {
183197
private void startup() {
184198
queryText = queries.remove(0);
185199

200+
if(!didClientScan) {
201+
if(queryText.matches(getString(R.string.pattern_on_client))) {
202+
// A client was specified in the query, so let's scan for clients before proceeding.
203+
// First, insert the query text back into the queries array, so we can use it after the scan is done.
204+
queries.add(0, queryText);
205+
Intent mServiceIntent = new Intent(this, GDMService.class);
206+
mServiceIntent.putExtra("port", 32412); // Port for clients
207+
mServiceIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
208+
mServiceIntent.putExtra("ORIGIN", PlexSearchService.class.getSimpleName());
209+
mServiceIntent.putExtra("class", PlexSearchService.class);
210+
mServiceIntent.putExtra(VoiceControlForPlexApplication.Intent.SCAN_TYPE, "client");
211+
startService(mServiceIntent);
212+
return;
213+
}
214+
}
215+
216+
186217
Logger.d("Starting up with query string: %s", queryText);
187218
tracks = new ArrayList<PlexTrack>();
188219
videos = new ArrayList<PlexVideo>();

Voice Control For Plex/src/main/java/com/atomjack/vcfp/activities/MainActivity.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ public void onFailure(int statusCode) {
348348
feedback.e(getResources().getString(R.string.no_wifi_connection_message));
349349
return;
350350
}
351+
VoiceControlForPlexApplication.clients = new HashMap<String, PlexClient>();
351352
localScan.searchForPlexClients();
352353
} else if (holder.tag.equals(holder.TAG_FEEDBACK)) {
353354
selectFeedback();
@@ -717,9 +718,9 @@ public void showUsageExamples(View v) {
717718
usageDialog.setTitle(R.string.help_usage_button);
718719
usageDialog.setMessage(R.string.help_usage);
719720
usageDialog.setPositiveButton(R.string.got_it, new DialogInterface.OnClickListener() {
720-
public void onClick(DialogInterface dialog, int id) {
721-
dialog.dismiss();
722-
}
721+
public void onClick(DialogInterface dialog, int id) {
722+
dialog.dismiss();
723+
}
723724
});
724725
usageDialog.show();
725726
}

Voice Control For Plex/src/main/res/xml/changelog.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<changelog>
3+
<release version="1.8.3" versioncode="18">
4+
<change>Fixed a bug that sometimes prevented playback when a client is specified in the spoken query.</change>
5+
</release>
36
<release version="1.8.2" versioncode="17">
47
<change>Added Pin login.</change>
58
<change>Subscribe to player and exit from Now Playing screen if the player stops.</change>

0 commit comments

Comments
 (0)