mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
Add the notification player
Now when you select a video to play it in the background mode, appears a notification (for now does nothing).
This commit is contained in:
parent
87430dc21e
commit
cb6579362e
@ -4,6 +4,7 @@ import android.content.Context
|
||||
import com.github.libretube.obj.Streams
|
||||
import com.google.android.exoplayer2.ExoPlayer
|
||||
import com.google.android.exoplayer2.MediaItem
|
||||
import com.google.android.exoplayer2.ui.PlayerNotificationManager
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
@ -22,6 +23,8 @@ class BackgroundMode {
|
||||
private var player: ExoPlayer? = null
|
||||
private var playWhenReadyPlayer = true
|
||||
|
||||
private var playerNotificationManager: PlayerNotificationManager? = null
|
||||
|
||||
/**
|
||||
* Initializes the [player] player with the [MediaItem].
|
||||
*/
|
||||
@ -30,6 +33,15 @@ class BackgroundMode {
|
||||
setMediaItem()
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the [playerNotificationManager] attached to the [player].
|
||||
*/
|
||||
private fun initializePlayerNotification(c: Context) {
|
||||
playerNotificationManager =
|
||||
PlayerNotificationManager.Builder(c, 1, "background_mode").build()
|
||||
playerNotificationManager?.setPlayer(player)
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases the [player].
|
||||
*/
|
||||
@ -60,6 +72,7 @@ class BackgroundMode {
|
||||
job.join()
|
||||
|
||||
initializePlayer(c)
|
||||
initializePlayerNotification(c)
|
||||
|
||||
player?.apply {
|
||||
playWhenReady = playWhenReadyPlayer
|
||||
|
@ -1,11 +1,36 @@
|
||||
package com.github.libretube
|
||||
|
||||
import android.app.Application
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.os.Build
|
||||
|
||||
class myApp : Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
initializeNotificationChannels()
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the required [NotificationChannel] for the app.
|
||||
*/
|
||||
private fun initializeNotificationChannels() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
// Create the NotificationChannel
|
||||
val name = "Background Mode"
|
||||
val descriptionText = "Shows a notification with buttons to control the audio player"
|
||||
val importance = NotificationManager.IMPORTANCE_DEFAULT
|
||||
val mChannel = NotificationChannel("background_mode", name, importance)
|
||||
mChannel.description = descriptionText
|
||||
|
||||
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.createNotificationChannel(mChannel)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
var seekTo : Long? = 0
|
||||
var seekTo: Long? = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user