mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +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
|
private lateinit var nowPlayingNotification: NowPlayingNotification
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setting the required [notification] for running as a foreground service
|
||||||
|
*/
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
/**
|
|
||||||
* setting the required notification for running as a foreground service
|
|
||||||
*/
|
|
||||||
if (Build.VERSION.SDK_INT >= 26) {
|
if (Build.VERSION.SDK_INT >= 26) {
|
||||||
val channelId = BACKGROUND_CHANNEL_ID
|
val channelId = BACKGROUND_CHANNEL_ID
|
||||||
val channel = NotificationChannel(
|
val channel = NotificationChannel(
|
||||||
@ -169,11 +169,7 @@ class BackgroundMode : Service() {
|
|||||||
if (autoplay) playNextVideo()
|
if (autoplay) playNextVideo()
|
||||||
}
|
}
|
||||||
Player.STATE_IDLE -> {
|
Player.STATE_IDLE -> {
|
||||||
// called when the user pressed stop in the notification
|
onDestroy()
|
||||||
// stop the service from being in the foreground and remove the notification
|
|
||||||
stopForeground(true)
|
|
||||||
// destroy the service
|
|
||||||
stopSelf()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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? {
|
override fun onBind(p0: Intent?): IBinder? {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
@ -117,6 +117,9 @@ class NowPlayingNotification(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a [MediaSessionCompat] amd a [MediaSessionConnector] for the player
|
||||||
|
*/
|
||||||
private fun createMediaSession() {
|
private fun createMediaSession() {
|
||||||
if (this::mediaSession.isInitialized) return
|
if (this::mediaSession.isInitialized) return
|
||||||
mediaSession = MediaSessionCompat(context, this.javaClass.name)
|
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(
|
fun updatePlayerNotification(
|
||||||
streams: Streams
|
streams: Streams
|
||||||
@ -139,6 +142,9 @@ class NowPlayingNotification(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the [playerNotification] attached to the [player] and shows it.
|
||||||
|
*/
|
||||||
private fun createNotification() {
|
private fun createNotification() {
|
||||||
playerNotification = PlayerNotificationManager
|
playerNotification = PlayerNotificationManager
|
||||||
.Builder(context, PLAYER_NOTIFICATION_ID, BACKGROUND_CHANNEL_ID)
|
.Builder(context, PLAYER_NOTIFICATION_ID, BACKGROUND_CHANNEL_ID)
|
||||||
@ -157,6 +163,9 @@ class NowPlayingNotification(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy the [NowPlayingNotification]
|
||||||
|
*/
|
||||||
fun destroy() {
|
fun destroy() {
|
||||||
mediaSession.isActive = false
|
mediaSession.isActive = false
|
||||||
mediaSession.release()
|
mediaSession.release()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user