add documentation

This commit is contained in:
Bnyro 2022-08-07 19:15:23 +02:00
parent 955d6de690
commit 6945f29282
2 changed files with 27 additions and 9 deletions

View File

@ -68,11 +68,11 @@ class BackgroundMode : Service() {
*/
private lateinit var nowPlayingNotification: NowPlayingNotification
/**
* Setting the required [notification] for running as a foreground service
*/
override fun onCreate() {
super.onCreate()
/**
* setting the required notification for running as a foreground service
*/
if (Build.VERSION.SDK_INT >= 26) {
val channelId = BACKGROUND_CHANNEL_ID
val channel = NotificationChannel(
@ -169,11 +169,7 @@ class BackgroundMode : Service() {
if (autoplay) playNextVideo()
}
Player.STATE_IDLE -> {
// called when the user pressed stop in the notification
// stop the service from being in the foreground and remove the notification
stopForeground(true)
// destroy the service
stopSelf()
onDestroy()
}
}
}
@ -243,6 +239,19 @@ class BackgroundMode : Service() {
}
}
/**
* destroy the [BackgroundMode] foreground service
*/
override fun onDestroy() {
// called when the user pressed stop in the notification
// stop the service from being in the foreground and remove the notification
stopForeground(true)
// destroy the service
stopSelf()
if (this::nowPlayingNotification.isInitialized) nowPlayingNotification.destroy()
super.onDestroy()
}
override fun onBind(p0: Intent?): IBinder? {
TODO("Not yet implemented")
}

View File

@ -117,6 +117,9 @@ class NowPlayingNotification(
}
}
/**
* Creates a [MediaSessionCompat] amd a [MediaSessionConnector] for the player
*/
private fun createMediaSession() {
if (this::mediaSession.isInitialized) return
mediaSession = MediaSessionCompat(context, this.javaClass.name)
@ -127,7 +130,7 @@ class NowPlayingNotification(
}
/**
* Initializes the [playerNotification] attached to the [player] and shows it.
* Updates or creates the [playerNotification]
*/
fun updatePlayerNotification(
streams: Streams
@ -139,6 +142,9 @@ class NowPlayingNotification(
}
}
/**
* Initializes the [playerNotification] attached to the [player] and shows it.
*/
private fun createNotification() {
playerNotification = PlayerNotificationManager
.Builder(context, PLAYER_NOTIFICATION_ID, BACKGROUND_CHANNEL_ID)
@ -157,6 +163,9 @@ class NowPlayingNotification(
}
}
/**
* Destroy the [NowPlayingNotification]
*/
fun destroy() {
mediaSession.isActive = false
mediaSession.release()