All Downloads are FREE. Search and download functionalities are using the official Maven repository.

androidMain.tech.skot.libraries.video.SKAudioApplicationExtension.kt Maven / Gradle / Ivy

There is a newer version: 0.2.4_1.2.7
Show newest version
package tech.skot.libraries.video

import android.app.Application
import android.content.Intent
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ProcessLifecycleOwner
import tech.skot.core.SKLog

fun Application.bindAudioService(audioService: Class) {

    ProcessLifecycleOwner.get().lifecycle.addObserver(
        object : DefaultLifecycleObserver {
            override fun onStart(owner: LifecycleOwner) {
                super.onStart(owner)
                startService(Intent(applicationContext, audioService).apply {
                    action = SKAudioService.ACTION_FOREGROUND
                })
            }

            override fun onStop(owner: LifecycleOwner) {
                super.onStop(owner)
                startService(Intent(applicationContext, audioService).apply {
                    action = SKAudioService.ACTION_BACKGROUND
                })
            }


        }
    )
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy