@@ -59,6 +59,8 @@ public class PlexSearchService extends Service {
59
59
private List <PlexTrack > tracks = new ArrayList <PlexTrack >();
60
60
private List <PlexDirectory > albums = new ArrayList <PlexDirectory >();
61
61
62
+ private boolean didClientScan = false ;
63
+
62
64
private ArrayList <String > queries ;
63
65
// Will be set to true after we scan for servers, so we don't have to do it again on the next query
64
66
private boolean didServerScan = false ;
@@ -90,13 +92,25 @@ public int onStartCommand(Intent intent, int flags, int startId) {
90
92
}
91
93
92
94
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
+ }
100
114
} else {
101
115
queryText = null ;
102
116
client = null ;
@@ -183,6 +197,23 @@ public IBinder onBind(Intent intent) {
183
197
private void startup () {
184
198
queryText = queries .remove (0 );
185
199
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
+
186
217
Logger .d ("Starting up with query string: %s" , queryText );
187
218
tracks = new ArrayList <PlexTrack >();
188
219
videos = new ArrayList <PlexVideo >();
0 commit comments