Skip to content

Commit 9d2c193

Browse files
author
Chris Bellew
committed
Added Chromecast Options. Added ability to email device logs. Lots of other fixes.
1 parent ec0407e commit 9d2c193

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1076
-391
lines changed

VoiceControlForPlex.iml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
2+
<module external.linked.project.id="VoiceControlForPlex" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
33
<component name="FacetManager">
44
<facet type="java-gradle" name="Java-Gradle">
55
<configuration>
66
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
7+
<option name="BUILDABLE" value="false" />
78
</configuration>
89
</facet>
910
</component>
10-
<component name="NewModuleRootManager" inherit-compiler-output="true">
11+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
1112
<exclude-output />
1213
<content url="file://$MODULE_DIR$">
1314
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
1415
</content>
1516
<orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />
1617
<orderEntry type="sourceFolder" forTests="false" />
1718
</component>
18-
</module>
19-
19+
</module>

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ buildscript {
44
mavenCentral()
55
}
66
dependencies {
7-
classpath 'com.android.tools.build:gradle:1.0.0'
7+
classpath 'com.android.tools.build:gradle:1.3.1'
88
}
99
}
1010

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=gradle-2.1.zip
6+
distributionUrl=https\://downloads.gradle.org/distributions/gradle-2.5-all.zip

mobile/build.gradle

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
apply plugin: 'android'
22

33
android {
4-
compileSdkVersion 21
5-
buildToolsVersion '22.0.1'
4+
useLibrary 'org.apache.http.legacy'
5+
compileSdkVersion 23
6+
buildToolsVersion '23.0.0'
67
defaultConfig {
78
applicationId "com.atomjack.vcfp"
89
minSdkVersion 15
9-
targetSdkVersion 21
10+
targetSdkVersion 23
1011
}
1112
dexOptions {
1213
preDexLibraries = false
@@ -104,20 +105,21 @@ android {
104105

105106
dependencies {
106107
wearApp project(':wear')
107-
compile 'com.loopj.android:android-async-http:1.4.4'
108+
compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
109+
compile 'com.loopj.android:android-async-http:1.4.8'
108110
compile files('libs/bugsense-3.6.jar')
109111
compile('org.simpleframework:simple-xml:2.7.1') {
110112
exclude group: 'stax', module: 'stax-api'
111113
exclude group: 'xpp3', module: 'xpp3'
112114
}
113-
compile 'com.google.code.gson:gson:2.3.+'
114-
compile 'com.android.support:support-v4:21.0+'
115+
compile 'com.android.support:support-v4:23.0+'
115116
compile 'com.github.codechimp-org.apprater:library:1.0.+'
116-
compile 'com.google.android.gms:play-services-wearable:6.5.87'
117-
compile 'com.android.support:appcompat-v7:21.0.3'
118-
compile 'com.android.support:mediarouter-v7:19.1.+'
117+
compile 'com.google.android.gms:play-services-wearable:7.8.0'
118+
compile 'com.android.support:appcompat-v7:23.0.0'
119+
compile 'com.android.support:mediarouter-v7:23.0.0'
119120
compile project(':CastCompanionLibrary-android')
120121
compile 'com.jakewharton:disklrucache:2.0.2'
121122
compile files('libs/commons-io-2.4.jar')
122123
compile project(':shared')
124+
compile files('libs/org.apache.http.legacy.jar')
123125
}
296 KB
Binary file not shown.

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

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import com.atomjack.vcfp.model.PlexTrack;
1515
import com.atomjack.vcfp.model.PlexVideo;
1616
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;
1818

1919
import org.json.JSONObject;
2020

@@ -96,14 +96,18 @@ public void setContext(Context context) {
9696

9797
public void subscribe(final PlexClient _client) {
9898
if(castManager == null) {
99+
Logger.d("creating castManager");
99100
castManager = getCastManager(mContext);
100101
castManager.addVideoCastConsumer(castConsumer);
101102
castManager.incrementUiCounter();
102103
}
103104
if(castManager.isConnected()) {
104105
castManager.disconnect();
105106
}
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");
107111
castConsumer.setOnConnected(new Runnable() {
108112
@Override
109113
public void run() {
@@ -140,7 +144,7 @@ public void run() {
140144
}
141145

142146
public boolean isSubscribed() {
143-
Logger.d("[CastPlayerManager] subscribed: %s, mClient: %s", subscribed, mClient);
147+
Logger.d("[CastPlayerManager] subscribed: %s, client: %s", subscribed, mClient);
144148
return subscribed && mClient != null;
145149
}
146150

@@ -177,6 +181,7 @@ public interface CastListener {
177181
void onCastPlayerPlaylistAdvance(PlexMedia media);
178182
void onCastPlayerState(PlayerState state, PlexMedia media);
179183
void onCastConnectionFailed();
184+
void onCastSeek();
180185
PlexMedia getNowPlayingMedia();
181186
};
182187

@@ -186,6 +191,7 @@ public VideoCastManager getCastManager() {
186191

187192
// This will send a message to the cast device to load the passed in media
188193
public void loadMedia(PlexMedia media, List<PlexMedia> album, final int offset) {
194+
Logger.d("Loading media");
189195
nowPlayingMedia = media;
190196
nowPlayingAlbum = album;
191197
nowPlayingMedia.server.findServerConnection(new ActiveConnectionHandler() {
@@ -229,12 +235,13 @@ public void onSuccess(Connection connection) {
229235
obj.put(PARAMS.SRC, getTranscodeUrl(nowPlayingMedia, connection, seconds));
230236
obj.put(PARAMS.RESUME, VoiceControlForPlexApplication.getInstance().prefs.get(Preferences.RESUME, false));
231237
sendMessage(obj);
238+
listener.onCastSeek();
232239
} catch (Exception ex) {}
233240
}
234241

235242
@Override
236243
public void onFailure(int statusCode) {
237-
244+
// TODO: Handle failure
238245
}
239246
});
240247
}
@@ -277,16 +284,17 @@ private void sendMessage(JSONObject obj) {
277284

278285
private static VideoCastManager getCastManager(Context context) {
279286
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);
286293

287294
}
288295
// castManager.setContext(context);
289-
castManager.setStopOnDisconnect(true);
296+
castManager = VideoCastManager.getInstance();
297+
castManager.setStopOnDisconnect(false);
290298
return castManager;
291299
}
292300

@@ -388,10 +396,9 @@ public void onApplicationStatusChanged(String appStatus) {
388396
}
389397

390398
@Override
391-
public boolean onApplicationConnectionFailed(int errorCode) {
399+
public void onApplicationConnectionFailed(int errorCode) {
392400
Logger.d("[CastPlayerManager] onApplicationConnectionFailed: %d", errorCode);
393401
listener.onCastConnectionFailed();
394-
return false;
395402
}
396403

397404
@Override
@@ -408,6 +415,7 @@ public void onCastDeviceDetected(final MediaRouter.RouteInfo info) {
408415
}
409416

410417
public String getTranscodeUrl(PlexMedia media, Connection connection, int offset) {
418+
Logger.d("getTranscodeUrl, offset: %d", offset);
411419
String url = connection.uri;
412420
url += String.format("/%s/:/transcode/universal/start?", media instanceof PlexVideo ? "video" : "audio");
413421
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
416424
qs.add("protocol", "http");
417425
qs.add("offset", Integer.toString(offset));
418426
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");
419429
qs.add("directPlay", "0");
420430
qs.add("directStream", "1");
421431
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]);
424434
qs.add("subtitleSize", "100");
425435
qs.add("audioBoost", "100");
426436
qs.add("session", mSessionId);
@@ -462,6 +472,7 @@ public JSONObject buildMedia(Connection connection, int offset) {
462472
data.put(PARAMS.CLIENT, VoiceControlForPlexApplication.gsonWrite.toJson(mClient));
463473
data.put(PARAMS.SRC, getTranscodeUrl(nowPlayingMedia, connection, offset));
464474
data.put(PARAMS.ACCESS_TOKEN, nowPlayingMedia.server.accessToken);
475+
Logger.d("token: %s", nowPlayingMedia.server.accessToken);
465476
data.put(PARAMS.PLAYLIST, getPlaylistJson());
466477
} catch (Exception ex) {
467478
ex.printStackTrace();
@@ -477,6 +488,10 @@ public PlayerState getCurrentState() {
477488
return currentState;
478489
}
479490

491+
public void setNowPlayingMedia(PlexMedia nowPlayingMedia) {
492+
this.nowPlayingMedia = nowPlayingMedia;
493+
}
494+
480495
public PlexMedia getNowPlayingMedia() {
481496
return nowPlayingMedia;
482497
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public void onReceive(final Context context, final Intent intent)
2222
if(queryText != null && queryText.matches(context.getResources().getString(R.string.pattern_recognition))) {
2323
queryText = queryText.toLowerCase();
2424
Intent sendIntent = new Intent(context, PlexSearchService.class);
25-
// sendIntent.setAction("com.atomjack.vcfp.intent.ACTION_SEARCH");
2625
sendIntent.putExtra(com.atomjack.shared.Intent.EXTRA_QUERYTEXT, queryText);
2726
sendIntent.addFlags(Intent.FLAG_FROM_BACKGROUND);
2827
sendIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.atomjack.vcfp;
22

3-
import com.google.sample.castcompanionlibrary.cast.callbacks.VideoCastConsumerImpl;
3+
4+
import com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumerImpl;
45

56
public class VCFPCastConsumer extends VideoCastConsumerImpl {
67
public void setOnConnected(Runnable runnable) {}

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import java.util.ArrayList;
7272
import java.util.Arrays;
7373
import java.util.HashMap;
74+
import java.util.LinkedHashMap;
7475
import java.util.Locale;
7576
import java.util.Map;
7677
import java.util.UUID;
@@ -99,12 +100,14 @@ public class VoiceControlForPlexApplication extends Application
99100
.create();
100101

101102
private NOTIFICATION_STATUS notificationStatus = NOTIFICATION_STATUS.off;
102-
public static enum NOTIFICATION_STATUS {
103+
public enum NOTIFICATION_STATUS {
103104
off,
104105
on,
105106
initializing
106107
}
107108

109+
public static HashMap<String, String[]> chromecastVideoOptions = new LinkedHashMap<>();
110+
108111
private NotificationManager mNotifyMgr;
109112
private Bitmap notificationBitmap = null;
110113
private Bitmap notificationBitmapBig = null;
@@ -160,6 +163,22 @@ public void onCreate() {
160163
plexSubscription = new PlexSubscription();
161164
castPlayerManager = new CastPlayerManager(getApplicationContext());
162165

166+
// chromecastVideoOptions.put(getString(R.string.original), new String[]{"12000", "1920x1080", "1"}); // Disabled for now. Don't know how to get PMS to direct play to chromecast
167+
chromecastVideoOptions.put("20mbps 720p", new String[]{"20000", "1280x720"});
168+
chromecastVideoOptions.put("12mbps 720p", new String[]{"12000", "1280x720"});
169+
chromecastVideoOptions.put("10mbps 720p", new String[]{"10000", "1280x720"});
170+
chromecastVideoOptions.put("8mbps 720p", new String[]{"8000", "1280x720"});
171+
chromecastVideoOptions.put("4mbps 720p", new String[]{"4000", "1280x720"});
172+
chromecastVideoOptions.put("3mbps 720p", new String[]{"3000", "1280x720"});
173+
chromecastVideoOptions.put("2mbps 720p", new String[]{"2000", "1280x720"});
174+
chromecastVideoOptions.put("1.5mbps 720p", new String[]{"1500", "1280x720"});
175+
176+
if(VoiceControlForPlexApplication.getInstance().prefs.getString(Preferences.CHROMECAST_VIDEO_QUALITY_LOCAL) == null)
177+
VoiceControlForPlexApplication.getInstance().prefs.put(Preferences.CHROMECAST_VIDEO_QUALITY_LOCAL, "8mbps 720p");
178+
if(VoiceControlForPlexApplication.getInstance().prefs.getString(Preferences.CHROMECAST_VIDEO_QUALITY_REMOTE) == null)
179+
VoiceControlForPlexApplication.getInstance().prefs.put(Preferences.CHROMECAST_VIDEO_QUALITY_REMOTE, "8mbps 720p");
180+
181+
163182
// Check for donate version, and if found, allow chromecast & wear
164183
PackageInfo pinfo;
165184
try

0 commit comments

Comments
 (0)