콘텐츠 상세
- 10초 전/후로 이동 기능 추가
This commit is contained in:
@@ -203,6 +203,14 @@ class AudioContentPlayService :
|
||||
}
|
||||
}
|
||||
|
||||
MusicAction.SEEK_BACKWARD.name -> {
|
||||
seekBackward10Seconds()
|
||||
}
|
||||
|
||||
MusicAction.SEEK_FORWARD.name -> {
|
||||
seekForward10Seconds()
|
||||
}
|
||||
|
||||
else -> {
|
||||
val contentId = intent?.getLongExtra(Constants.EXTRA_AUDIO_CONTENT_ID, 0)
|
||||
if (contentId != null && this.contentId == contentId) {
|
||||
@@ -314,6 +322,23 @@ class AudioContentPlayService :
|
||||
}
|
||||
}
|
||||
|
||||
private fun seekForward10Seconds() {
|
||||
if (this::mediaPlayer.isInitialized && mediaPlayer.isPlaying) {
|
||||
val currentPosition = mediaPlayer.currentPosition
|
||||
val duration = mediaPlayer.duration
|
||||
val newPosition = (currentPosition + 10_000).coerceAtMost(duration)
|
||||
mediaPlayer.seekTo(newPosition)
|
||||
}
|
||||
}
|
||||
|
||||
private fun seekBackward10Seconds() {
|
||||
if (this::mediaPlayer.isInitialized && mediaPlayer.isPlaying) {
|
||||
val currentPosition = mediaPlayer.currentPosition
|
||||
val newPosition = (currentPosition - 10_000).coerceAtLeast(0)
|
||||
mediaPlayer.seekTo(newPosition)
|
||||
}
|
||||
}
|
||||
|
||||
private fun toggleIsPlaying(isPlaying: Boolean? = null) {
|
||||
this.isPlaying = isPlaying ?: !this.isPlaying
|
||||
if (this.isPlaying) {
|
||||
@@ -578,6 +603,6 @@ class AudioContentPlayService :
|
||||
}
|
||||
|
||||
enum class MusicAction {
|
||||
PLAY, PAUSE, STOP, PROGRESS, INIT, CONDITIONAL_STOP
|
||||
PLAY, PAUSE, STOP, PROGRESS, INIT, CONDITIONAL_STOP, SEEK_FORWARD, SEEK_BACKWARD
|
||||
}
|
||||
}
|
||||
|
||||
@@ -719,6 +719,8 @@ class AudioContentDetailActivity : BaseActivity<ActivityAudioContentDetailBindin
|
||||
binding.flSoldOut.visibility = View.GONE
|
||||
binding.tvSoldOutBig.visibility = View.GONE
|
||||
binding.ivPlayOrPause.visibility = View.GONE
|
||||
binding.ivSeekBackward10.visibility = View.GONE
|
||||
binding.ivSeekForward10.visibility = View.GONE
|
||||
binding.tvPreviewNo.visibility = View.GONE
|
||||
binding.tvTotalDuration.text = " / ${response.duration}"
|
||||
|
||||
@@ -741,12 +743,18 @@ class AudioContentDetailActivity : BaseActivity<ActivityAudioContentDetailBindin
|
||||
binding.ivPlayOrPause.visibility = View.VISIBLE
|
||||
binding.ivPlayOrPause.setOnClickListener {
|
||||
startService(
|
||||
Intent(applicationContext, AudioContentPlayerService::class.java).apply {
|
||||
Intent(
|
||||
applicationContext,
|
||||
AudioContentPlayerService::class.java
|
||||
).apply {
|
||||
action = "STOP_SERVICE"
|
||||
}
|
||||
)
|
||||
startService(
|
||||
Intent(this, AudioContentPlayService::class.java).apply {
|
||||
Intent(
|
||||
applicationContext,
|
||||
AudioContentPlayService::class.java
|
||||
).apply {
|
||||
putExtra(
|
||||
Constants.EXTRA_AUDIO_CONTENT_COVER_IMAGE_URL,
|
||||
response.coverImageUrl
|
||||
@@ -775,6 +783,33 @@ class AudioContentDetailActivity : BaseActivity<ActivityAudioContentDetailBindin
|
||||
R.drawable.btn_audio_content_preview_play
|
||||
}
|
||||
)
|
||||
|
||||
if (!isAlertPreview) {
|
||||
binding.ivSeekForward10.visibility = View.VISIBLE
|
||||
binding.ivSeekBackward10.visibility = View.VISIBLE
|
||||
|
||||
binding.ivSeekForward10.setOnClickListener {
|
||||
startService(
|
||||
Intent(
|
||||
applicationContext,
|
||||
AudioContentPlayService::class.java
|
||||
).apply {
|
||||
action = AudioContentPlayService.MusicAction.SEEK_FORWARD.name
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
binding.ivSeekBackward10.setOnClickListener {
|
||||
startService(
|
||||
Intent(
|
||||
applicationContext,
|
||||
AudioContentPlayService::class.java
|
||||
).apply {
|
||||
action = AudioContentPlayService.MusicAction.SEEK_BACKWARD.name
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
} else if (response.releaseDate == null) {
|
||||
binding.tvPreviewNo.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user