Categories
Mastering Development

Media Player has not been initialized but song is playing

I added a song to my app using MediaPlayer, like that: class BackgroundSongService : Service() { private lateinit var mediaPlayer: MediaPlayer private var length = 0 override fun onBind(p0: Intent?): IBinder? { return null } override fun onCreate() { super.onCreate() mediaPlayer = MediaPlayer.create(this, R.raw.bonte_song) mediaPlayer.isLooping = true mediaPlayer.setVolume(20f, 20f) } override fun onDestroy() { mediaPlayer.stop() […]