14
14
import com .atomjack .vcfp .model .PlexTrack ;
15
15
import com .atomjack .vcfp .model .PlexVideo ;
16
16
import com .google .android .gms .cast .ApplicationMetadata ;
17
- import com .google .sample . castcompanionlibrary .cast .VideoCastManager ;
17
+ import com .google .android . libraries . cast . companionlibrary .cast .VideoCastManager ;
18
18
19
19
import org .json .JSONObject ;
20
20
@@ -96,14 +96,18 @@ public void setContext(Context context) {
96
96
97
97
public void subscribe (final PlexClient _client ) {
98
98
if (castManager == null ) {
99
+ Logger .d ("creating castManager" );
99
100
castManager = getCastManager (mContext );
100
101
castManager .addVideoCastConsumer (castConsumer );
101
102
castManager .incrementUiCounter ();
102
103
}
103
104
if (castManager .isConnected ()) {
104
105
castManager .disconnect ();
105
106
}
106
- castManager .setDevice (_client .castDevice );
107
+ Logger .d ("selecting device: %s" , _client .castDevice );
108
+ castManager .onDeviceSelected (_client .castDevice );
109
+ // castManager.setDevice(_client.castDevice);
110
+ Logger .d ("device selected" );
107
111
castConsumer .setOnConnected (new Runnable () {
108
112
@ Override
109
113
public void run () {
@@ -140,7 +144,7 @@ public void run() {
140
144
}
141
145
142
146
public boolean isSubscribed () {
143
- Logger .d ("[CastPlayerManager] subscribed: %s, mClient : %s" , subscribed , mClient );
147
+ Logger .d ("[CastPlayerManager] subscribed: %s, client : %s" , subscribed , mClient );
144
148
return subscribed && mClient != null ;
145
149
}
146
150
@@ -177,6 +181,7 @@ public interface CastListener {
177
181
void onCastPlayerPlaylistAdvance (PlexMedia media );
178
182
void onCastPlayerState (PlayerState state , PlexMedia media );
179
183
void onCastConnectionFailed ();
184
+ void onCastSeek ();
180
185
PlexMedia getNowPlayingMedia ();
181
186
};
182
187
@@ -186,6 +191,7 @@ public VideoCastManager getCastManager() {
186
191
187
192
// This will send a message to the cast device to load the passed in media
188
193
public void loadMedia (PlexMedia media , List <PlexMedia > album , final int offset ) {
194
+ Logger .d ("Loading media" );
189
195
nowPlayingMedia = media ;
190
196
nowPlayingAlbum = album ;
191
197
nowPlayingMedia .server .findServerConnection (new ActiveConnectionHandler () {
@@ -229,12 +235,13 @@ public void onSuccess(Connection connection) {
229
235
obj .put (PARAMS .SRC , getTranscodeUrl (nowPlayingMedia , connection , seconds ));
230
236
obj .put (PARAMS .RESUME , VoiceControlForPlexApplication .getInstance ().prefs .get (Preferences .RESUME , false ));
231
237
sendMessage (obj );
238
+ listener .onCastSeek ();
232
239
} catch (Exception ex ) {}
233
240
}
234
241
235
242
@ Override
236
243
public void onFailure (int statusCode ) {
237
-
244
+ // TODO: Handle failure
238
245
}
239
246
});
240
247
}
@@ -277,16 +284,17 @@ private void sendMessage(JSONObject obj) {
277
284
278
285
private static VideoCastManager getCastManager (Context context ) {
279
286
if (null == castManager ) {
280
- castManager = VideoCastManager .initialize (context , BuildConfig .CHROMECAST_APP_ID ,
281
- null , "urn:x-cast:com.atomjack.vcfp" );
282
- castManager .enableFeatures (
283
- VideoCastManager .FEATURE_NOTIFICATION |
284
- VideoCastManager .FEATURE_LOCKSCREEN |
285
- VideoCastManager .FEATURE_DEBUGGING );
287
+ VideoCastManager .initialize (context , BuildConfig .CHROMECAST_APP_ID ,
288
+ null , "urn:x-cast:com.atomjack.vcfp" )
289
+ .enableFeatures (
290
+ VideoCastManager .FEATURE_NOTIFICATION |
291
+ VideoCastManager .FEATURE_LOCKSCREEN |
292
+ VideoCastManager .FEATURE_DEBUGGING );
286
293
287
294
}
288
295
// castManager.setContext(context);
289
- castManager .setStopOnDisconnect (true );
296
+ castManager = VideoCastManager .getInstance ();
297
+ castManager .setStopOnDisconnect (false );
290
298
return castManager ;
291
299
}
292
300
@@ -388,10 +396,9 @@ public void onApplicationStatusChanged(String appStatus) {
388
396
}
389
397
390
398
@ Override
391
- public boolean onApplicationConnectionFailed (int errorCode ) {
399
+ public void onApplicationConnectionFailed (int errorCode ) {
392
400
Logger .d ("[CastPlayerManager] onApplicationConnectionFailed: %d" , errorCode );
393
401
listener .onCastConnectionFailed ();
394
- return false ;
395
402
}
396
403
397
404
@ Override
@@ -408,6 +415,7 @@ public void onCastDeviceDetected(final MediaRouter.RouteInfo info) {
408
415
}
409
416
410
417
public String getTranscodeUrl (PlexMedia media , Connection connection , int offset ) {
418
+ Logger .d ("getTranscodeUrl, offset: %d" , offset );
411
419
String url = connection .uri ;
412
420
url += String .format ("/%s/:/transcode/universal/start?" , media instanceof PlexVideo ? "video" : "audio" );
413
421
QueryString qs = new QueryString ("path" , String .format ("http://127.0.0.1:32400%s" , media .key ));
@@ -416,11 +424,13 @@ public String getTranscodeUrl(PlexMedia media, Connection connection, int offset
416
424
qs .add ("protocol" , "http" );
417
425
qs .add ("offset" , Integer .toString (offset ));
418
426
qs .add ("fastSeek" , "1" );
427
+ // String[] videoQuality = VoiceControlForPlexApplication.chromecastVideoOptions.get(VoiceControlForPlexApplication.getInstance().prefs.getString(connection.local ? Preferences.CHROMECAST_VIDEO_QUALITY_LOCAL : Preferences.CHROMECAST_VIDEO_QUALITY_REMOTE));
428
+ // qs.add("directPlay", videoQuality.length == 3 && videoQuality[2] == "1" ? "1" : "0");
419
429
qs .add ("directPlay" , "0" );
420
430
qs .add ("directStream" , "1" );
421
431
qs .add ("videoQuality" , "60" );
422
- qs .add ("videoResolution " , "1024x768" );
423
- qs .add ("maxVideoBitrate " , "2000" );
432
+ qs .add ("maxVideoBitrate " , VoiceControlForPlexApplication . chromecastVideoOptions . get ( VoiceControlForPlexApplication . getInstance (). prefs . getString ( connection . local ? Preferences . CHROMECAST_VIDEO_QUALITY_LOCAL : Preferences . CHROMECAST_VIDEO_QUALITY_REMOTE ))[ 0 ] );
433
+ qs .add ("videoResolution " , VoiceControlForPlexApplication . chromecastVideoOptions . get ( VoiceControlForPlexApplication . getInstance (). prefs . getString ( connection . local ? Preferences . CHROMECAST_VIDEO_QUALITY_LOCAL : Preferences . CHROMECAST_VIDEO_QUALITY_REMOTE ))[ 1 ] );
424
434
qs .add ("subtitleSize" , "100" );
425
435
qs .add ("audioBoost" , "100" );
426
436
qs .add ("session" , mSessionId );
@@ -462,6 +472,7 @@ public JSONObject buildMedia(Connection connection, int offset) {
462
472
data .put (PARAMS .CLIENT , VoiceControlForPlexApplication .gsonWrite .toJson (mClient ));
463
473
data .put (PARAMS .SRC , getTranscodeUrl (nowPlayingMedia , connection , offset ));
464
474
data .put (PARAMS .ACCESS_TOKEN , nowPlayingMedia .server .accessToken );
475
+ Logger .d ("token: %s" , nowPlayingMedia .server .accessToken );
465
476
data .put (PARAMS .PLAYLIST , getPlaylistJson ());
466
477
} catch (Exception ex ) {
467
478
ex .printStackTrace ();
@@ -477,6 +488,10 @@ public PlayerState getCurrentState() {
477
488
return currentState ;
478
489
}
479
490
491
+ public void setNowPlayingMedia (PlexMedia nowPlayingMedia ) {
492
+ this .nowPlayingMedia = nowPlayingMedia ;
493
+ }
494
+
480
495
public PlexMedia getNowPlayingMedia () {
481
496
return nowPlayingMedia ;
482
497
}
0 commit comments