@@ -59,20 +59,35 @@ public class PlayMediaActivity extends Activity implements TextToSpeech.OnInitLi
59
59
private List <PlexDirectory > albums = new ArrayList <PlexDirectory >();
60
60
private TextToSpeech mTts = null ;
61
61
private String ttsDelayedFeedback = null ;
62
+ private PlexVideo playingVideo ; // The video currently playing
63
+ private PlexTrack playingTrack ; // The track currently playing
62
64
63
65
protected void onCreate (Bundle savedInstanceState ) {
64
66
Logger .d ("on create PlayMediaActivity" );
65
67
super .onCreate (savedInstanceState );
66
68
67
-
68
69
BugSenseHandler .initAndStartSession (PlayMediaActivity .this , MainActivity .BUGSENSE_APIKEY );
69
70
70
71
mPrefs = getSharedPreferences (PREFS , MODE_PRIVATE );
71
72
72
73
setContentView (R .layout .play_media );
73
- Intent intent = getIntent ();
74
- this .queryText = intent .getStringExtra ("queryText" );
75
- startup ();
74
+ if (savedInstanceState == null ) {
75
+ playingVideo = null ;
76
+ playingTrack = null ;
77
+ client = null ;
78
+ Intent intent = getIntent ();
79
+ this .queryText = intent .getStringExtra ("queryText" );
80
+ startup ();
81
+ } else {
82
+ Logger .d ("found saved instance state" );
83
+ playingVideo = savedInstanceState .getParcelable ("video" );
84
+ playingTrack = savedInstanceState .getParcelable ("track" );
85
+ client = savedInstanceState .getParcelable ("client" );
86
+ if (playingVideo != null )
87
+ showPlayingVideo ();
88
+ else if (playingTrack != null )
89
+ showPlayingTrack ();
90
+ }
76
91
}
77
92
78
93
@ Override
@@ -1239,7 +1254,7 @@ public void onSuccess(MediaContainer mc)
1239
1254
track .album = album .title ;
1240
1255
playTrack (track , album );
1241
1256
} else {
1242
- Logger .d ("Didn't find a video " );
1257
+ Logger .d ("Didn't find any tracks " );
1243
1258
feedback (getResources ().getString (R .string .couldnt_find_album ));
1244
1259
searchDialog .dismiss ();
1245
1260
finish ();
@@ -1281,19 +1296,8 @@ public void onSuccess(PlexResponse r)
1281
1296
}
1282
1297
Logger .d ("Playback response: %s" , r .code );
1283
1298
if (passed ) {
1284
- setContentView (R .layout .now_playing_music );
1285
-
1286
- TextView artist = (TextView )findViewById (R .id .nowPlayingArtist );
1287
- artist .setText (track .artist );
1288
- TextView album = (TextView )findViewById (R .id .nowPlayingAlbum );
1289
- album .setText (track .album );
1290
- TextView title = (TextView )findViewById (R .id .nowPlayingTitle );
1291
- title .setText (track .title );
1292
-
1293
- TextView nowPlayingOnClient = (TextView )findViewById (R .id .nowPlayingOnClient );
1294
- nowPlayingOnClient .setText (getResources ().getString (R .string .now_playing_on ) + " " + client .name );
1295
-
1296
- PlexHttpClient .setThumb (track , (ImageView )findViewById (R .id .nowPlayingImage ));
1299
+ playingTrack = track ;
1300
+ showPlayingTrack ();
1297
1301
} else {
1298
1302
searchDialog .dismiss ();
1299
1303
feedback (getResources ().getString (R .string .http_status_code_error ), r .code );
@@ -1310,6 +1314,24 @@ public void onFailure(Throwable error) {
1310
1314
});
1311
1315
}
1312
1316
1317
+ private void showPlayingTrack () {
1318
+ if (playingTrack == null )
1319
+ return ;
1320
+ setContentView (R .layout .now_playing_music );
1321
+
1322
+ TextView artist = (TextView )findViewById (R .id .nowPlayingArtist );
1323
+ artist .setText (playingTrack .artist );
1324
+ TextView album = (TextView )findViewById (R .id .nowPlayingAlbum );
1325
+ album .setText (playingTrack .album );
1326
+ TextView title = (TextView )findViewById (R .id .nowPlayingTitle );
1327
+ title .setText (playingTrack .title );
1328
+
1329
+ TextView nowPlayingOnClient = (TextView )findViewById (R .id .nowPlayingOnClient );
1330
+ nowPlayingOnClient .setText (getResources ().getString (R .string .now_playing_on ) + " " + client .name );
1331
+
1332
+ PlexHttpClient .setThumb (playingTrack , (ImageView )findViewById (R .id .nowPlayingImage ));
1333
+ }
1334
+
1313
1335
private void playVideo (final PlexVideo video ) {
1314
1336
Logger .d ("Playing video: %s" , video .title );
1315
1337
try {
@@ -1337,38 +1359,10 @@ public void onSuccess(PlexResponse r)
1337
1359
}
1338
1360
Logger .d ("Playback response: %s" , r .code );
1339
1361
if (passed ) {
1362
+ playingVideo = video ;
1363
+ Logger .d ("duration: %s" , video .getDuration ());
1340
1364
videoPlayed = true ;
1341
- if (video .type .equals ("movie" )) {
1342
- setContentView (R .layout .now_playing_movie );
1343
- TextView title = (TextView )findViewById (R .id .nowPlayingTitle );
1344
- title .setText (video .title );
1345
- TextView genre = (TextView )findViewById (R .id .nowPlayingGenre );
1346
- genre .setText (video .getGenres ());
1347
- TextView year = (TextView )findViewById (R .id .nowPlayingYear );
1348
- year .setText (video .year );
1349
- TextView duration = (TextView )findViewById (R .id .nowPlayingDuration );
1350
- duration .setText (video .getDuration ());
1351
- TextView summary = (TextView )findViewById (R .id .nowPlayingSummary );
1352
- summary .setText (video .summary );
1353
- } else {
1354
- setContentView (R .layout .now_playing_show );
1355
-
1356
- TextView showTitle = (TextView )findViewById (R .id .nowPlayingShowTitle );
1357
- showTitle .setText (video .showTitle );
1358
- TextView episodeTitle = (TextView )findViewById (R .id .nowPlayingEpisodeTitle );
1359
- episodeTitle .setText (video .title );
1360
- TextView year = (TextView )findViewById (R .id .nowPlayingYear );
1361
- year .setText (video .year );
1362
- TextView duration = (TextView )findViewById (R .id .nowPlayingDuration );
1363
- duration .setText (video .getDuration ());
1364
- TextView summary = (TextView )findViewById (R .id .nowPlayingSummary );
1365
- summary .setText (video .summary );
1366
- }
1367
-
1368
- TextView nowPlayingOnClient = (TextView )findViewById (R .id .nowPlayingOnClient );
1369
- nowPlayingOnClient .setText (getResources ().getString (R .string .now_playing_on ) + " " + client .name );
1370
-
1371
- PlexHttpClient .setThumb (video , (ScrollView )findViewById (R .id .background ));
1365
+ showPlayingVideo ();
1372
1366
} else {
1373
1367
searchDialog .dismiss ();
1374
1368
feedback (getResources ().getString (R .string .http_status_code_error ), r .code );
@@ -1410,6 +1404,41 @@ protected void onResume() {
1410
1404
LocalBroadcastManager .getInstance (this ).registerReceiver (gdmReceiver , filters );
1411
1405
}
1412
1406
1407
+ private void showPlayingVideo () {
1408
+ if (playingVideo == null )
1409
+ return ;
1410
+ if (playingVideo .type .equals ("movie" )) {
1411
+ setContentView (R .layout .now_playing_movie );
1412
+ TextView title = (TextView )findViewById (R .id .nowPlayingTitle );
1413
+ title .setText (playingVideo .title );
1414
+ TextView genre = (TextView )findViewById (R .id .nowPlayingGenre );
1415
+ genre .setText (playingVideo .getGenres ());
1416
+ TextView year = (TextView )findViewById (R .id .nowPlayingYear );
1417
+ year .setText (playingVideo .year );
1418
+ TextView duration = (TextView )findViewById (R .id .nowPlayingDuration );
1419
+ duration .setText (playingVideo .getDuration ());
1420
+ TextView summary = (TextView )findViewById (R .id .nowPlayingSummary );
1421
+ summary .setText (playingVideo .summary );
1422
+ } else {
1423
+ setContentView (R .layout .now_playing_show );
1424
+
1425
+ TextView showTitle = (TextView )findViewById (R .id .nowPlayingShowTitle );
1426
+ showTitle .setText (playingVideo .showTitle );
1427
+ TextView episodeTitle = (TextView )findViewById (R .id .nowPlayingEpisodeTitle );
1428
+ episodeTitle .setText (playingVideo .title );
1429
+ TextView year = (TextView )findViewById (R .id .nowPlayingYear );
1430
+ year .setText (playingVideo .year );
1431
+ TextView duration = (TextView )findViewById (R .id .nowPlayingDuration );
1432
+ duration .setText (playingVideo .getDuration ());
1433
+ TextView summary = (TextView )findViewById (R .id .nowPlayingSummary );
1434
+ summary .setText (playingVideo .summary );
1435
+ }
1436
+
1437
+ TextView nowPlayingOnClient = (TextView )findViewById (R .id .nowPlayingOnClient );
1438
+ nowPlayingOnClient .setText (getResources ().getString (R .string .now_playing_on ) + " " + client .name );
1439
+
1440
+ PlexHttpClient .setThumb (playingVideo , (ScrollView )findViewById (R .id .background ));
1441
+ }
1413
1442
private static Boolean compareTitle (String title , String queryTerm ) {
1414
1443
// First, check if the two terms are equal
1415
1444
if (title .toLowerCase ().equals (queryTerm .toLowerCase ()))
@@ -1424,4 +1453,12 @@ private static Boolean compareTitle(String title, String queryTerm) {
1424
1453
}
1425
1454
return !missing ;
1426
1455
}
1456
+
1457
+ @ Override
1458
+ protected void onSaveInstanceState (Bundle outState ) {
1459
+ super .onSaveInstanceState (outState );
1460
+ outState .putParcelable ("video" , playingVideo );
1461
+ outState .putParcelable ("client" , client );
1462
+ outState .putParcelable ("track" , playingTrack );
1463
+ }
1427
1464
}
0 commit comments