Skip to content

Commit 2a21fdd

Browse files
liraz747Liraz Shalom
andauthored
feat: Add Google Cast support
Co-authored-by: Liraz Shalom <liraz@Lirazs-MacBook-Air.local>
1 parent 3b2afa9 commit 2a21fdd

Some content is hidden

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

45 files changed

+1658
-139
lines changed

app/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,13 @@ dependencies {
202202
implementation(libs.media3)
203203
implementation(libs.media3.session)
204204
implementation(libs.media3.okhttp)
205+
implementation(libs.media3.cast)
205206
implementation(libs.squigglyslider)
206207

208+
// Google Cast
209+
implementation(libs.mediarouter)
210+
implementation(libs.cast.framework)
211+
207212
implementation(libs.room.runtime)
208213
implementation(libs.kuromoji.ipadic)
209214
implementation(libs.tinypinyin)

app/proguard-rules.pro

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,8 @@
111111
-dontwarn com.yalantis.ucrop**
112112
-keep class com.yalantis.ucrop** { *; }
113113
-keep interface com.yalantis.ucrop** { *; }
114+
115+
## Google Cast Rules
116+
-keep class com.metrolist.music.cast.** { *; }
117+
-keep class com.google.android.gms.cast.** { *; }
118+
-keep class androidx.mediarouter.** { *; }

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@
174174
<meta-data
175175
android:name="com.google.android.gms.car.application"
176176
android:resource="@xml/automotive_app_desc" />
177+
178+
<!-- Google Cast Options Provider -->
179+
<meta-data
180+
android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
181+
android:value="com.metrolist.music.cast.CastOptionsProvider" />
177182
</application>
178183

179184
</manifest>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.metrolist.music.cast
2+
3+
import android.content.Context
4+
import com.google.android.gms.cast.CastMediaControlIntent
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+
/**
13+
* CastOptionsProvider for Google Cast integration.
14+
* This class provides the Cast options for the app.
15+
*/
16+
class CastOptionsProvider : OptionsProvider {
17+
18+
override fun getCastOptions(context: Context): CastOptions {
19+
val notificationOptions = NotificationOptions.Builder()
20+
.setActions(
21+
listOf(
22+
MediaIntentReceiver.ACTION_SKIP_PREV,
23+
MediaIntentReceiver.ACTION_TOGGLE_PLAYBACK,
24+
MediaIntentReceiver.ACTION_SKIP_NEXT,
25+
MediaIntentReceiver.ACTION_STOP_CASTING
26+
),
27+
intArrayOf(1, 2) // Indices of actions for compact view
28+
)
29+
.build()
30+
31+
val mediaOptions = CastMediaOptions.Builder()
32+
.setNotificationOptions(notificationOptions)
33+
.build()
34+
35+
return CastOptions.Builder()
36+
.setReceiverApplicationId(CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID)
37+
.setCastMediaOptions(mediaOptions)
38+
.setStopReceiverApplicationWhenEndingSession(true)
39+
.build()
40+
}
41+
42+
override fun getAdditionalSessionProviders(context: Context): List<SessionProvider>? {
43+
return null
44+
}
45+
}

app/src/main/kotlin/com/metrolist/music/constants/PreferenceKeys.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ val DiscordNameKey = stringPreferencesKey("discordName")
7878
val EnableDiscordRPCKey = booleanPreferencesKey("discordRPCEnable")
7979
val DiscordUseDetailsKey = booleanPreferencesKey("discordUseDetails")
8080

81+
// Google Cast
82+
val EnableGoogleCastKey = booleanPreferencesKey("enableGoogleCast")
83+
8184
val LastFMSessionKey = stringPreferencesKey("lastfmSession")
8285
val LastFMUsernameKey = stringPreferencesKey("lastfmUsername")
8386
val EnableLastFMScrobblingKey = booleanPreferencesKey("lastfmScrobblingEnable")

0 commit comments

Comments
 (0)