Skip to content

Commit b140c23

Browse files
committed
adding google cast v3 sample
1 parent 3303623 commit b140c23

File tree

25 files changed

+621
-0
lines changed

25 files changed

+621
-0
lines changed

GoogleCastV3/.gitignore

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
=======
10+
# Built application files
11+
*.apk
12+
*.ap_
13+
14+
# Files for the ART/Dalvik VM
15+
*.dex
16+
17+
# Java class files
18+
*.class
19+
20+
# Generated files
21+
bin/
22+
gen/
23+
out/
24+
25+
# Gradle files
26+
.gradle/
27+
build/
28+
29+
# Local configuration file (sdk path, etc)
30+
local.properties
31+
32+
# Proguard folder generated by Eclipse
33+
proguard/
34+
35+
# Log Files
36+
*.log
37+
38+
# Android Studio Navigation editor temp files
39+
.navigation/
40+
41+
# Android Studio captures folder
42+
captures/
43+
44+
# Intellij
45+
*.iml
46+
.idea/workspace.xml
47+
48+
# Keystore files
49+
*.jks

GoogleCastV3/app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

GoogleCastV3/app/build.gradle

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 24
5+
buildToolsVersion "24.0.0"
6+
7+
defaultConfig {
8+
applicationId "com.tutsplus.googlecastv3"
9+
minSdkVersion 16
10+
targetSdkVersion 24
11+
versionCode 1
12+
versionName "1.0"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
testCompile 'junit:junit:4.12'
25+
compile 'com.android.support:appcompat-v7:24.1.1'
26+
27+
compile 'com.android.support:mediarouter-v7:24.1.1'
28+
compile 'com.google.android.gms:play-services-cast-framework:9.4.0'
29+
}

GoogleCastV3/app/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/paultr/Library/Android/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.tutsplus.googlecastv3;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.tutsplus.googlecastv3">
4+
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
7+
<application
8+
android:allowBackup="true"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:supportsRtl="true"
12+
android:theme="@style/AppTheme">
13+
14+
<meta-data
15+
android:name=
16+
"com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
17+
android:value="com.tutsplus.googlecastv3.CastOptionsProvider" />
18+
19+
<activity android:name=".MainActivity">
20+
<intent-filter>
21+
<action android:name="android.intent.action.MAIN" />
22+
23+
<category android:name="android.intent.category.LAUNCHER" />
24+
</intent-filter>
25+
</activity>
26+
27+
<activity android:name=".MovieDetailActivity" />
28+
29+
<activity
30+
android:name=".ExpandedControlsActivity"
31+
android:label="@string/app_name"
32+
android:theme="@style/ExpandedCastControlsStyle"
33+
android:launchMode="singleTask"
34+
android:screenOrientation="portrait">
35+
<intent-filter>
36+
<action android:name="android.intent.action.MAIN"/>
37+
</intent-filter>
38+
<meta-data
39+
android:name="android.support.PARENT_ACTIVITY"
40+
android:value=".MainActivity"/>
41+
</activity>
42+
</application>
43+
44+
</manifest>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.tutsplus.googlecastv3;
2+
3+
import android.content.Context;
4+
5+
import com.google.android.gms.cast.framework.CastOptions;
6+
import com.google.android.gms.cast.framework.OptionsProvider;
7+
import com.google.android.gms.cast.framework.SessionProvider;
8+
import com.google.android.gms.cast.framework.media.CastMediaOptions;
9+
import com.google.android.gms.cast.framework.media.MediaIntentReceiver;
10+
import com.google.android.gms.cast.framework.media.NotificationOptions;
11+
12+
import java.util.ArrayList;
13+
import java.util.List;
14+
15+
public class CastOptionsProvider implements OptionsProvider {
16+
@Override
17+
public CastOptions getCastOptions(Context context) {
18+
List<String> buttonActions = new ArrayList<>();
19+
20+
buttonActions.add(MediaIntentReceiver.ACTION_TOGGLE_PLAYBACK);
21+
buttonActions.add(MediaIntentReceiver.ACTION_STOP_CASTING);
22+
23+
int[] compatButtonActionsIndicies = new int[]{ 0, 1 };
24+
25+
NotificationOptions notificationOptions = new NotificationOptions.Builder()
26+
.setActions(buttonActions, compatButtonActionsIndicies)
27+
.setTargetActivityClassName(ExpandedControlsActivity.class.getName())
28+
.build();
29+
30+
CastMediaOptions mediaOptions = new CastMediaOptions.Builder()
31+
.setNotificationOptions(notificationOptions)
32+
.setExpandedControllerActivityClassName(ExpandedControlsActivity.class.getName())
33+
.build();
34+
35+
CastOptions castOptions = new CastOptions.Builder()
36+
.setResumeSavedSession(true)
37+
.setEnableReconnectionService(true)
38+
.setReceiverApplicationId(context.getString(R.string.cast_app_id))
39+
.setCastMediaOptions(mediaOptions)
40+
.build();
41+
42+
return castOptions;
43+
}
44+
45+
@Override
46+
public List<SessionProvider> getAdditionalSessionProviders(Context context) {
47+
return null;
48+
}
49+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.tutsplus.googlecastv3;
2+
3+
import android.view.Menu;
4+
5+
import com.google.android.gms.cast.framework.CastButtonFactory;
6+
import com.google.android.gms.cast.framework.media.widget.ExpandedControllerActivity;
7+
8+
public class ExpandedControlsActivity extends ExpandedControllerActivity {
9+
10+
@Override
11+
public boolean onCreateOptionsMenu(Menu menu) {
12+
super.onCreateOptionsMenu(menu);
13+
getMenuInflater().inflate(R.menu.menu_main, menu);
14+
CastButtonFactory.setUpMediaRouteButton(this, menu, R.id.media_route_menu_item);
15+
return true;
16+
}
17+
}

0 commit comments

Comments
 (0)