Skip to content

Commit 3b6d762

Browse files
author
Chris Bellew
committed
[NowPlayingActivity] Delay checking if we're subscribed/client is playing, as upon first launch it may take a small amount of time for subscription to be initiated.
[Wear] Fixes to functionality. [Wear] Proper display of media information for TV Shows and Music.
1 parent 3cd1daf commit 3b6d762

File tree

14 files changed

+104
-52
lines changed

14 files changed

+104
-52
lines changed

mobile/src/main/java/com/atomjack/vcfp/PlexSubscription.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public class PlexSubscription {
7070

7171
private Handler mHandler;
7272

73-
private PlayerState currentState;
73+
private PlayerState currentState = PlayerState.STOPPED;
7474
private Timeline currentTimeline;
7575

7676
public PlexSubscription() {

mobile/src/main/java/com/atomjack/vcfp/VoiceControlForPlexApplication.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,4 +774,19 @@ public static Asset createAssetFromBitmap(Bitmap bitmap) {
774774
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteStream);
775775
return Asset.createFromBytes(byteStream.toByteArray());
776776
}
777+
778+
public static void SetWearMediaTitles(DataMap dataMap, PlexMedia media) {
779+
if(media.isShow()) {
780+
dataMap.putString(WearConstants.MEDIA_TITLE, media.getTitle());
781+
Logger.d("[VCFPActivity] got show title: %s", media.getTitle());
782+
dataMap.putString(WearConstants.MEDIA_SUBTITLE, media.getEpisodeTitle());
783+
} else if(media.isMovie()) {
784+
dataMap.putString(WearConstants.MEDIA_TITLE, media.title);
785+
dataMap.remove(WearConstants.MEDIA_SUBTITLE);
786+
} else if(media.isMusic()) {
787+
Logger.d("[VCFPActivity] got music: %s by %s", media.title, media.grandparentTitle);
788+
dataMap.putString(WearConstants.MEDIA_TITLE, media.grandparentTitle);
789+
dataMap.putString(WearConstants.MEDIA_SUBTITLE, media.title);
790+
}
791+
}
777792
}

mobile/src/main/java/com/atomjack/vcfp/activities/NowPlayingActivity.java

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.Intent;
44
import android.content.res.Configuration;
55
import android.os.Bundle;
6+
import android.os.Handler;
67
import android.view.Menu;
78
import android.view.View;
89
import android.widget.SeekBar;
@@ -25,6 +26,8 @@
2526

2627
public class NowPlayingActivity extends PlayerActivity {
2728
private boolean subscribed = false;
29+
private boolean fromWear = false;
30+
private final Handler handler = new Handler();
2831

2932
PlayerState state = PlayerState.STOPPED;
3033

@@ -45,38 +48,46 @@ protected void onCreate(Bundle savedInstanceState) {
4548
Logger.d("found saved instance state");
4649
nowPlayingMedia = savedInstanceState.getParcelable(com.atomjack.shared.Intent.EXTRA_MEDIA);
4750
mClient = savedInstanceState.getParcelable(com.atomjack.shared.Intent.EXTRA_CLIENT);
51+
fromWear = savedInstanceState.getBoolean(WearConstants.FROM_WEAR, false);
4852
Logger.d("[NowPlaying] set client: %s", mClient);
4953
} else {
5054
nowPlayingMedia = getIntent().getParcelableExtra(com.atomjack.shared.Intent.EXTRA_MEDIA);
5155
mClient = getIntent().getParcelableExtra(com.atomjack.shared.Intent.EXTRA_CLIENT);
56+
fromWear = getIntent().getBooleanExtra(WearConstants.FROM_WEAR, false);
57+
if(fromWear) {
58+
new SendToDataLayerThread(WearConstants.FINISH, this).start();
59+
}
5260
Logger.d("[NowPlayingActivity] 2 set client: %s", mClient);
5361
}
5462

5563
if(mClient == null || nowPlayingMedia == null)
5664
finish();
5765

58-
if(plexSubscription.isSubscribed()) {
59-
state = plexSubscription.getCurrentState();
60-
if(state == PlayerState.STOPPED) {
66+
// If we're not subscribed, or the current state of the PlexClient is stopped, finish the activity.
67+
// However, we need to wait a few seconds before checking this as if we're not subscribed when playback
68+
// is triggered, getting subscribed will take a small amount of time
69+
handler.postDelayed(new Runnable() {
70+
@Override
71+
public void run() {
72+
Logger.d("[NowPlayingActivity] subscribed: %s", plexSubscription.isSubscribed());
73+
if(!plexSubscription.isSubscribed() || plexSubscription.getCurrentState() == PlayerState.STOPPED) {
6174
VoiceControlForPlexApplication.getInstance().cancelNotification();
6275
finish();
63-
} else {
64-
Logger.d("mClient: %s", mClient);
65-
Logger.d("nowPlayingMedia: %s", nowPlayingMedia);
66-
showNowPlaying();
67-
seekBar = (SeekBar) findViewById(R.id.seekBar);
68-
seekBar.setOnSeekBarChangeListener(NowPlayingActivity.this);
69-
seekBar.setMax(nowPlayingMedia.duration);
70-
seekBar.setProgress(Integer.parseInt(nowPlayingMedia.viewOffset));
71-
72-
setCurrentTimeDisplay(getOffset(nowPlayingMedia));
73-
durationDisplay.setText(VoiceControlForPlexApplication.secondsToTimecode(nowPlayingMedia.duration / 1000));
7476
}
75-
} else {
76-
VoiceControlForPlexApplication.getInstance().cancelNotification();
77-
finish();
78-
}
77+
}
78+
}, 3000);
7979

80+
81+
Logger.d("mClient: %s", mClient);
82+
Logger.d("nowPlayingMedia: %s", nowPlayingMedia);
83+
showNowPlaying();
84+
seekBar = (SeekBar) findViewById(R.id.seekBar);
85+
seekBar.setOnSeekBarChangeListener(NowPlayingActivity.this);
86+
seekBar.setMax(nowPlayingMedia.duration);
87+
seekBar.setProgress(Integer.parseInt(nowPlayingMedia.viewOffset));
88+
89+
setCurrentTimeDisplay(getOffset(nowPlayingMedia));
90+
durationDisplay.setText(VoiceControlForPlexApplication.secondsToTimecode(nowPlayingMedia.duration / 1000));
8091
}
8192

8293

mobile/src/main/java/com/atomjack/vcfp/activities/VCFPActivity.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,8 +904,8 @@ public void sendWearPlaybackChange() {
904904
final DataMap data = new DataMap();
905905
String msg = null;
906906
if (mCurrentState == PlayerState.PLAYING) {
907-
data.putString(WearConstants.MEDIA_TITLE, nowPlayingMedia.title);
908-
// data.putString(WearConstants.IMAGE, nowPlayingMedia.art);
907+
data.putString(WearConstants.MEDIA_TYPE, nowPlayingMedia.getType());
908+
VoiceControlForPlexApplication.SetWearMediaTitles(data, nowPlayingMedia);
909909
msg = WearConstants.MEDIA_PLAYING;
910910
} else if (mCurrentState == PlayerState.STOPPED) {
911911
msg = WearConstants.MEDIA_STOPPED;
@@ -920,6 +920,7 @@ public void onSuccess(Bitmap bitmap) {
920920
DataMap binaryDataMap = new DataMap();
921921
binaryDataMap.putAll(data);
922922
binaryDataMap.putAsset(WearConstants.IMAGE, VoiceControlForPlexApplication.createAssetFromBitmap(bitmap));
923+
binaryDataMap.putString(WearConstants.PLAYBACK_STATE, mCurrentState.name());
923924
new SendToDataLayerThread(WearConstants.RECEIVE_MEDIA_IMAGE, binaryDataMap, VCFPActivity.this).sendDataItem();
924925
}
925926
});

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ public boolean isShow() {
5757

5858
public boolean isClip() { return false; }
5959

60+
public String getType() {
61+
if(isMovie())
62+
return "movie";
63+
else if(isMusic())
64+
return "music";
65+
else if(isShow())
66+
return "show";
67+
else if(isClip())
68+
return "clip";
69+
else
70+
return "unknown";
71+
}
72+
6073
@Attribute
6174
public String key;
6275
@Attribute

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public boolean isClip() {
5959

6060
@Override
6161
public String getTitle() {
62-
return type.equals("movie") ? title : showTitle;
62+
return type.equals("movie") ? title : grandparentTitle;
6363
}
6464

6565
@Override

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import com.google.android.gms.common.api.ResultCallback;
5353
import com.google.android.gms.common.api.Status;
5454
import com.google.android.gms.wearable.DataMap;
55-
import com.google.android.gms.wearable.Wearable;
5655
import com.google.gson.Gson;
5756
import com.google.gson.GsonBuilder;
5857

@@ -104,7 +103,6 @@ public class PlexSearchService extends Service {
104103
private VCFPActivity.NetworkState currentNetworkState;
105104

106105
private boolean fromWear = false;
107-
GoogleApiClient googleApiClient;
108106

109107
// Chromecast
110108
MediaRouter mMediaRouter;
@@ -145,7 +143,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
145143
Logger.d("CAST MANAGER IS SUBSCRIBED");
146144
}
147145

148-
if(intent.getBooleanExtra(WearConstants.FROM_WEAR, false) == true) {
146+
if(intent.getBooleanExtra(WearConstants.FROM_WEAR, false) == true && VoiceControlForPlexApplication.getInstance().hasWear()) {
149147
fromWear = true;
150148
}
151149

@@ -967,7 +965,6 @@ else if(media instanceof PlexTrack)
967965
theMedia.server = media.server;
968966
playMedia(theMedia);
969967
onActionFinished(WearConstants.SPEECH_QUERY_RESULT, false, theMedia);
970-
971968
} else {
972969
// TODO: Handle failure
973970
}
@@ -1097,6 +1094,7 @@ private void castAlbum(List<PlexTrack> tracks) {
10971094
private void showPlayingMedia(PlexMedia media) {
10981095
Logger.d("[PlexSearchService] nowPlayingMedia: %s", media.title);
10991096
Intent nowPlayingIntent = new Intent(this, NowPlayingActivity.class);
1097+
nowPlayingIntent.putExtra(WearConstants.FROM_WEAR, fromWear);
11001098
nowPlayingIntent.putExtra(com.atomjack.shared.Intent.EXTRA_MEDIA, media);
11011099
nowPlayingIntent.putExtra(com.atomjack.shared.Intent.EXTRA_CLIENT, client);
11021100
nowPlayingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@@ -1880,10 +1878,6 @@ private void sendClientScanIntent() {
18801878
private void onActionFinished(String action, boolean error, PlexMedia media) {
18811879
if(fromWear) {
18821880
Logger.d("[PlexSearchService] onActionFinished: %s", action);
1883-
googleApiClient = new GoogleApiClient.Builder(this)
1884-
.addApi(Wearable.API)
1885-
.build();
1886-
googleApiClient.connect();
18871881

18881882
DataMap dataMap = new DataMap();
18891883
dataMap.putBoolean(WearConstants.SPEECH_QUERY_RESULT, !error);
@@ -1900,15 +1894,13 @@ public SearchFeedback(Context ctx) {
19001894
}
19011895

19021896
@Override
1903-
protected void feedback(String text, boolean errors) {
1904-
super.feedback(text, errors);
1905-
if(VoiceControlForPlexApplication.getInstance().hasWear()) {
1897+
protected void feedback(String text, boolean error) {
1898+
super.feedback(text, error);
1899+
if(VoiceControlForPlexApplication.getInstance().hasWear() && error) {
19061900
DataMap dataMap = new DataMap();
19071901
dataMap.putString(WearConstants.INFORMATION, text);
19081902
new SendToDataLayerThread(WearConstants.SET_INFO, dataMap, PlexSearchService.this).start();
19091903
}
19101904
}
1911-
19121905
}
1913-
19141906
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public void onMessageReceived(MessageEvent messageEvent) {
104104
}
105105
if(messageEvent.getPath() != null) {
106106
final DataMap dataMap = new DataMap();
107+
final DataMap receivedDataMap = DataMap.fromByteArray(messageEvent.getData());
107108

108109
PlexSubscription plexSubscription = VoiceControlForPlexApplication.getInstance().plexSubscription;
109110
CastPlayerManager castPlayerManager = VoiceControlForPlexApplication.getInstance().castPlayerManager;
@@ -118,18 +119,18 @@ public void onMessageReceived(MessageEvent messageEvent) {
118119

119120

120121
if(message.equals(WearConstants.SPEECH_QUERY)) {
121-
DataMap dataMap1 = DataMap.fromByteArray(messageEvent.getData());
122-
Logger.d("[WearListenerService] message received: %s", dataMap1);
122+
Logger.d("[WearListenerService] message received: %s", receivedDataMap);
123123

124124
Intent sendIntent = new Intent(this, PlexSearchService.class);
125-
sendIntent.putStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS, dataMap1.getStringArrayList(WearConstants.SPEECH_QUERY));
125+
sendIntent.putStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS, receivedDataMap.getStringArrayList(WearConstants.SPEECH_QUERY));
126126
sendIntent.putExtra(WearConstants.FROM_WEAR, true);
127127
sendIntent.addFlags(Intent.FLAG_FROM_BACKGROUND);
128128
sendIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
129129
sendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
130130
startService(sendIntent);
131131
} else if(message.equals(WearConstants.GET_PLAYBACK_STATE)) {
132132
Logger.d("[WearListenerService] get playback state");
133+
dataMap.putBoolean(WearConstants.LAUNCHED, receivedDataMap.getBoolean(WearConstants.LAUNCHED, false));
133134
// PlexSubscription plexSubscription = VoiceControlForPlexApplication.getInstance().plexSubscription;
134135
// CastPlayerManager castPlayerManager = VoiceControlForPlexApplication.getInstance().castPlayerManager;
135136
if (plexSubscription.isSubscribed()) {
@@ -147,13 +148,15 @@ public void onMessageReceived(MessageEvent messageEvent) {
147148
if(listener != null && listener.getNowPlayingMedia() != null) {
148149
Logger.d("now playing: %s", listener.getNowPlayingMedia().title);
149150
dataMap.putString(WearConstants.MEDIA_TITLE, listener.getNowPlayingMedia().title);
151+
dataMap.putString(WearConstants.MEDIA_TYPE, listener.getNowPlayingMedia().getType());
150152
final PlexMedia media = plexSubscription.getListener().getNowPlayingMedia();
151153
VoiceControlForPlexApplication.getWearMediaImage(media, new BitmapHandler() {
152154
@Override
153155
public void onSuccess(Bitmap bitmap) {
154156
DataMap binaryDataMap = new DataMap();
155157
binaryDataMap.putAll(dataMap);
156158
binaryDataMap.putAsset(WearConstants.IMAGE, VoiceControlForPlexApplication.createAssetFromBitmap(bitmap));
159+
binaryDataMap.putString(WearConstants.PLAYBACK_STATE, dataMap.getString(WearConstants.PLAYBACK_STATE));
157160
new SendToDataLayerThread(WearConstants.RECEIVE_MEDIA_IMAGE, binaryDataMap, WearListenerService.this).sendDataItem();
158161
new SendToDataLayerThread(WearConstants.GET_PLAYBACK_STATE, dataMap, WearListenerService.this).start();
159162
Logger.d("[WearListenerService] sent is playing status (%s) to wearable.", dataMap.getString(WearConstants.PLAYBACK_STATE));

shared/src/main/java/com/atomjack/shared/WearConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public class WearConstants {
2828
// This is used to know whether or not the voice input was triggered from an initial launch of the app
2929
public final static String LAUNCHED = "com.atomjack.vcfp.launched";
3030

31+
public final static String FINISH = "com.atomjack.vcfp.finish";
32+
3133
public final static String SPEECH_QUERY_RESULT = "com.atomjack.vcfp.speech_query_result";
3234

3335
public final static String SEARCHING_FOR = "com.atomjack.vcfp.searching_for";
@@ -48,6 +50,7 @@ public class WearConstants {
4850
// media metadata
4951
public final static String MEDIA_TYPE = "com.atomjack.vcfp.media_type";
5052
public final static String MEDIA_TITLE = "com.atomjack.vcfp.media_title";
53+
public final static String MEDIA_SUBTITLE = "com.atomjack.vcfp.media_episode_title";
5154
public final static String IMAGE = "com.atomjack.vcfp.image";
5255
public final static String CLIENT_NAME = "com.atomjack.vcfp.client_name";
5356
}

wear/src/main/java/com/atomjack/wear/MainActivity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ protected void onCreate(Bundle savedInstanceState) {
5656
if (action.equals(Intent.ACTION_MAIN)) {
5757
// Send a message to the paired device asking if it's connected to a Plex Client that is currently playing
5858
DataMap dataMap = new DataMap();
59-
// dataMap.putBoolean(WearConstants.LAUNCHED, true);
60-
new SendToDataLayerThread(WearConstants.GET_PLAYBACK_STATE, this).start();
59+
dataMap.putBoolean(WearConstants.LAUNCHED, true);
60+
new SendToDataLayerThread(WearConstants.GET_PLAYBACK_STATE, dataMap, this).start();
6161
} else if(action.equals(WearConstants.SET_INFO)) {
62+
Logger.d("[MainActivity] setting info to %s", getIntent().getStringExtra(WearConstants.INFORMATION));
6263
setInformationView(getIntent().getStringExtra(WearConstants.INFORMATION));
6364
}
6465
}
@@ -139,6 +140,7 @@ private void setInformationView(String info) {
139140
watchViewStub.setRectLayout(R.layout.activity_information_rect);
140141
watchViewStub.setRoundLayout(R.layout.activity_information_round);
141142
TextView textView = (TextView)findViewById(R.id.textView);
143+
Logger.d("[MainActivity] Setting Information View: %s", info);
142144
textView.setText(info);
143145
}
144146

0 commit comments

Comments
 (0)