I have a problem with service.
In method onCreate I'm creating media player. When I'm moving between activities, I'm able to access service smoothly and it keeps the same media player instance. Although, when I leave application (audio from services mediaplayer is still playing) and then I return to application - I get new MediaPlayer instance. Audio stream from previous instance is still playing.
I would like to have the access to the same instance of MediaPlayer as preiously to manipulate playing song (pause for example).
Do you know what may be the issue?
class PlayerService : Service(), MediaPlayer.OnPreparedListener, PlayerServiceContract.ServiceContract {
private val mBinder = PlayerBinder()
private var mPlayer: MediaPlayer? = null
private var mPresenter: PlayerServiceContract.Presenter? = null
private var mRecording: Recording? = null
override fun onCreate() {
super.onCreate()
mPlayer = MediaPlayer()
mPlayer?.setWakeMode(applicationContext,
PowerManager.PARTIAL_WAKE_LOCK)
mPlayer?.setAudioStreamType(AudioManager.STREAM_MUSIC)
mPlayer?.setOnPreparedListener(this)