Код: Выделить всё
class Sound(): Service() {
private var mainSoundPlayer = MediaPlayer()
override fun onBind(arg0: Intent?): IBinder? {
return null
}
override fun onCreate() {
super.onCreate()
mainSoundPlayer = MediaPlayer.create(this, R.raw.mainsound)
mainSoundPlayer.isLooping = true
mainSoundPlayer.start()
}
override fun onDestroy() {
super.onDestroy()
}
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... foreground