Skip to content

Commit

Permalink
player: Notification stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
mikooomich committed Jan 26, 2025
1 parent f739037 commit 984795b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/dd3boh/outertune/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class MainActivity : ComponentActivity() {
override fun onStart() {
super.onStart()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startService(Intent(this, MusicService::class.java))
startForegroundService(Intent(this, MusicService::class.java))
} else {
startService(Intent(this, MusicService::class.java))
}
Expand Down
18 changes: 10 additions & 8 deletions app/src/main/java/com/dd3boh/outertune/playback/MusicService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import androidx.media3.exoplayer.audio.DefaultAudioSink
import androidx.media3.exoplayer.audio.SilenceSkippingAudioProcessor
import androidx.media3.exoplayer.source.DefaultMediaSourceFactory
import androidx.media3.session.CommandButton
import androidx.media3.session.DefaultMediaNotificationProvider
import androidx.media3.session.MediaController
import androidx.media3.session.MediaLibraryService
import androidx.media3.session.MediaSession
Expand Down Expand Up @@ -192,14 +193,15 @@ class MusicService : MediaLibraryService(),

override fun onCreate() {
super.onCreate()
val notificationBuilder = NotificationCompat.Builder(this, KEEP_ALIVE_CHANNEL_ID)
.setContentTitle(getString(R.string.music_player))
.setSmallIcon(R.drawable.small_icon)
.setOngoing(true) // Ensures notification stays until service stops

val notification = notificationBuilder.build()
setMediaNotificationProvider(
DefaultMediaNotificationProvider(this, { NOTIFICATION_ID },
CHANNEL_ID, R.string.music_player)
.apply {
setSmallIcon(R.drawable.small_icon)
}
)

// FG notification
// FG keep alive
if (dataStore.get(KeepAliveKey, false)) {
try {
startService(Intent(this, KeepAlive::class.java))
Expand Down Expand Up @@ -888,7 +890,7 @@ class MusicService : MediaLibraryService(),
const val PLAYLIST = "playlist"

const val CHANNEL_ID = "music_channel_01"
const val KEEP_ALIVE_CHANNEL_ID = "outertune_keep_alive"
const val NOTIFICATION_ID = 888
const val ERROR_CODE_NO_STREAM = 1000001
const val CHUNK_LENGTH = 512 * 1024L
}
Expand Down

0 comments on commit 984795b

Please sign in to comment.