mediaPlayer 를 사용하는 곳은 항상 초기화 되어 있는지 확인 하고 로직이 실행되도록 수정
This commit is contained in:
parent
a4cdbebeb4
commit
f7299cc0df
|
@ -146,7 +146,7 @@ class AudioContentPlayService :
|
||||||
}
|
}
|
||||||
|
|
||||||
MusicAction.PLAY.name -> {
|
MusicAction.PLAY.name -> {
|
||||||
if (!isPlaying) {
|
if (!isPlaying && this::mediaPlayer.isInitialized) {
|
||||||
mediaPlayer.start()
|
mediaPlayer.start()
|
||||||
toggleIsPlaying()
|
toggleIsPlaying()
|
||||||
updateNotification()
|
updateNotification()
|
||||||
|
@ -154,7 +154,7 @@ class AudioContentPlayService :
|
||||||
}
|
}
|
||||||
|
|
||||||
MusicAction.PAUSE.name -> {
|
MusicAction.PAUSE.name -> {
|
||||||
if (isPlaying) {
|
if (isPlaying && this::mediaPlayer.isInitialized) {
|
||||||
mediaPlayer.pause()
|
mediaPlayer.pause()
|
||||||
toggleIsPlaying()
|
toggleIsPlaying()
|
||||||
updateNotification()
|
updateNotification()
|
||||||
|
@ -186,11 +186,14 @@ class AudioContentPlayService :
|
||||||
|
|
||||||
MusicAction.PROGRESS.name -> {
|
MusicAction.PROGRESS.name -> {
|
||||||
val progress = intent.getIntExtra(Constants.EXTRA_AUDIO_CONTENT_PROGRESS, 0)
|
val progress = intent.getIntExtra(Constants.EXTRA_AUDIO_CONTENT_PROGRESS, 0)
|
||||||
if (progress > 0) {
|
if (progress > 0 && this::mediaPlayer.isInitialized) {
|
||||||
if (contentId != null) saveNewPlaybackTracking(
|
if (contentId != null) {
|
||||||
|
saveNewPlaybackTracking(
|
||||||
totalDuration = mediaPlayer.duration,
|
totalDuration = mediaPlayer.duration,
|
||||||
progress = progress
|
progress = progress
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
mediaPlayer.seekTo(progress)
|
mediaPlayer.seekTo(progress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -258,7 +261,7 @@ class AudioContentPlayService :
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
if (isPlaying) {
|
if (isPlaying && this::mediaPlayer.isInitialized) {
|
||||||
mediaPlayer.stop()
|
mediaPlayer.stop()
|
||||||
setEndPositionPlaybackTracking(mediaPlayer.currentPosition)
|
setEndPositionPlaybackTracking(mediaPlayer.currentPosition)
|
||||||
|
|
||||||
|
@ -290,12 +293,12 @@ class AudioContentPlayService :
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCompletion(mp: MediaPlayer?) {
|
override fun onCompletion(mp: MediaPlayer) {
|
||||||
setEndPositionPlaybackTracking(mediaPlayer.currentPosition)
|
setEndPositionPlaybackTracking(mp.currentPosition)
|
||||||
|
|
||||||
if (SharedPreferenceManager.isContentPlayLoop) {
|
if (SharedPreferenceManager.isContentPlayLoop) {
|
||||||
saveNewPlaybackTracking(totalDuration = mediaPlayer.duration, progress = 0)
|
saveNewPlaybackTracking(totalDuration = mp.duration, progress = 0)
|
||||||
mediaPlayer.start()
|
mp.start()
|
||||||
} else {
|
} else {
|
||||||
toggleIsPlaying(false)
|
toggleIsPlaying(false)
|
||||||
mediaPlayer.release()
|
mediaPlayer.release()
|
||||||
|
@ -370,6 +373,7 @@ class AudioContentPlayService :
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPrepared(mp: MediaPlayer?) {
|
override fun onPrepared(mp: MediaPlayer?) {
|
||||||
|
if (this::mediaPlayer.isInitialized) {
|
||||||
saveNewPlaybackTracking(totalDuration = mediaPlayer.duration, progress = 0)
|
saveNewPlaybackTracking(totalDuration = mediaPlayer.duration, progress = 0)
|
||||||
sendBroadcast(
|
sendBroadcast(
|
||||||
Intent(Constants.ACTION_AUDIO_CONTENT_RECEIVER)
|
Intent(Constants.ACTION_AUDIO_CONTENT_RECEIVER)
|
||||||
|
@ -426,6 +430,7 @@ class AudioContentPlayService :
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun updateNotification() {
|
private fun updateNotification() {
|
||||||
val intent = Intent(this, MainActivity::class.java)
|
val intent = Intent(this, MainActivity::class.java)
|
||||||
|
|
Loading…
Reference in New Issue