Skip to content

Commit 25118d0

Browse files
author
Chris Bellew
committed
Fixed seeking on Chromecast; Fixed a few bugs; Allow users who have the donate app installed to have Chromecast access.
1 parent ea6ab2a commit 25118d0

File tree

8 files changed

+84
-39
lines changed

8 files changed

+84
-39
lines changed

Voice Control For Plex/Voice Control For Plex.iml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,25 @@
5656
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
5757
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
5858
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
59-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates" />
59+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
60+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
61+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
62+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
63+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
64+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
65+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
66+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
67+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
68+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
69+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
70+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
71+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
72+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
73+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
74+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
75+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
76+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
77+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
6078
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
6179
</content>
6280
<orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
44
package="com.atomjack.vcfp"
5-
android:versionCode="21"
6-
android:versionName="1.9.0b2" >
5+
android:versionCode="22"
6+
android:versionName="1.9.0b3" >
77

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ public void seekTo(int seconds) {
169169
JSONObject obj = new JSONObject();
170170
try {
171171
obj.put(PARAMS.ACTION, PARAMS.ACTION_SEEK);
172+
obj.put(PARAMS.OFFSET, seconds);
172173
if(nowPlayingMedia instanceof PlexVideo)
173174
obj.put(PARAMS.SRC, getTranscodeUrl(nowPlayingMedia, seconds));
174175
obj.put(PARAMS.RESUME, VoiceControlForPlexApplication.getInstance().prefs.get(Preferences.RESUME, false));

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

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ public void onCreate() {
157157
plexSubscription = new PlexSubscription();
158158
castPlayerManager = new CastPlayerManager(getApplicationContext());
159159

160+
// Check for donate version, and if found, allow chromecast
161+
PackageInfo pinfo;
162+
try
163+
{
164+
pinfo = getPackageManager().getPackageInfo("com.atomjack.vcfpd", 0);
165+
mHasChromecast = true;
166+
} catch(Exception e) {}
167+
160168
// If this build includes chromecast support, no need to setup purchasing
161169
if(!mHasChromecast)
162170
setupInAppPurchasing();
@@ -386,16 +394,20 @@ private void fetchNotificationBitmap(final PlexMedia.IMAGE_KEY key, final PlexCl
386394
protected Object doInBackground(Object[] objects) {
387395
if (client != null && media != null) {
388396
InputStream inputStream = media.getNotificationThumb(media instanceof PlexTrack ? PlexMedia.IMAGE_KEY.NOTIFICATION_THUMB_MUSIC : key);
389-
try {
390-
inputStream.reset();
391-
} catch (IOException e) {}
392-
try {
393-
Logger.d("image key: %s", media.getImageKey(key));
394-
mSimpleDiskCache.put(media.getImageKey(key), inputStream);
395-
inputStream.close();
396-
Logger.d("Downloaded thumb. Redoing notification.");
397-
setNotification(client, currentState, media, true);
398-
} catch (Exception e) {}
397+
if(inputStream != null) {
398+
try {
399+
inputStream.reset();
400+
} catch (IOException e) {
401+
}
402+
try {
403+
Logger.d("image key: %s", media.getImageKey(key));
404+
mSimpleDiskCache.put(media.getImageKey(key), inputStream);
405+
inputStream.close();
406+
Logger.d("Downloaded thumb. Redoing notification.");
407+
setNotification(client, currentState, media, true);
408+
} catch (Exception e) {
409+
}
410+
}
399411
}
400412
return null;
401413
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,10 @@ protected void onResume() {
209209

210210
@Override
211211
protected void onPause() {
212-
castManager.decrementUiCounter();
213-
castManager.removeVideoCastConsumer(castConsumer);
212+
if(castManager != null) {
213+
castManager.decrementUiCounter();
214+
castManager.removeVideoCastConsumer(castConsumer);
215+
}
214216
super.onPause();
215217
}
216218

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

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,6 @@ protected void onCreate(Bundle savedInstanceState) {
136136

137137
client = gsonRead.fromJson(VoiceControlForPlexApplication.getInstance().prefs.get(Preferences.CLIENT, ""), PlexClient.class);
138138

139-
localScan = new LocalScan(this, MainActivity.class, new ScanHandler() {
140-
@Override
141-
public void onDeviceSelected(PlexDevice device, boolean resume) {
142-
if(device instanceof PlexServer)
143-
setServer((PlexServer) device);
144-
else if(device instanceof PlexClient)
145-
setClient((PlexClient)device);
146-
}
147-
});
148-
149139
initMainWithServer();
150140
}
151141

@@ -778,19 +768,22 @@ protected void onNewIntent(Intent intent) {
778768
if(searchDialog != null)
779769
searchDialog.cancel();
780770
VoiceControlForPlexApplication.getInstance().prefs.put(Preferences.SAVED_SERVERS, gsonWrite.toJson(VoiceControlForPlexApplication.servers));
781-
if (VoiceControlForPlexApplication.servers.size() > 0) {
782-
localScan.showPlexServers();
783-
} else {
784-
localScan.hideSearchDialog();
785-
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
786-
builder.setTitle(R.string.no_servers_found);
787-
builder.setCancelable(false).setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
771+
772+
if(intent.getBooleanExtra(VoiceControlForPlexApplication.Intent.EXTRA_SILENT, false) == false) {
773+
if (VoiceControlForPlexApplication.servers.size() > 0) {
774+
localScan.showPlexServers();
775+
} else {
776+
localScan.hideSearchDialog();
777+
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
778+
builder.setTitle(R.string.no_servers_found);
779+
builder.setCancelable(false).setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
788780
public void onClick(DialogInterface dialog, int id) {
789781
dialog.cancel();
790782
}
791783
});
792-
AlertDialog d = builder.create();
793-
d.show();
784+
AlertDialog d = builder.create();
785+
d.show();
786+
}
794787
}
795788
} else if(intent.getStringExtra(VoiceControlForPlexApplication.Intent.SCAN_TYPE).equals(VoiceControlForPlexApplication.Intent.SCAN_TYPE_CLIENT)) {
796789
ArrayList<PlexClient> clients = intent.getParcelableArrayListExtra(VoiceControlForPlexApplication.Intent.EXTRA_CLIENTS);
@@ -825,8 +818,8 @@ public void onClick(DialogInterface dialog, int id) {
825818
}
826819

827820

828-
829-
private void setServer(PlexServer _server) {
821+
@Override
822+
protected void setServer(PlexServer _server) {
830823
Logger.d("Setting Server %s", _server.name);
831824
server = _server;
832825
saveSettings();
@@ -839,7 +832,8 @@ private void setServer(PlexServer _server) {
839832

840833
}
841834

842-
private void setClient(PlexClient _client) {
835+
@Override
836+
protected void setClient(PlexClient _client) {
843837
if(!VoiceControlForPlexApplication.getInstance().hasChromecast() && _client.isCastClient) {
844838
showChromecastPurchase(_client, new Runnable() {
845839
@Override
@@ -1009,7 +1003,7 @@ public void onRouteRemoved(MediaRouter router, MediaRouter.RouteInfo route) {
10091003
@Override
10101004
public void onRouteAdded(MediaRouter router, MediaRouter.RouteInfo route)
10111005
{
1012-
Logger.d("onRouteAdded: %s", route);
1006+
// Logger.d("onRouteAdded: %s", route);
10131007
if(!VoiceControlForPlexApplication.castClients.containsKey(route.getName())) {
10141008
PlexClient client = new PlexClient();
10151009
client.isCastClient = true;

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,15 @@ protected void onCreate(Bundle savedInstanceState) {
145145

146146
currentNetworkState = NetworkState.getCurrentNetworkState(this);
147147

148-
148+
localScan = new LocalScan(this, MainActivity.class, new ScanHandler() {
149+
@Override
150+
public void onDeviceSelected(PlexDevice device, boolean resume) {
151+
if(device instanceof PlexServer)
152+
setServer((PlexServer) device);
153+
else if(device instanceof PlexClient)
154+
setClient((PlexClient)device);
155+
}
156+
});
149157

150158
castPlayerManager = VoiceControlForPlexApplication.getInstance().castPlayerManager;
151159
castPlayerManager.setContext(this);
@@ -167,6 +175,7 @@ protected void onSubscriptionMessage(Timeline timeline) {
167175

168176
private void getPlayingMedia(final PlexServer server, final Timeline timeline) {
169177
Logger.d("[VCFPActivity] getPlayingMedia: %s", timeline.key);
178+
// TODO: Find out why server can sometimes be null
170179
server.findServerConnection(new ServerFindHandler() {
171180
@Override
172181
public void onSuccess() {
@@ -470,6 +479,7 @@ public void onTimelineReceived(MediaContainer mc) {
470479
if(server == null) {
471480
// TODO: Scan servers for this server, then get playing media
472481
Logger.d("server is null");
482+
localScan.searchForPlexServers(true);
473483
} else {
474484
getPlayingMedia(server, timeline);
475485
}
@@ -692,4 +702,10 @@ public void onDisconnected() {
692702
public void onCastPlayerPlaylistAdvance(PlexMedia media) {
693703

694704
}
705+
706+
protected void setServer(PlexServer _server) {
707+
}
708+
709+
protected void setClient(PlexClient _client) {
710+
}
695711
}

Voice Control For Plex/src/main/java/us/nineworlds/serenity/GDMReceiver.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public void onReceive(Context context, Intent intent) {
8080
i.putExtra(VoiceControlForPlexApplication.Intent.SCAN_TYPE, intent.getStringExtra(VoiceControlForPlexApplication.Intent.SCAN_TYPE));
8181
i.putExtra(VoiceControlForPlexApplication.Intent.EXTRA_CONNECT_TO_CLIENT, intent.getBooleanExtra(VoiceControlForPlexApplication.Intent.EXTRA_CONNECT_TO_CLIENT, false));
8282

83+
i.putExtra(VoiceControlForPlexApplication.Intent.EXTRA_SILENT, intent.getBooleanExtra(VoiceControlForPlexApplication.Intent.EXTRA_SILENT, false));
84+
8385
i.addFlags(Intent.FLAG_FROM_BACKGROUND);
8486
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
8587
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

0 commit comments

Comments
 (0)