mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
add documentation
This commit is contained in:
parent
955d6de690
commit
6945f29282
@ -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")
|
||||
}
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user