Skip to content

Commit

Permalink
ui: Updated to Canary BOM (2024.04.00-alpha02)
Browse files Browse the repository at this point in the history
fix: Made player survive screen rotations

Signed-off-by: Gabriel Fontán <[email protected]>
  • Loading branch information
BobbyESP committed Apr 27, 2024
1 parent 9ffbdf8 commit 05d30c7
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ dependencies {

//---------------User Interface---------------//
//Core UI libraries
api(platform(libs.compose.bom))
api(platform(libs.compose.bom.canary))

//Accompanist libraries
implementation(libs.bundles.accompanist)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ package com.bobbyesp.mediaplayer.service
import androidx.media3.common.MediaItem
import androidx.media3.common.MediaMetadata
import androidx.media3.common.Player
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.exoplayer.analytics.AnalyticsListener
import androidx.media3.exoplayer.analytics.PlaybackStats
import androidx.media3.exoplayer.analytics.PlaybackStatsListener
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -16,9 +20,10 @@ import javax.inject.Inject
* It provides methods to control the media player such as play, pause, stop, and seek.
* It also provides methods to manage the media queue such as set, add, and remove media items.
*/
@UnstableApi
class MediaServiceHandler @Inject constructor(
private val player: ExoPlayer
) : Player.Listener {
) : Player.Listener, PlaybackStatsListener.Callback {
private val _mediaState = MutableStateFlow<MediaState>(MediaState.Idle)
val mediaState = _mediaState.asStateFlow()

Expand Down Expand Up @@ -208,6 +213,13 @@ class MediaServiceHandler @Inject constructor(
MediaState.Playing(false)
}
}

override fun onPlaybackStatsReady(
eventTime: AnalyticsListener.EventTime,
playbackStats: PlaybackStats
) {
TODO("Not yet implemented")
}
}

sealed class PlayerEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import com.bobbyesp.mediaplayer.service.notifications.MediaNotificationManager
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@UnstableApi
@AndroidEntryPoint
class MediaplayerService : MediaSessionService() {

@Inject
lateinit var mediaSession: MediaSession

Expand Down Expand Up @@ -50,10 +50,14 @@ class MediaplayerService : MediaSessionService() {
super.onDestroy()
}

override fun onGetSession(controllerInfo: MediaSession.ControllerInfo): MediaSession {
return mediaSession
override fun onTaskRemoved(rootIntent: Intent?) {
super.onTaskRemoved(rootIntent)
stopSelf()
}

override fun onGetSession(controllerInfo: MediaSession.ControllerInfo): MediaSession =
mediaSession

inner class MusicBinder : Binder() {
val service: MediaplayerService
get() = this@MediaplayerService
Expand Down
17 changes: 10 additions & 7 deletions app/src/main/java/com/bobbyesp/metadator/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat
import androidx.media3.common.util.UnstableApi
import com.bobbyesp.mediaplayer.service.ConnectionHandler
import com.bobbyesp.mediaplayer.service.MediaplayerService
import com.bobbyesp.metadator.presentation.Navigator
Expand All @@ -24,6 +25,7 @@ import dagger.hilt.android.AndroidEntryPoint
import setupFirebase
import javax.inject.Inject

@androidx.annotation.OptIn(UnstableApi::class)
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
private var isMusicPlayerServiceStarted = false
Expand All @@ -44,7 +46,6 @@ class MainActivity : ComponentActivity() {
}
activity = this
setupFirebase()
startMediaPlayerService()
setContent {
val windowSizeClass = calculateWindowSizeClass(this)
AppLocalSettingsProvider(windowSizeClass.widthSizeClass, connectionHandler) {
Expand All @@ -58,9 +59,13 @@ class MainActivity : ComponentActivity() {
}
}

override fun onDestroy() {
super.onDestroy()
stopService(Intent(this, MediaplayerService::class.java))
override fun onStart() {
super.onStart()
startMediaPlayerService()
}

override fun onStop() {
super.onStop()
unbindService(serviceConnection)
isMusicPlayerServiceStarted = false
}
Expand Down Expand Up @@ -96,8 +101,6 @@ class MainActivity : ComponentActivity() {

companion object {
private lateinit var activity: MainActivity
fun getActivity(): MainActivity {
return activity
}
fun getActivity(): MainActivity = activity
}
}
26 changes: 13 additions & 13 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
[versions]
#General, lifecycle and core
agp = "8.5.0-alpha02"
agp = "8.5.0-alpha06"
firebaseCrashlyticsGradle = "2.9.9"
gradle = "8.5.0-alpha02"
gradle = "8.5.0-alpha06"
kotlin = "1.9.23"
appcompat = "1.7.0-alpha03"
core-ktx = "1.12.0"
core-ktx = "1.13.0"
legacySupportV4 = "1.0.0"
lifecycle-runtime-ktx = "2.7.0"
activity-compose = "1.8.2"
activity-compose = "1.9.0"
compose-compiler = "1.5.11"
ksp = "1.9.23-1.0.19"
lyricfier = "1.0"
splashscreen = "1.0.1"
material = "1.11.0"
media3 = "1.3.0"
media3 = "1.3.1"
leakcanary = "2.13"

#Compose
compose-bom = "2024.04.00"
compose-bom-canary = "2024.04.00-alpha01"
compose-bom = "2024.04.01"
compose-bom-canary = "2024.04.00-alpha02"
constraintLayout = "1.1.0-alpha13"
androidx-compose-material3 = "1.2.1"
compose-util = "1.6.5"
compose-util = "1.6.6"
accompanist = "0.34.0"
compose-pagination = "3.2.1"
commonsIo = "2.15.0"
Expand Down Expand Up @@ -62,7 +62,7 @@ hilt-ext = "1.2.0"

#Database
room = "2.6.1"
datastore = "1.0.0"
datastore = "1.1.0"

#High performance Key-value storage
mmkv = "1.3.2"
Expand All @@ -75,9 +75,9 @@ markdown = "0.3.7"

#Firebase, GMS...
firebaseAuth = "22.3.1"
gmsPlayServicesAuth = "21.0.0"
gmsPlayServicesAuth = "21.1.0"
googleServices = "4.4.1"
firebaseBom = "32.8.0"
firebaseBom = "32.8.1"

#Others
taglib = "1.0.0-alpha07"
Expand Down Expand Up @@ -116,7 +116,7 @@ compose-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
compose-runtime = { group = "androidx.compose.runtime", name = "runtime" }
compose-foundation = { group = "androidx.compose.foundation", name = "foundation" }
compose-material-iconsExtended = { group = "androidx.compose.material", name = "material-icons-extended" }
compose-animation-graphics = { group = "androidx.compose.animation", name = "animation-graphics" }
compose-animation = { group = "androidx.compose.animation", name = "animation" }
compose-ui = { group = "androidx.compose.ui", name = "ui" }
compose-material = { group = "androidx.compose.material", name = "material" }
compose-ui-util = { group = "androidx.compose.ui", name = "ui-util", version.ref = "compose-util" }
Expand Down Expand Up @@ -263,7 +263,7 @@ androidx-baselineprofile = { id = "androidx.baselineprofile", version.ref = "and
core = ["core-ktx", "lifecycle-runtime-ktx", "lifecycle-compose-runtime", "lifecycle-compose-viewModel", "activity-compose", "core-appcompat", "core-splashscreen"]
ktor = ["ktor-android", "ktor-okhttp" ,"ktor-core", "ktor-serialization", "ktor-logging", "ktor-contentnegotiation", "ktor-encoding"]
accompanist = ["accompanist-navigation-animation", "accompanist-permissions", "accompanist-webview", "accompanist-pager-layouts", "accompanist-pager-indicators", "accompanist-flowlayout", "accompanist-material"]
compose = ["compose-ui-util","compose-graphics", "compose-runtime", "compose-foundation", "compose-material-iconsExtended", "compose-animation-graphics", "compose-ui", "compose-material", "compose-material3", "compose-navigation" ,"compose-material3-windowSizeClass", "compose-constraintLayout"]
compose = ["compose-ui-util", "compose-graphics", "compose-runtime", "compose-foundation", "compose-material-iconsExtended", "compose-animation", "compose-ui", "compose-material", "compose-material3", "compose-navigation", "compose-material3-windowSizeClass", "compose-constraintLayout"]
hilt = ["compose-hilt-navigation", "hilt-android"]
hilt-kapt = ["hilt-compiler", "hilt-ext-compiler"]
pagination = ["paging-compose", "paging-runtime"]
Expand Down

0 comments on commit 05d30c7

Please sign in to comment.