-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat/WIP: Started adding repeat and shuffle options
Signed-off-by: Gabriel Fontán <gabilessto@gmail.com>
- Loading branch information
Showing
15 changed files
with
332 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...mediaplayer/src/main/java/com/bobbyesp/mediaplayer/service/MediaLibrarySessionCallback.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.bobbyesp.mediaplayer.service | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import androidx.annotation.OptIn | ||
import androidx.media3.common.Player.REPEAT_MODE_ALL | ||
import androidx.media3.common.Player.REPEAT_MODE_OFF | ||
import androidx.media3.common.Player.REPEAT_MODE_ONE | ||
import androidx.media3.common.util.UnstableApi | ||
import androidx.media3.session.MediaLibraryService | ||
import androidx.media3.session.MediaSession | ||
import androidx.media3.session.SessionCommand | ||
import androidx.media3.session.SessionResult | ||
import com.bobbyesp.mediaplayer.service.MediaServiceHandler.Companion.ACTION_TOGGLE_LIBRARY | ||
import com.bobbyesp.mediaplayer.service.MediaServiceHandler.Companion.ACTION_TOGGLE_LIKE | ||
import com.bobbyesp.mediaplayer.service.MediaServiceHandler.Companion.ACTION_TOGGLE_REPEAT_MODE | ||
import com.bobbyesp.mediaplayer.service.MediaServiceHandler.Companion.ACTION_TOGGLE_SHUFFLE | ||
import com.bobbyesp.mediaplayer.service.MediaServiceHandler.Companion.CommandToggleLibrary | ||
import com.bobbyesp.mediaplayer.service.MediaServiceHandler.Companion.CommandToggleLike | ||
import com.bobbyesp.mediaplayer.service.MediaServiceHandler.Companion.CommandToggleRepeatMode | ||
import com.bobbyesp.mediaplayer.service.MediaServiceHandler.Companion.CommandToggleShuffle | ||
import com.google.common.util.concurrent.Futures | ||
import com.google.common.util.concurrent.ListenableFuture | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import javax.inject.Inject | ||
|
||
class MediaLibrarySessionCallback @Inject constructor( | ||
@ApplicationContext val context: Context | ||
) : MediaLibraryService.MediaLibrarySession.Callback { | ||
|
||
override fun onConnect( | ||
session: MediaSession, | ||
controller: MediaSession.ControllerInfo | ||
): MediaSession.ConnectionResult { | ||
val connectionResult = super.onConnect(session, controller) | ||
return MediaSession.ConnectionResult.accept( | ||
connectionResult.availableSessionCommands.buildUpon() | ||
.add(CommandToggleLibrary) | ||
.add(CommandToggleLike) | ||
.add(CommandToggleShuffle) | ||
.add(CommandToggleRepeatMode) | ||
.build(), | ||
connectionResult.availablePlayerCommands | ||
) | ||
} | ||
|
||
@OptIn(UnstableApi::class) | ||
override fun onCustomCommand( | ||
session: MediaSession, | ||
controller: MediaSession.ControllerInfo, | ||
customCommand: SessionCommand, | ||
args: Bundle, | ||
): ListenableFuture<SessionResult> { | ||
when (customCommand.customAction) { | ||
ACTION_TOGGLE_LIKE -> TODO() | ||
ACTION_TOGGLE_LIBRARY -> TODO() | ||
ACTION_TOGGLE_SHUFFLE -> session.player.shuffleModeEnabled = | ||
!session.player.shuffleModeEnabled | ||
|
||
ACTION_TOGGLE_REPEAT_MODE -> session.player.repeatMode = | ||
when (session.player.repeatMode) { | ||
REPEAT_MODE_OFF -> REPEAT_MODE_ONE | ||
REPEAT_MODE_ONE -> REPEAT_MODE_ALL | ||
REPEAT_MODE_ALL -> REPEAT_MODE_OFF | ||
else -> REPEAT_MODE_OFF | ||
} | ||
} | ||
return Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS)) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...src/main/java/com/bobbyesp/mediaplayer/service/notifications/MediaSessionLayoutHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.bobbyesp.mediaplayer.service.notifications | ||
|
||
interface MediaSessionLayoutHandler { | ||
fun updateNotificationLayout() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:height="24dp" | ||
android:tint="#000000" | ||
android:viewportHeight="24" | ||
android:viewportWidth="24" | ||
android:width="24dp"> | ||
|
||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M7,7h10v1.79c0,0.45 0.54,0.67 0.85,0.35l2.79,-2.79c0.2,-0.2 0.2,-0.51 0,-0.71l-2.79,-2.79c-0.31,-0.31 -0.85,-0.09 -0.85,0.36L17,5L6,5c-0.55,0 -1,0.45 -1,1v4c0,0.55 0.45,1 1,1s1,-0.45 1,-1L7,7zM17,17L7,17v-1.79c0,-0.45 -0.54,-0.67 -0.85,-0.35l-2.79,2.79c-0.2,0.2 -0.2,0.51 0,0.71l2.79,2.79c0.31,0.31 0.85,0.09 0.85,-0.36L7,19h11c0.55,0 1,-0.45 1,-1v-4c0,-0.55 -0.45,-1 -1,-1s-1,0.45 -1,1v3z" /> | ||
|
||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:height="24dp" | ||
android:tint="#000000" | ||
android:viewportHeight="24" | ||
android:viewportWidth="24" | ||
android:width="24dp"> | ||
|
||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M21,1H3C1.9,1 1,1.9 1,3v18c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2V3C23,1.9 22.1,1 21,1zM19,18c0,0.55 -0.45,1 -1,1H7v1.79c0,0.45 -0.54,0.67 -0.85,0.36l-2.79,-2.79c-0.2,-0.2 -0.2,-0.51 0,-0.71l2.79,-2.79C6.46,14.54 7,14.76 7,15.21V17h10v-3c0,-0.55 0.45,-1 1,-1s1,0.45 1,1V18zM20.64,6.35l-2.79,2.79C17.54,9.46 17,9.24 17,8.79V7H7v3c0,0.55 -0.45,1 -1,1s-1,-0.45 -1,-1V6c0,-0.55 0.45,-1 1,-1h11V3.21c0,-0.45 0.54,-0.67 0.85,-0.36l2.79,2.79C20.84,5.84 20.84,6.15 20.64,6.35z" /> | ||
|
||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:height="24dp" | ||
android:tint="#000000" | ||
android:viewportHeight="24" | ||
android:viewportWidth="24" | ||
android:width="24dp"> | ||
|
||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M21,1H3C1.9,1 1,1.9 1,3v18c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2V3C23,1.9 22.1,1 21,1zM19,18c0,0.55 -0.45,1 -1,1H7v1.79c0,0.45 -0.54,0.67 -0.85,0.36l-2.79,-2.79c-0.2,-0.2 -0.2,-0.51 0,-0.71l2.79,-2.79C6.46,14.54 7,14.76 7,15.21V17h10v-3c0,-0.55 0.45,-1 1,-1s1,0.45 1,1V18zM10.75,10.5c-0.41,0 -0.75,-0.34 -0.75,-0.75S10.34,9 10.75,9h1.5C12.66,9 13,9.34 13,9.75v4.5c0,0.41 -0.34,0.75 -0.75,0.75s-0.75,-0.34 -0.75,-0.75V10.5H10.75zM20.64,6.35l-2.79,2.79C17.54,9.46 17,9.24 17,8.79V7H7v3c0,0.55 -0.45,1 -1,1s-1,-0.45 -1,-1V6c0,-0.55 0.45,-1 1,-1h11V3.21c0,-0.45 0.54,-0.67 0.85,-0.36l2.79,2.79C20.84,5.84 20.84,6.15 20.64,6.35z" /> | ||
|
||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:height="24dp" | ||
android:tint="#000000" | ||
android:viewportHeight="24" | ||
android:viewportWidth="24" | ||
android:width="24dp"> | ||
|
||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M10.59,9.17L6.12,4.7c-0.39,-0.39 -1.02,-0.39 -1.41,0 -0.39,0.39 -0.39,1.02 0,1.41l4.46,4.46 1.42,-1.4zM15.35,4.85l1.19,1.19L4.7,17.88c-0.39,0.39 -0.39,1.02 0,1.41 0.39,0.39 1.02,0.39 1.41,0L17.96,7.46l1.19,1.19c0.31,0.31 0.85,0.09 0.85,-0.36L20,4.5c0,-0.28 -0.22,-0.5 -0.5,-0.5h-3.79c-0.45,0 -0.67,0.54 -0.36,0.85zM14.83,13.41l-1.41,1.41 3.13,3.13 -1.2,1.2c-0.31,0.31 -0.09,0.85 0.36,0.85h3.79c0.28,0 0.5,-0.22 0.5,-0.5v-3.79c0,-0.45 -0.54,-0.67 -0.85,-0.35l-1.19,1.19 -3.13,-3.14z" /> | ||
|
||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:height="24dp" | ||
android:tint="#000000" | ||
android:viewportHeight="24" | ||
android:viewportWidth="24" | ||
android:width="24dp"> | ||
|
||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M21,1H3C1.9,1 1,1.9 1,3v18c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2V3C23,1.9 22.1,1 21,1zM4.3,4.7c0.39,-0.39 1.02,-0.39 1.41,0l4.47,4.47l-1.42,1.4L4.3,6.11C3.91,5.72 3.91,5.09 4.3,4.7zM19.59,19.5c0,0.28 -0.22,0.5 -0.5,0.5H15.3c-0.45,0 -0.67,-0.54 -0.36,-0.85l1.2,-1.2l-3.13,-3.13l1.41,-1.41l3.13,3.14l1.19,-1.19c0.31,-0.32 0.85,-0.1 0.85,0.35V19.5zM19.59,8.29c0,0.45 -0.54,0.67 -0.85,0.36l-1.19,-1.19L5.7,19.29c-0.39,0.39 -1.02,0.39 -1.41,0c-0.39,-0.39 -0.39,-1.02 0,-1.41L16.13,6.04l-1.19,-1.19C14.63,4.54 14.85,4 15.3,4h3.79c0.28,0 0.5,0.22 0.5,0.5V8.29z" /> | ||
|
||
</vector> |
Oops, something went wrong.