I've used the code from this existing post to play an MP3 file:
package com.mjr.testsound
import android.media.MediaPlayer
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (savedInstanceState == null) {
val mp: MediaPlayer = MediaPlayer.create(applicationContext, R.raw.guitar3)
mp.start()
}
setContentView(R.layout.activity_main)
}
}
The weird thing is that it cuts out after a second if it's played in the MAIN startup activity, but it works fine if played in a second activity. Any idea what's happening?
Also I know that the activity is not terminating, I've logged the activity lifecycle and the cut out happens well before OnPause is logged.