├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── themes.xml
│ │ │ │ └── colors.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── xml
│ │ │ │ ├── backup_rules.xml
│ │ │ │ └── data_extraction_rules.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── rcudev
│ │ │ │ └── simplemediaplayer
│ │ │ │ ├── SimpleMediaPlayerApp.kt
│ │ │ │ ├── common
│ │ │ │ └── ui
│ │ │ │ │ ├── Destination.kt
│ │ │ │ │ ├── theme
│ │ │ │ │ ├── Color.kt
│ │ │ │ │ ├── Type.kt
│ │ │ │ │ └── Theme.kt
│ │ │ │ │ ├── components
│ │ │ │ │ ├── BottomPlayerUI.kt
│ │ │ │ │ ├── PlayerUI.kt
│ │ │ │ │ ├── PlayerBar.kt
│ │ │ │ │ └── PlayerControls.kt
│ │ │ │ │ ├── SimpleMediaActivity.kt
│ │ │ │ │ └── SimpleMediaViewModel.kt
│ │ │ │ ├── secondary
│ │ │ │ └── SecondaryScreen.kt
│ │ │ │ └── main
│ │ │ │ └── MainScreen.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── rcudev
│ │ │ └── simplemediaplayer
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── rcudev
│ │ └── simplemediaplayer
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle.kts
├── player-service
├── .gitignore
├── consumer-rules.pro
├── src
│ ├── main
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── rcudev
│ │ │ └── player_service
│ │ │ ├── service
│ │ │ ├── SimpleMediaService.kt
│ │ │ ├── notification
│ │ │ │ ├── SimpleMediaNotificationAdapter.kt
│ │ │ │ └── SimpleMediaNotificationManager.kt
│ │ │ └── SimpleMediaServiceHandler.kt
│ │ │ └── di
│ │ │ └── SimpleMediaModule.kt
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── rcudev
│ │ │ └── player_service
│ │ │ └── ExampleUnitTest.kt
│ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── rcudev
│ │ │ └── player_service
│ │ │ └── ExampleInstrumentedTest.kt
│ └── debug
│ │ └── res
│ │ └── drawable
│ │ └── ic_microphone.xml
├── proguard-rules.pro
└── build.gradle.kts
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── settings.gradle
├── gradle.properties
├── .gitignore
├── gradlew.bat
├── README.md
├── gradlew
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/player-service/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/player-service/consumer-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SimpleMediaPlayer
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RcuDev/SimpleMediaPlayer/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RcuDev/SimpleMediaPlayer/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RcuDev/SimpleMediaPlayer/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RcuDev/SimpleMediaPlayer/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RcuDev/SimpleMediaPlayer/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RcuDev/SimpleMediaPlayer/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RcuDev/SimpleMediaPlayer/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RcuDev/SimpleMediaPlayer/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RcuDev/SimpleMediaPlayer/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RcuDev/SimpleMediaPlayer/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RcuDev/SimpleMediaPlayer/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/player-service/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rcudev/simplemediaplayer/SimpleMediaPlayerApp.kt:
--------------------------------------------------------------------------------
1 | package com.rcudev.simplemediaplayer
2 |
3 | import android.app.Application
4 | import dagger.hilt.android.HiltAndroidApp
5 |
6 | @HiltAndroidApp
7 | class SimpleMediaPlayerApp: Application()
--------------------------------------------------------------------------------
/app/src/main/java/com/rcudev/simplemediaplayer/common/ui/Destination.kt:
--------------------------------------------------------------------------------
1 | package com.rcudev.simplemediaplayer.common.ui
2 |
3 | sealed class Destination(val route: String) {
4 | object Main: Destination("main")
5 | object Secondary: Destination("secondary")
6 | }
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Mar 24 10:06:16 CET 2023
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rcudev/simplemediaplayer/common/ui/theme/Color.kt:
--------------------------------------------------------------------------------
1 | package com.rcudev.simplemediaplayer.common.ui.theme
2 |
3 | import androidx.compose.ui.graphics.Color
4 |
5 | val Purple80 = Color(0xFFD0BCFF)
6 | val PurpleGrey80 = Color(0xFFCCC2DC)
7 | val Pink80 = Color(0xFFEFB8C8)
8 |
9 | val Purple40 = Color(0xFF6650a4)
10 | val PurpleGrey40 = Color(0xFF625b71)
11 | val Pink40 = Color(0xFF7D5260)
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | gradlePluginPortal()
4 | google()
5 | mavenCentral()
6 | }
7 | }
8 | dependencyResolutionManagement {
9 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
10 | repositories {
11 | google()
12 | mavenCentral()
13 | }
14 | }
15 | rootProject.name = "SimpleMediaPlayer"
16 | include ':app'
17 | include ':player-service'
18 |
--------------------------------------------------------------------------------
/app/src/test/java/com/rcudev/simplemediaplayer/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.rcudev.simplemediaplayer
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/player-service/src/test/java/com/rcudev/player_service/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.rcudev.player_service
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/res/xml/backup_rules.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/data_extraction_rules.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
12 |
13 |
19 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/rcudev/simplemediaplayer/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.rcudev.simplemediaplayer
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.rcudev.simplemediaplayer", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/player-service/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/player-service/src/androidTest/java/com/rcudev/player_service/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.rcudev.player_service
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.rcudev.player_service.test", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/player-service/src/debug/res/drawable/ic_microphone.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rcudev/simplemediaplayer/common/ui/theme/Type.kt:
--------------------------------------------------------------------------------
1 | package com.rcudev.simplemediaplayer.common.ui.theme
2 |
3 | import androidx.compose.material3.Typography
4 | import androidx.compose.ui.text.TextStyle
5 | import androidx.compose.ui.text.font.FontFamily
6 | import androidx.compose.ui.text.font.FontWeight
7 | import androidx.compose.ui.unit.sp
8 |
9 | // Set of Material typography styles to start with
10 | val Typography = Typography(
11 | bodyLarge = TextStyle(
12 | fontFamily = FontFamily.Default,
13 | fontWeight = FontWeight.Normal,
14 | fontSize = 16.sp,
15 | lineHeight = 24.sp,
16 | letterSpacing = 0.5.sp
17 | )
18 | /* Other default text styles to override
19 | titleLarge = TextStyle(
20 | fontFamily = FontFamily.Default,
21 | fontWeight = FontWeight.Normal,
22 | fontSize = 22.sp,
23 | lineHeight = 28.sp,
24 | letterSpacing = 0.sp
25 | ),
26 | labelSmall = TextStyle(
27 | fontFamily = FontFamily.Default,
28 | fontWeight = FontWeight.Medium,
29 | fontSize = 11.sp,
30 | lineHeight = 16.sp,
31 | letterSpacing = 0.5.sp
32 | )
33 | */
34 | )
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Kotlin code style for this project: "official" or "obsolete":
19 | kotlin.code.style=official
20 | # Enables namespacing of each library's R class so that its R class includes only the
21 | # resources declared in the library itself and none from the library's dependencies,
22 | # thereby reducing the size of the R class for that library
23 | android.nonTransitiveRClass=true
24 | android.enableJetifier=true
--------------------------------------------------------------------------------
/player-service/src/main/java/com/rcudev/player_service/service/SimpleMediaService.kt:
--------------------------------------------------------------------------------
1 | package com.rcudev.player_service.service
2 |
3 | import android.content.Intent
4 | import androidx.media3.common.Player
5 | import androidx.media3.common.util.UnstableApi
6 | import androidx.media3.session.MediaSession
7 | import androidx.media3.session.MediaSessionService
8 | import com.rcudev.player_service.service.notification.SimpleMediaNotificationManager
9 | import dagger.hilt.android.AndroidEntryPoint
10 | import javax.inject.Inject
11 |
12 | @AndroidEntryPoint
13 | class SimpleMediaService : MediaSessionService() {
14 |
15 | @Inject
16 | lateinit var mediaSession: MediaSession
17 |
18 | @Inject
19 | lateinit var notificationManager: SimpleMediaNotificationManager
20 |
21 | @UnstableApi
22 | override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
23 | notificationManager.startNotificationService(
24 | mediaSessionService = this,
25 | mediaSession = mediaSession
26 | )
27 |
28 | return super.onStartCommand(intent, flags, startId)
29 | }
30 |
31 | override fun onDestroy() {
32 | super.onDestroy()
33 | mediaSession.run {
34 | release()
35 | if (player.playbackState != Player.STATE_IDLE) {
36 | player.seekTo(0)
37 | player.playWhenReady = false
38 | player.stop()
39 | }
40 | }
41 | }
42 |
43 | override fun onGetSession(controllerInfo: MediaSession.ControllerInfo): MediaSession =
44 | mediaSession
45 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/rcudev/simplemediaplayer/common/ui/components/BottomPlayerUI.kt:
--------------------------------------------------------------------------------
1 | package com.rcudev.simplemediaplayer.common.ui.components
2 |
3 | import androidx.compose.foundation.background
4 | import androidx.compose.foundation.layout.Column
5 | import androidx.compose.foundation.layout.fillMaxWidth
6 | import androidx.compose.foundation.layout.height
7 | import androidx.compose.material3.Divider
8 | import androidx.compose.runtime.Composable
9 | import androidx.compose.ui.Alignment
10 | import androidx.compose.ui.Modifier
11 | import androidx.compose.ui.graphics.Color
12 | import androidx.compose.ui.unit.dp
13 | import com.rcudev.simplemediaplayer.common.ui.UIEvent
14 |
15 | @Composable
16 | fun BottomPlayerUI(
17 | modifier: Modifier = Modifier,
18 | durationString: String,
19 | playResourceProvider: () -> Int,
20 | progressProvider: () -> Pair,
21 | onUiEvent: (UIEvent) -> Unit
22 | ) {
23 | val (progress, progressString) = progressProvider()
24 |
25 | Column(
26 | modifier = modifier
27 | .fillMaxWidth()
28 | .background(Color.LightGray),
29 | horizontalAlignment = Alignment.CenterHorizontally
30 | ) {
31 |
32 | Divider(
33 | modifier = Modifier
34 | .fillMaxWidth()
35 | .height(1.dp)
36 | .background(Color.Black)
37 | )
38 |
39 | PlayerBar(
40 | progress = progress,
41 | durationString = durationString,
42 | progressString = progressString,
43 | onUiEvent = onUiEvent
44 | )
45 | PlayerControls(
46 | playResourceProvider = playResourceProvider,
47 | onUiEvent = onUiEvent
48 | )
49 | }
50 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/rcudev/simplemediaplayer/common/ui/components/PlayerUI.kt:
--------------------------------------------------------------------------------
1 | package com.rcudev.simplemediaplayer.common.ui.components
2 |
3 | import androidx.compose.foundation.background
4 | import androidx.compose.foundation.layout.Box
5 | import androidx.compose.foundation.layout.Column
6 | import androidx.compose.foundation.layout.padding
7 | import androidx.compose.foundation.shape.RoundedCornerShape
8 | import androidx.compose.runtime.Composable
9 | import androidx.compose.ui.Alignment
10 | import androidx.compose.ui.Modifier
11 | import androidx.compose.ui.draw.shadow
12 | import androidx.compose.ui.graphics.Color
13 | import androidx.compose.ui.unit.dp
14 | import com.rcudev.simplemediaplayer.common.ui.UIEvent
15 |
16 | @Composable
17 | fun SimpleMediaPlayerUI(
18 | modifier: Modifier = Modifier,
19 | durationString: String,
20 | playResourceProvider: () -> Int,
21 | progressProvider: () -> Pair,
22 | onUiEvent: (UIEvent) -> Unit
23 | ) {
24 | val (progress, progressString) = progressProvider()
25 |
26 | Box(
27 | modifier = modifier
28 | .padding(16.dp)
29 | .shadow(elevation = 8.dp, shape = RoundedCornerShape(8.dp))
30 | .background(Color.LightGray)
31 | ) {
32 | Column(
33 | horizontalAlignment = Alignment.CenterHorizontally
34 | ) {
35 | PlayerBar(
36 | progress = progress,
37 | durationString = durationString,
38 | progressString = progressString,
39 | onUiEvent = onUiEvent
40 | )
41 | PlayerControls(
42 | playResourceProvider = playResourceProvider,
43 | onUiEvent = onUiEvent
44 | )
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/rcudev/simplemediaplayer/secondary/SecondaryScreen.kt:
--------------------------------------------------------------------------------
1 | package com.rcudev.simplemediaplayer.secondary
2 |
3 | import androidx.compose.foundation.Image
4 | import androidx.compose.foundation.layout.fillMaxSize
5 | import androidx.compose.foundation.layout.padding
6 | import androidx.compose.material3.Scaffold
7 | import androidx.compose.material3.Surface
8 | import androidx.compose.runtime.Composable
9 | import androidx.compose.ui.Modifier
10 | import androidx.compose.ui.layout.ContentScale
11 | import coil.compose.rememberAsyncImagePainter
12 | import com.rcudev.simplemediaplayer.common.ui.SimpleMediaViewModel
13 | import com.rcudev.simplemediaplayer.common.ui.components.BottomPlayerUI
14 |
15 | @Composable
16 | fun SecondaryScreen(
17 | vm: SimpleMediaViewModel
18 | ) {
19 |
20 | Scaffold(
21 | bottomBar = {
22 | BottomPlayerUI(
23 | durationString = vm.formatDuration(vm.duration),
24 | playResourceProvider = {
25 | if (vm.isPlaying) android.R.drawable.ic_media_pause
26 | else android.R.drawable.ic_media_play
27 | },
28 | progressProvider = { Pair(vm.progress, vm.progressString) },
29 | onUiEvent = vm::onUIEvent
30 | )
31 | }
32 | ) { paddingValues ->
33 | Surface(
34 | modifier = Modifier.padding(paddingValues)
35 | ) {
36 |
37 | Image(
38 | painter = rememberAsyncImagePainter("https://i.pinimg.com/736x/4b/02/1f/4b021f002b90ab163ef41aaaaa17c7a4.jpg"),
39 | contentDescription = null,
40 | contentScale = ContentScale.Crop,
41 | modifier = Modifier.fillMaxSize()
42 | )
43 | }
44 | }
45 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
20 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
34 |
35 |
36 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.aar
4 | *.ap_
5 | *.aab
6 |
7 | # Files for the ART/Dalvik VM
8 | *.dex
9 |
10 | # Java class files
11 | *.class
12 |
13 | # Generated files
14 | bin/
15 | gen/
16 | out/
17 | # Uncomment the following line in case you need and you don't have the release build type files in your app
18 | # release/
19 |
20 | # Gradle files
21 | .gradle/
22 | build/
23 |
24 | # Local configuration file (sdk path, etc)
25 | local.properties
26 |
27 | # Proguard folder generated by Eclipse
28 | proguard/
29 |
30 | # Log Files
31 | *.log
32 |
33 | # Android Studio Navigation editor temp files
34 | .navigation/
35 |
36 | # Android Studio captures folder
37 | captures/
38 |
39 | # IntelliJ
40 | *.iml
41 | .idea/*
42 | .idea/workspace.xml
43 | .idea/tasks.xml
44 | .idea/gradle.xml
45 | .idea/assetWizardSettings.xml
46 | .idea/dictionaries
47 | .idea/libraries
48 | # Android Studio 3 in .gitignore file.
49 | .idea/caches
50 | .idea/modules.xml
51 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you
52 | .idea/navEditor.xml
53 |
54 | # Keystore files
55 | # Uncomment the following lines if you do not want to check your keystore files in.
56 | #*.jks
57 | #*.keystore
58 |
59 | # External native build folder generated in Android Studio 2.2 and later
60 | .externalNativeBuild
61 | .cxx/
62 |
63 | # Google Services (e.g. APIs or Firebase)
64 | # google-services.json
65 |
66 | # Freeline
67 | freeline.py
68 | freeline/
69 | freeline_project_description.json
70 |
71 | # fastlane
72 | fastlane/report.xml
73 | fastlane/Preview.html
74 | fastlane/screenshots
75 | fastlane/test_output
76 | fastlane/readme.md
77 |
78 | # Version control
79 | vcs.xml
80 |
81 | # lint
82 | lint/intermediates/
83 | lint/generated/
84 | lint/outputs/
85 | lint/tmp/
86 | # lint/reports/
87 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rcudev/simplemediaplayer/common/ui/components/PlayerBar.kt:
--------------------------------------------------------------------------------
1 | package com.rcudev.simplemediaplayer.common.ui.components
2 |
3 | import androidx.compose.foundation.layout.*
4 | import androidx.compose.material3.Slider
5 | import androidx.compose.material3.Text
6 | import androidx.compose.runtime.Composable
7 | import androidx.compose.runtime.mutableStateOf
8 | import androidx.compose.runtime.remember
9 | import androidx.compose.ui.Modifier
10 | import androidx.compose.ui.unit.dp
11 | import com.rcudev.simplemediaplayer.common.ui.UIEvent
12 |
13 | @Composable
14 | internal fun PlayerBar(
15 | progress: Float,
16 | durationString: String,
17 | progressString: String,
18 | onUiEvent: (UIEvent) -> Unit
19 | ) {
20 | val newProgressValue = remember { mutableStateOf(0f) }
21 | val useNewProgressValue = remember { mutableStateOf(false) }
22 |
23 | Column(
24 | modifier = Modifier.fillMaxWidth()
25 | ) {
26 | Slider(
27 | value = if (useNewProgressValue.value) newProgressValue.value else progress,
28 | onValueChange = { newValue ->
29 | useNewProgressValue.value = true
30 | newProgressValue.value = newValue
31 | onUiEvent(UIEvent.UpdateProgress(newProgress = newValue))
32 | },
33 | onValueChangeFinished = {
34 | useNewProgressValue.value = false
35 | },
36 | modifier = Modifier
37 | .padding(horizontal = 8.dp)
38 | )
39 | Row(
40 | horizontalArrangement = Arrangement.SpaceBetween,
41 | modifier = Modifier
42 | .fillMaxWidth()
43 | .padding(horizontal = 16.dp)
44 | ) {
45 | Text(text = progressString)
46 | Text(text = durationString)
47 | }
48 | }
49 | }
--------------------------------------------------------------------------------
/player-service/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("com.android.library")
3 | id("org.jetbrains.kotlin.android")
4 | id("kotlin-kapt")
5 | id("dagger.hilt.android.plugin")
6 | }
7 |
8 | android {
9 | namespace = "com.rcudev.player_service"
10 | compileSdk = 34
11 |
12 | defaultConfig {
13 | minSdk = 26
14 |
15 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
16 | consumerProguardFiles("consumer-rules.pro")
17 | }
18 |
19 | buildTypes {
20 | getByName("release") {
21 | isMinifyEnabled = false
22 | proguardFiles(
23 | getDefaultProguardFile("proguard-android-optimize.txt"),
24 | "proguard-rules.pro"
25 | )
26 | }
27 | }
28 | compileOptions {
29 | sourceCompatibility = JavaVersion.VERSION_17
30 | targetCompatibility = JavaVersion.VERSION_17
31 | }
32 | }
33 |
34 | dependencies {
35 |
36 | implementation("androidx.core:core-ktx:1.12.0")
37 | implementation("androidx.appcompat:appcompat:1.6.1")
38 | implementation("androidx.legacy:legacy-support-v4:1.0.0") // Needed MediaSessionCompat.Token
39 | implementation("com.google.android.material:material:1.10.0")
40 |
41 | // Hilt
42 | implementation("com.google.dagger:hilt-android:2.46.1")
43 | kapt("com.google.dagger:hilt-compiler:2.46.1")
44 |
45 | // Media3
46 | implementation("androidx.media3:media3-exoplayer:1.2.0")
47 | implementation("androidx.media3:media3-ui:1.2.0")
48 | implementation("androidx.media3:media3-session:1.2.0")
49 |
50 | // Glide
51 | implementation("com.github.bumptech.glide:glide:4.15.1")
52 |
53 | testImplementation("junit:junit:4.13.2")
54 | androidTestImplementation("androidx.test.ext:junit:1.1.5")
55 | androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
56 | }
--------------------------------------------------------------------------------
/player-service/src/main/java/com/rcudev/player_service/service/notification/SimpleMediaNotificationAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.rcudev.player_service.service.notification
2 |
3 | import android.app.PendingIntent
4 | import android.content.Context
5 | import android.graphics.Bitmap
6 | import android.graphics.drawable.Drawable
7 | import androidx.media3.common.Player
8 | import androidx.media3.common.util.UnstableApi
9 | import androidx.media3.ui.PlayerNotificationManager
10 | import com.bumptech.glide.Glide
11 | import com.bumptech.glide.load.engine.DiskCacheStrategy
12 | import com.bumptech.glide.request.target.CustomTarget
13 | import com.bumptech.glide.request.transition.Transition
14 |
15 | @UnstableApi
16 | class SimpleMediaNotificationAdapter(
17 | private val context: Context,
18 | private val pendingIntent: PendingIntent?
19 | ) : PlayerNotificationManager.MediaDescriptionAdapter {
20 |
21 | override fun getCurrentContentTitle(player: Player): CharSequence =
22 | player.mediaMetadata.albumTitle ?: ""
23 |
24 | override fun createCurrentContentIntent(player: Player): PendingIntent? =
25 | pendingIntent
26 |
27 | override fun getCurrentContentText(player: Player): CharSequence =
28 | player.mediaMetadata.displayTitle ?: ""
29 |
30 | override fun getCurrentLargeIcon(
31 | player: Player,
32 | callback: PlayerNotificationManager.BitmapCallback
33 | ): Bitmap? {
34 | Glide.with(context)
35 | .asBitmap()
36 | .load(player.mediaMetadata.artworkUri)
37 | .diskCacheStrategy(DiskCacheStrategy.ALL)
38 | .into(object : CustomTarget() {
39 | override fun onLoadCleared(placeholder: Drawable?) = Unit
40 | override fun onResourceReady(
41 | resource: Bitmap,
42 | transition: Transition?
43 | ) {
44 | callback.onBitmap(resource)
45 | }
46 | })
47 | return null
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rcudev/simplemediaplayer/common/ui/components/PlayerControls.kt:
--------------------------------------------------------------------------------
1 | package com.rcudev.simplemediaplayer.common.ui.components
2 |
3 | import androidx.compose.foundation.Image
4 | import androidx.compose.foundation.clickable
5 | import androidx.compose.foundation.layout.Arrangement
6 | import androidx.compose.foundation.layout.Row
7 | import androidx.compose.foundation.layout.padding
8 | import androidx.compose.foundation.layout.size
9 | import androidx.compose.foundation.shape.CircleShape
10 | import androidx.compose.material3.Icon
11 | import androidx.compose.runtime.Composable
12 | import androidx.compose.ui.Alignment
13 | import androidx.compose.ui.Modifier
14 | import androidx.compose.ui.draw.clip
15 | import androidx.compose.ui.res.painterResource
16 | import androidx.compose.ui.unit.dp
17 | import com.rcudev.simplemediaplayer.common.ui.UIEvent
18 |
19 | @Composable
20 | internal fun PlayerControls(
21 | playResourceProvider: () -> Int,
22 | onUiEvent: (UIEvent) -> Unit
23 | ) {
24 | Row(
25 | horizontalArrangement = Arrangement.spacedBy(35.dp),
26 | verticalAlignment = Alignment.CenterVertically
27 | ) {
28 | Icon(
29 | painter = painterResource(android.R.drawable.ic_media_rew),
30 | contentDescription = "Backward Button",
31 | modifier = Modifier
32 | .clip(CircleShape)
33 | .clickable(onClick = { onUiEvent(UIEvent.Backward) })
34 | .padding(12.dp)
35 | .size(34.dp)
36 | )
37 | Image(
38 | painter = painterResource(id = playResourceProvider()),
39 | contentDescription = "Play/Pause Button",
40 | modifier = Modifier
41 | .clip(CircleShape)
42 | .clickable(onClick = { onUiEvent(UIEvent.PlayPause) })
43 | .padding(8.dp)
44 | .size(56.dp)
45 | )
46 | Icon(
47 | painter = painterResource(android.R.drawable.ic_media_ff),
48 | contentDescription = "Forward Button",
49 | modifier = Modifier
50 | .clip(CircleShape)
51 | .clickable(onClick = { onUiEvent(UIEvent.Forward) })
52 | .padding(12.dp)
53 | .size(34.dp)
54 | )
55 | }
56 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/rcudev/simplemediaplayer/common/ui/SimpleMediaActivity.kt:
--------------------------------------------------------------------------------
1 | package com.rcudev.simplemediaplayer.common.ui
2 |
3 | import android.content.Intent
4 | import android.os.Bundle
5 | import androidx.activity.ComponentActivity
6 | import androidx.activity.compose.setContent
7 | import androidx.activity.viewModels
8 | import androidx.navigation.compose.NavHost
9 | import androidx.navigation.compose.composable
10 | import androidx.navigation.compose.rememberNavController
11 | import com.rcudev.player_service.service.SimpleMediaService
12 | import com.rcudev.simplemediaplayer.common.ui.theme.SimpleMediaPlayerTheme
13 | import com.rcudev.simplemediaplayer.main.SimpleMediaScreen
14 | import com.rcudev.simplemediaplayer.secondary.SecondaryScreen
15 | import dagger.hilt.android.AndroidEntryPoint
16 |
17 | @AndroidEntryPoint
18 | class SimpleMediaActivity : ComponentActivity() {
19 |
20 | private val viewModel: SimpleMediaViewModel by viewModels()
21 | private var isServiceRunning = false
22 |
23 | override fun onCreate(savedInstanceState: Bundle?) {
24 | super.onCreate(savedInstanceState)
25 |
26 | setContent {
27 | SimpleMediaPlayerTheme {
28 | val navController = rememberNavController()
29 |
30 | NavHost(navController = navController, startDestination = Destination.Main.route) {
31 | composable(Destination.Main.route) {
32 | SimpleMediaScreen(
33 | vm = viewModel,
34 | navController = navController,
35 | startService = ::startService
36 | )
37 | }
38 | composable(Destination.Secondary.route) {
39 | SecondaryScreen(vm = viewModel)
40 | }
41 | }
42 | }
43 | }
44 | }
45 |
46 | override fun onDestroy() {
47 | super.onDestroy()
48 | stopService(Intent(this, SimpleMediaService::class.java))
49 | isServiceRunning = false
50 | }
51 |
52 | private fun startService() {
53 | if (!isServiceRunning) {
54 | val intent = Intent(this, SimpleMediaService::class.java)
55 | startForegroundService(intent)
56 | isServiceRunning = true
57 | }
58 | }
59 | }
--------------------------------------------------------------------------------
/player-service/src/main/java/com/rcudev/player_service/di/SimpleMediaModule.kt:
--------------------------------------------------------------------------------
1 | package com.rcudev.player_service.di
2 |
3 | import android.content.Context
4 | import androidx.media3.common.AudioAttributes
5 | import androidx.media3.common.C
6 | import androidx.media3.common.util.UnstableApi
7 | import androidx.media3.exoplayer.ExoPlayer
8 | import androidx.media3.exoplayer.trackselection.DefaultTrackSelector
9 | import androidx.media3.session.MediaSession
10 | import com.rcudev.player_service.service.SimpleMediaServiceHandler
11 | import com.rcudev.player_service.service.notification.SimpleMediaNotificationManager
12 | import dagger.Module
13 | import dagger.Provides
14 | import dagger.Reusable
15 | import dagger.hilt.InstallIn
16 | import dagger.hilt.android.qualifiers.ApplicationContext
17 | import dagger.hilt.components.SingletonComponent
18 | import javax.inject.Singleton
19 |
20 | @Module
21 | @InstallIn(SingletonComponent::class)
22 | class SimpleMediaModule {
23 |
24 | @Provides
25 | @Singleton
26 | fun provideAudioAttributes(): AudioAttributes =
27 | AudioAttributes.Builder()
28 | .setContentType(C.AUDIO_CONTENT_TYPE_MOVIE)
29 | .setUsage(C.USAGE_MEDIA)
30 | .build()
31 |
32 | @Provides
33 | @Singleton
34 | @UnstableApi
35 | fun providePlayer(
36 | @ApplicationContext context: Context,
37 | audioAttributes: AudioAttributes
38 | ): ExoPlayer =
39 | ExoPlayer.Builder(context)
40 | .setAudioAttributes(audioAttributes, true)
41 | .setHandleAudioBecomingNoisy(true)
42 | .setTrackSelector(DefaultTrackSelector(context))
43 | .build()
44 |
45 | @Provides
46 | @Singleton
47 | fun provideNotificationManager(
48 | @ApplicationContext context: Context,
49 | player: ExoPlayer
50 | ): SimpleMediaNotificationManager =
51 | SimpleMediaNotificationManager(
52 | context = context,
53 | player = player
54 | )
55 |
56 | @Provides
57 | @Singleton
58 | fun provideMediaSession(
59 | @ApplicationContext context: Context,
60 | player: ExoPlayer
61 | ): MediaSession =
62 | MediaSession.Builder(context, player).build()
63 |
64 | @Provides
65 | @Singleton
66 | fun provideServiceHandler(
67 | player: ExoPlayer
68 | ): SimpleMediaServiceHandler =
69 | SimpleMediaServiceHandler(
70 | player = player
71 | )
72 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/rcudev/simplemediaplayer/common/ui/theme/Theme.kt:
--------------------------------------------------------------------------------
1 | package com.rcudev.simplemediaplayer.common.ui.theme
2 |
3 | import android.app.Activity
4 | import android.os.Build
5 | import androidx.compose.foundation.isSystemInDarkTheme
6 | import androidx.compose.material3.MaterialTheme
7 | import androidx.compose.material3.darkColorScheme
8 | import androidx.compose.material3.dynamicDarkColorScheme
9 | import androidx.compose.material3.dynamicLightColorScheme
10 | import androidx.compose.material3.lightColorScheme
11 | import androidx.compose.runtime.Composable
12 | import androidx.compose.runtime.SideEffect
13 | import androidx.compose.ui.graphics.toArgb
14 | import androidx.compose.ui.platform.LocalContext
15 | import androidx.compose.ui.platform.LocalView
16 | import androidx.core.view.ViewCompat
17 |
18 | private val DarkColorScheme = darkColorScheme(
19 | primary = Purple80,
20 | secondary = PurpleGrey80,
21 | tertiary = Pink80
22 | )
23 |
24 | private val LightColorScheme = lightColorScheme(
25 | primary = Purple40,
26 | secondary = PurpleGrey40,
27 | tertiary = Pink40
28 |
29 | /* Other default colors to override
30 | background = Color(0xFFFFFBFE),
31 | surface = Color(0xFFFFFBFE),
32 | onPrimary = Color.White,
33 | onSecondary = Color.White,
34 | onTertiary = Color.White,
35 | onBackground = Color(0xFF1C1B1F),
36 | onSurface = Color(0xFF1C1B1F),
37 | */
38 | )
39 |
40 | @Composable
41 | fun SimpleMediaPlayerTheme(
42 | darkTheme: Boolean = isSystemInDarkTheme(),
43 | // Dynamic color is available on Android 12+
44 | dynamicColor: Boolean = true,
45 | content: @Composable () -> Unit
46 | ) {
47 | val colorScheme = when {
48 | dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
49 | val context = LocalContext.current
50 | if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
51 | }
52 | darkTheme -> DarkColorScheme
53 | else -> LightColorScheme
54 | }
55 | val view = LocalView.current
56 | if (!view.isInEditMode) {
57 | SideEffect {
58 | (view.context as Activity).window.statusBarColor = colorScheme.primary.toArgb()
59 | ViewCompat.getWindowInsetsController(view)?.isAppearanceLightStatusBars = darkTheme
60 | }
61 | }
62 |
63 | MaterialTheme(
64 | colorScheme = colorScheme,
65 | typography = Typography,
66 | content = content
67 | )
68 | }
--------------------------------------------------------------------------------
/app/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("com.android.application")
3 | id("org.jetbrains.kotlin.android")
4 | id("kotlin-kapt")
5 | id("dagger.hilt.android.plugin")
6 | }
7 |
8 | var composeVersion: String = "1.5.4"
9 |
10 | android {
11 | namespace = "com.rcudev.simplemediaplayer"
12 | compileSdk = 34
13 |
14 | defaultConfig {
15 | applicationId = "com.rcudev.simplemediaplayer"
16 | minSdk = 26
17 | targetSdk = 34
18 | versionCode = 1
19 | versionName = "1.0"
20 |
21 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
22 | vectorDrawables {
23 | useSupportLibrary = true
24 | }
25 | }
26 |
27 | buildTypes {
28 | getByName("release") {
29 | isMinifyEnabled = false
30 | proguardFiles(
31 | getDefaultProguardFile("proguard-android-optimize.txt"),
32 | "proguard-rules.pro"
33 | )
34 | }
35 | }
36 | compileOptions {
37 | sourceCompatibility = JavaVersion.VERSION_17
38 | targetCompatibility = JavaVersion.VERSION_17
39 | }
40 | buildFeatures {
41 | compose = true
42 | }
43 | composeOptions {
44 | kotlinCompilerExtensionVersion = "1.4.4"
45 | }
46 | packagingOptions {
47 | resources.excludes.add("META-INF/{AL2.0,LGPL2.1}")
48 | }
49 | }
50 |
51 | dependencies {
52 | implementation(project(":player-service"))
53 |
54 | implementation("androidx.core:core-ktx:1.12.0")
55 | implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
56 |
57 | // Compose
58 | implementation("androidx.activity:activity-compose:1.8.1")
59 | implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2")
60 | implementation("androidx.lifecycle:lifecycle-runtime-compose:2.6.2")
61 | implementation("androidx.compose.ui:ui:1.5.4")
62 | implementation("androidx.compose.ui:ui-tooling-preview:$composeVersion")
63 | implementation("androidx.compose.material3:material3:1.1.2")
64 | implementation("androidx.navigation:navigation-compose:2.7.5")
65 | implementation("androidx.hilt:hilt-navigation-compose:1.1.0")
66 |
67 | // Hilt
68 | implementation("com.google.dagger:hilt-android:2.46.1")
69 | kapt("com.google.dagger:hilt-compiler:2.46.1")
70 |
71 | // Media3
72 | implementation("androidx.media3:media3-session:1.2.0")
73 |
74 | // Coil
75 | implementation("io.coil-kt:coil-compose:2.4.0")
76 |
77 | testImplementation("junit:junit:4.13.2")
78 | androidTestImplementation("androidx.test.ext:junit:1.1.5")
79 | androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
80 | androidTestImplementation("androidx.compose.ui:ui-test-junit4:$composeVersion")
81 | debugImplementation("androidx.compose.ui:ui-tooling:$composeVersion")
82 | debugImplementation("androidx.compose.ui:ui-test-manifest:$composeVersion")
83 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/rcudev/simplemediaplayer/main/MainScreen.kt:
--------------------------------------------------------------------------------
1 | package com.rcudev.simplemediaplayer.main
2 |
3 | import androidx.compose.foundation.background
4 | import androidx.compose.foundation.layout.*
5 | import androidx.compose.material3.CircularProgressIndicator
6 | import androidx.compose.material3.FloatingActionButton
7 | import androidx.compose.material3.MaterialTheme
8 | import androidx.compose.material3.Text
9 | import androidx.compose.runtime.Composable
10 | import androidx.compose.runtime.LaunchedEffect
11 | import androidx.compose.ui.Alignment
12 | import androidx.compose.ui.Modifier
13 | import androidx.compose.ui.unit.dp
14 | import androidx.lifecycle.compose.collectAsStateWithLifecycle
15 | import androidx.navigation.NavController
16 | import com.rcudev.simplemediaplayer.common.ui.Destination
17 | import com.rcudev.simplemediaplayer.common.ui.SimpleMediaViewModel
18 | import com.rcudev.simplemediaplayer.common.ui.UIState
19 | import com.rcudev.simplemediaplayer.common.ui.components.SimpleMediaPlayerUI
20 |
21 | @Composable
22 | internal fun SimpleMediaScreen(
23 | vm: SimpleMediaViewModel,
24 | navController: NavController,
25 | startService: () -> Unit,
26 | ) {
27 | val state = vm.uiState.collectAsStateWithLifecycle()
28 |
29 | Box(
30 | modifier = Modifier
31 | .fillMaxSize()
32 | .background(MaterialTheme.colorScheme.background)
33 | ) {
34 | when (state.value) {
35 | UIState.Initial -> CircularProgressIndicator(
36 | modifier = Modifier
37 | .size(30.dp)
38 | .align(Alignment.Center)
39 | )
40 | is UIState.Ready -> {
41 | LaunchedEffect(true) { // This is only call first time
42 | startService()
43 | }
44 |
45 | ReadyContent(vm = vm, navController = navController)
46 | }
47 | }
48 |
49 | }
50 | }
51 |
52 | @Composable
53 | private fun ReadyContent(
54 | vm: SimpleMediaViewModel,
55 | navController: NavController,
56 | ) {
57 |
58 | Column(
59 | modifier = Modifier.fillMaxSize(),
60 | verticalArrangement = Arrangement.Center,
61 | horizontalAlignment = Alignment.CenterHorizontally,
62 | ) {
63 | SimpleMediaPlayerUI(
64 | durationString = vm.formatDuration(vm.duration),
65 | playResourceProvider = {
66 | if (vm.isPlaying) android.R.drawable.ic_media_pause
67 | else android.R.drawable.ic_media_play
68 | },
69 | progressProvider = { Pair(vm.progress, vm.progressString) },
70 | onUiEvent = vm::onUIEvent,
71 | )
72 |
73 | FloatingActionButton(
74 | onClick = { navController.navigate(Destination.Secondary.route) },
75 | modifier = Modifier.padding(top = 16.dp)
76 | ) {
77 | Text(
78 | text = "Navigate to Secondary",
79 | modifier = Modifier.padding(horizontal = 16.dp)
80 | )
81 | }
82 | }
83 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/player-service/src/main/java/com/rcudev/player_service/service/notification/SimpleMediaNotificationManager.kt:
--------------------------------------------------------------------------------
1 | package com.rcudev.player_service.service.notification
2 |
3 | import android.app.Notification
4 | import android.app.NotificationChannel
5 | import android.app.NotificationManager
6 | import android.content.Context
7 | import androidx.core.app.NotificationCompat
8 | import androidx.core.app.NotificationManagerCompat
9 | import androidx.media3.common.util.UnstableApi
10 | import androidx.media3.exoplayer.ExoPlayer
11 | import androidx.media3.session.MediaSession
12 | import androidx.media3.session.MediaSessionService
13 | import androidx.media3.ui.PlayerNotificationManager
14 | import com.rcudev.player_service.R
15 | import dagger.hilt.android.qualifiers.ApplicationContext
16 | import javax.inject.Inject
17 |
18 | private const val NOTIFICATION_ID = 200
19 | private const val NOTIFICATION_CHANNEL_NAME = "notification channel 1"
20 | private const val NOTIFICATION_CHANNEL_ID = "notification channel id 1"
21 |
22 | class SimpleMediaNotificationManager @Inject constructor(
23 | @ApplicationContext private val context: Context,
24 | private val player: ExoPlayer
25 | ) {
26 |
27 | private var notificationManager: NotificationManagerCompat =
28 | NotificationManagerCompat.from(context)
29 |
30 | init {
31 | createNotificationChannel()
32 | }
33 |
34 | @UnstableApi
35 | fun startNotificationService(
36 | mediaSessionService: MediaSessionService,
37 | mediaSession: MediaSession
38 | ) {
39 | buildNotification(mediaSession)
40 | startForegroundNotification(mediaSessionService)
41 | }
42 |
43 | @UnstableApi
44 | private fun buildNotification(mediaSession: MediaSession) {
45 | PlayerNotificationManager.Builder(context, NOTIFICATION_ID, NOTIFICATION_CHANNEL_ID)
46 | .setMediaDescriptionAdapter(
47 | SimpleMediaNotificationAdapter(
48 | context = context,
49 | pendingIntent = mediaSession.sessionActivity
50 | )
51 | )
52 | .setSmallIconResourceId(R.drawable.ic_microphone)
53 | .build()
54 | .also {
55 | it.setMediaSessionToken(mediaSession.sessionCompatToken)
56 | it.setUseFastForwardActionInCompactView(true)
57 | it.setUseRewindActionInCompactView(true)
58 | it.setUseNextActionInCompactView(false)
59 | it.setPriority(NotificationCompat.PRIORITY_LOW)
60 | it.setPlayer(player)
61 | }
62 | }
63 |
64 | private fun startForegroundNotification(mediaSessionService: MediaSessionService) {
65 | val notification = Notification.Builder(context, NOTIFICATION_CHANNEL_ID)
66 | .setCategory(Notification.CATEGORY_SERVICE)
67 | .build()
68 | mediaSessionService.startForeground(NOTIFICATION_ID, notification)
69 | }
70 |
71 | private fun createNotificationChannel() {
72 | val channel = NotificationChannel(
73 | NOTIFICATION_CHANNEL_ID,
74 | NOTIFICATION_CHANNEL_NAME,
75 | NotificationManager.IMPORTANCE_LOW
76 | )
77 | notificationManager.createNotificationChannel(channel)
78 | }
79 | }
--------------------------------------------------------------------------------
/player-service/src/main/java/com/rcudev/player_service/service/SimpleMediaServiceHandler.kt:
--------------------------------------------------------------------------------
1 | package com.rcudev.player_service.service
2 |
3 | import android.annotation.SuppressLint
4 | import androidx.media3.common.MediaItem
5 | import androidx.media3.common.Player
6 | import androidx.media3.exoplayer.ExoPlayer
7 | import kotlinx.coroutines.*
8 | import kotlinx.coroutines.flow.MutableStateFlow
9 | import kotlinx.coroutines.flow.asStateFlow
10 | import javax.inject.Inject
11 |
12 | class SimpleMediaServiceHandler @Inject constructor(
13 | private val player: ExoPlayer
14 | ) : Player.Listener {
15 |
16 | private val _simpleMediaState = MutableStateFlow(SimpleMediaState.Initial)
17 | val simpleMediaState = _simpleMediaState.asStateFlow()
18 |
19 | private var job: Job? = null
20 |
21 | init {
22 | player.addListener(this)
23 | job = Job()
24 | }
25 |
26 | fun addMediaItem(mediaItem: MediaItem) {
27 | player.setMediaItem(mediaItem)
28 | player.prepare()
29 | }
30 |
31 | fun addMediaItemList(mediaItemList: List) {
32 | player.setMediaItems(mediaItemList)
33 | player.prepare()
34 | }
35 |
36 | suspend fun onPlayerEvent(playerEvent: PlayerEvent) {
37 | when (playerEvent) {
38 | PlayerEvent.Backward -> player.seekBack()
39 | PlayerEvent.Forward -> player.seekForward()
40 | PlayerEvent.PlayPause -> {
41 | if (player.isPlaying) {
42 | player.pause()
43 | stopProgressUpdate()
44 | } else {
45 | player.play()
46 | _simpleMediaState.value = SimpleMediaState.Playing(isPlaying = true)
47 | startProgressUpdate()
48 | }
49 | }
50 | PlayerEvent.Stop -> stopProgressUpdate()
51 | is PlayerEvent.UpdateProgress -> player.seekTo((player.duration * playerEvent.newProgress).toLong())
52 | }
53 | }
54 |
55 | @SuppressLint("SwitchIntDef")
56 | override fun onPlaybackStateChanged(playbackState: Int) {
57 | when (playbackState) {
58 | ExoPlayer.STATE_BUFFERING -> _simpleMediaState.value =
59 | SimpleMediaState.Buffering(player.currentPosition)
60 | ExoPlayer.STATE_READY -> _simpleMediaState.value =
61 | SimpleMediaState.Ready(player.duration)
62 | }
63 | }
64 |
65 | @OptIn(DelicateCoroutinesApi::class)
66 | override fun onIsPlayingChanged(isPlaying: Boolean) {
67 | _simpleMediaState.value = SimpleMediaState.Playing(isPlaying = isPlaying)
68 | if (isPlaying) {
69 | GlobalScope.launch(Dispatchers.Main) {
70 | startProgressUpdate()
71 | }
72 | } else {
73 | stopProgressUpdate()
74 | }
75 | }
76 |
77 | private suspend fun startProgressUpdate() = job.run {
78 | while (true) {
79 | delay(500)
80 | _simpleMediaState.value = SimpleMediaState.Progress(player.currentPosition)
81 | }
82 | }
83 |
84 | private fun stopProgressUpdate() {
85 | job?.cancel()
86 | _simpleMediaState.value = SimpleMediaState.Playing(isPlaying = false)
87 | }
88 | }
89 |
90 | sealed class PlayerEvent {
91 | object PlayPause : PlayerEvent()
92 | object Backward : PlayerEvent()
93 | object Forward : PlayerEvent()
94 | object Stop : PlayerEvent()
95 | data class UpdateProgress(val newProgress: Float) : PlayerEvent()
96 | }
97 |
98 | sealed class SimpleMediaState {
99 | object Initial : SimpleMediaState()
100 | data class Ready(val duration: Long) : SimpleMediaState()
101 | data class Progress(val progress: Long) : SimpleMediaState()
102 | data class Buffering(val progress: Long) : SimpleMediaState()
103 | data class Playing(val isPlaying: Boolean) : SimpleMediaState()
104 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # SimpleMediaPlayer
4 |
5 | With the arrival of media3 and for professional reasons, I have had to do a lot of research on the use of media3 for background audio playback using one of the different available services such as **MediaSessionService**, **MediaLibraryService** and **MediaBrowserService**. Also, I needed to display notifications on both the status bar and the lock screen.
6 |
7 | During the time that I was documented, I realized that there were few clear examples of the use of these services. Including those available in Android's own repositories (https://github.com/android/uamp, https://github.com/androidx/media), they are all difficult to follow and understand if what you are looking for it is simplicity and only having the necessary features to play music in the background with notifications.
8 |
9 | **Goal**
10 |
11 | The purpose of creating this repository is to present a simpler approach, creating only the necessary classes to comply with the features that I will describe in the next point, but without neglecting a logical, meaningful and reactive structure.
12 |
13 | I have not focused on UI, although I will update it to show the potential that a clean, simple service with features that could be assimilated to those offered by Spotify (with a bit of evolution) can have.
14 |
15 | **Features**
16 | - Modularized service to abstract dependencies.
17 | - Play music using the internal ExoPlayer client in media3.
18 | - MediaSessionService in the background that will allow us to have a shared playback service so that it can be played anywhere in the application.
19 | - Notifications both in the status bar and on the lock screen with media controls.
20 | - Updating playback status both in notifications and in-app view.
21 | - Shared viewmodel that allows to navigate to other screen with a second media player and continue play back.
22 |
23 | These features are specific to the example, but I'm really going to put the emphasis on the service, the control of it, and the notifications, classes that I will detail below, which are found in the service module.
24 |
25 | ## player-service Module
26 |
27 | ### SimpleMediaService
28 |
29 | **SimpleMediaService** inherits from **MediaSessionService** and feeds on hilt-injected classes (see **SimpleMediaModule** for more details). The injected classes are as follows:
30 | - **ExoPlayer**: playback client that will be shared in order to control common states.
31 | - **MediaSession**: this is the most important class because it is what creates the magic to be able to share the replay session with whoever needs it, including service and notifications.
32 | - **SimpleMediaNotificationManager**: is a class of its own that I will detail in the next point.
33 |
34 | ### SimpleMediaNotificationManager
35 |
36 | **SimpleMediaNotificationManager** has three main functions:
37 | - Create a notification channel.
38 | - Start the background service by assigning an ID and a notification.
39 | - Create the notification by assigning both the MediaSession **Token** and the **player** to it. Both are essential to be able to control the audio with notifications and to be able to see its progress.
40 |
41 | In this class is where we can create our custom notification with the controls, icons or images that we want.
42 |
43 | ### SimpleMediaNotificationAdapter
44 |
45 | **SimpleMediaNotificationAdapter** is used by SimpleMediaNotificationManager added to notification builder to get automaticatly metadata from the player and show album title, song title and image. All this data is added when MediaItem is created.
46 |
47 | ### SimpleMediaServiceHandler
48 |
49 | **SimpleMediaServiceHandler** is a bridge to be able to communicate the application with the service, because the only common dependency that is necessary to have is the one corresponding to the MediaSession.
50 |
51 | Two sealed classes are used that encapsulate the actions and events necessary to coordinate the state of the playback:
52 | - **PlayerEvent**: contains the actions performed by the user and through the **onPlayerEvent** method the state of the player is controlled.
53 | - **SimpleMediaState**: contains the states that will be emitted through a **StateFlow**. In the example the VM collects any emitted changes and thus updates the custom controls.
54 |
55 | Besides, it is in charge of arranging the necessary methods to add the MediaItem, be it one or a list.
56 |
57 | ## Conclusions
58 |
59 | A simple and clear playback service with notifications, with a reactive architecture. I will continue checking improvements, this is still an imperfect approach (nothing is perfect), improvable but that provides what is necessary without complications.
60 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rcudev/simplemediaplayer/common/ui/SimpleMediaViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.rcudev.simplemediaplayer.common.ui
2 |
3 | import android.net.Uri
4 | import androidx.compose.runtime.mutableStateOf
5 | import androidx.lifecycle.SavedStateHandle
6 | import androidx.lifecycle.ViewModel
7 | import androidx.lifecycle.viewModelScope
8 | import androidx.lifecycle.viewmodel.compose.SavedStateHandleSaveableApi
9 | import androidx.lifecycle.viewmodel.compose.saveable
10 | import androidx.media3.common.MediaItem
11 | import androidx.media3.common.MediaMetadata
12 | import com.rcudev.player_service.service.PlayerEvent
13 | import com.rcudev.player_service.service.SimpleMediaServiceHandler
14 | import com.rcudev.player_service.service.SimpleMediaState
15 | import dagger.hilt.android.lifecycle.HiltViewModel
16 | import kotlinx.coroutines.flow.MutableStateFlow
17 | import kotlinx.coroutines.flow.asStateFlow
18 | import kotlinx.coroutines.launch
19 | import java.util.concurrent.TimeUnit
20 | import javax.inject.Inject
21 |
22 | @OptIn(SavedStateHandleSaveableApi::class)
23 | @HiltViewModel
24 | class SimpleMediaViewModel @Inject constructor(
25 | private val simpleMediaServiceHandler: SimpleMediaServiceHandler,
26 | savedStateHandle: SavedStateHandle
27 | ) : ViewModel() {
28 |
29 | var duration by savedStateHandle.saveable { mutableStateOf(0L) }
30 | var progress by savedStateHandle.saveable { mutableStateOf(0f) }
31 | var progressString by savedStateHandle.saveable { mutableStateOf("00:00") }
32 | var isPlaying by savedStateHandle.saveable { mutableStateOf(false) }
33 |
34 | private val _uiState = MutableStateFlow(UIState.Initial)
35 | val uiState = _uiState.asStateFlow()
36 |
37 | init {
38 | viewModelScope.launch {
39 | loadData()
40 |
41 | simpleMediaServiceHandler.simpleMediaState.collect { mediaState ->
42 | when (mediaState) {
43 | is SimpleMediaState.Buffering -> calculateProgressValues(mediaState.progress)
44 | SimpleMediaState.Initial -> _uiState.value = UIState.Initial
45 | is SimpleMediaState.Playing -> isPlaying = mediaState.isPlaying
46 | is SimpleMediaState.Progress -> calculateProgressValues(mediaState.progress)
47 | is SimpleMediaState.Ready -> {
48 | duration = mediaState.duration
49 | _uiState.value = UIState.Ready
50 | }
51 | }
52 | }
53 | }
54 | }
55 |
56 | override fun onCleared() {
57 | viewModelScope.launch {
58 | simpleMediaServiceHandler.onPlayerEvent(PlayerEvent.Stop)
59 | }
60 | }
61 |
62 | fun onUIEvent(uiEvent: UIEvent) = viewModelScope.launch {
63 | when (uiEvent) {
64 | UIEvent.Backward -> simpleMediaServiceHandler.onPlayerEvent(PlayerEvent.Backward)
65 | UIEvent.Forward -> simpleMediaServiceHandler.onPlayerEvent(PlayerEvent.Forward)
66 | UIEvent.PlayPause -> simpleMediaServiceHandler.onPlayerEvent(PlayerEvent.PlayPause)
67 | is UIEvent.UpdateProgress -> {
68 | progress = uiEvent.newProgress
69 | simpleMediaServiceHandler.onPlayerEvent(
70 | PlayerEvent.UpdateProgress(
71 | uiEvent.newProgress
72 | )
73 | )
74 | }
75 | }
76 | }
77 |
78 | fun formatDuration(duration: Long): String {
79 | val minutes: Long = TimeUnit.MINUTES.convert(duration, TimeUnit.MILLISECONDS)
80 | val seconds: Long = (TimeUnit.SECONDS.convert(duration, TimeUnit.MILLISECONDS)
81 | - minutes * TimeUnit.SECONDS.convert(1, TimeUnit.MINUTES))
82 | return String.format("%02d:%02d", minutes, seconds)
83 | }
84 |
85 | private fun calculateProgressValues(currentProgress: Long) {
86 | progress = if (currentProgress > 0) (currentProgress.toFloat() / duration) else 0f
87 | progressString = formatDuration(currentProgress)
88 | }
89 |
90 | private fun loadData() {
91 | val mediaItem = MediaItem.Builder()
92 | .setUri("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3")
93 | .setMediaMetadata(
94 | MediaMetadata.Builder()
95 | .setFolderType(MediaMetadata.FOLDER_TYPE_ALBUMS)
96 | .setArtworkUri(Uri.parse("https://i.pinimg.com/736x/4b/02/1f/4b021f002b90ab163ef41aaaaa17c7a4.jpg"))
97 | .setAlbumTitle("SoundHelix")
98 | .setDisplayTitle("Song 1")
99 | .build()
100 | ).build()
101 |
102 | //val mediaItemList = mutableListOf()
103 | //(1..17).forEach {
104 | // mediaItemList.add(
105 | // MediaItem.Builder()
106 | // .setUri("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-$it.mp3")
107 | // .setMediaMetadata(MediaMetadata.Builder()
108 | // .setFolderType(MediaMetadata.FOLDER_TYPE_ALBUMS)
109 | // .setArtworkUri(Uri.parse("https://cdns-images.dzcdn.net/images/cover/1fddc1ab0535ee34189dc4c9f5f87bf9/264x264.jpg"))
110 | // .setAlbumTitle("SoundHelix")
111 | // .setDisplayTitle("Song $it")
112 | // .build()
113 | // ).build()
114 | // )
115 | //}
116 |
117 | simpleMediaServiceHandler.addMediaItem(mediaItem)
118 | //simpleMediaServiceHandler.addMediaItemList(mediaItemList)
119 | }
120 |
121 | }
122 |
123 | sealed class UIEvent {
124 | object PlayPause : UIEvent()
125 | object Backward : UIEvent()
126 | object Forward : UIEvent()
127 | data class UpdateProgress(val newProgress: Float) : UIEvent()
128 | }
129 |
130 | sealed class UIState {
131 | object Initial : UIState()
132 | object Ready : UIState()
133 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------