LibreTube/app/src/main/java/com/github/libretube/util/BackgroundHelper.kt

27 lines
823 B
Kotlin
Raw Normal View History

2022-07-23 19:11:57 +05:30
package com.github.libretube.util
import android.content.Context
import android.content.Intent
import com.github.libretube.services.BackgroundMode
2022-08-08 14:13:46 +05:30
/**
* Helper for starting a new Instance of the [BackgroundMode]
*/
2022-07-23 19:11:57 +05:30
object BackgroundHelper {
fun playOnBackground(
context: Context,
videoId: String,
2022-08-08 14:13:46 +05:30
position: Long? = null,
playlistId: String? = null
2022-07-23 19:11:57 +05:30
) {
2022-08-08 14:13:46 +05:30
// create an intent for the background mode service
2022-07-23 19:11:57 +05:30
val intent = Intent(context, BackgroundMode::class.java)
intent.putExtra("videoId", videoId)
2022-08-08 14:13:46 +05:30
if (playlistId != null) intent.putExtra("playlistId", playlistId)
2022-07-23 19:11:57 +05:30
if (position != null) intent.putExtra("position", position)
2022-08-08 14:13:46 +05:30
// start the background mode as foreground service
2022-07-23 19:11:57 +05:30
context.startForegroundService(intent)
}
}