parent
01dc0cabbe
commit
dfb2c903a4
|
@ -203,6 +203,14 @@ class AudioContentPlayService :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MusicAction.SEEK_BACKWARD.name -> {
|
||||||
|
seekBackward10Seconds()
|
||||||
|
}
|
||||||
|
|
||||||
|
MusicAction.SEEK_FORWARD.name -> {
|
||||||
|
seekForward10Seconds()
|
||||||
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
val contentId = intent?.getLongExtra(Constants.EXTRA_AUDIO_CONTENT_ID, 0)
|
val contentId = intent?.getLongExtra(Constants.EXTRA_AUDIO_CONTENT_ID, 0)
|
||||||
if (contentId != null && this.contentId == contentId) {
|
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) {
|
private fun toggleIsPlaying(isPlaying: Boolean? = null) {
|
||||||
this.isPlaying = isPlaying ?: !this.isPlaying
|
this.isPlaying = isPlaying ?: !this.isPlaying
|
||||||
if (this.isPlaying) {
|
if (this.isPlaying) {
|
||||||
|
@ -578,6 +603,6 @@ class AudioContentPlayService :
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class MusicAction {
|
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.flSoldOut.visibility = View.GONE
|
||||||
binding.tvSoldOutBig.visibility = View.GONE
|
binding.tvSoldOutBig.visibility = View.GONE
|
||||||
binding.ivPlayOrPause.visibility = View.GONE
|
binding.ivPlayOrPause.visibility = View.GONE
|
||||||
|
binding.ivSeekBackward10.visibility = View.GONE
|
||||||
|
binding.ivSeekForward10.visibility = View.GONE
|
||||||
binding.tvPreviewNo.visibility = View.GONE
|
binding.tvPreviewNo.visibility = View.GONE
|
||||||
binding.tvTotalDuration.text = " / ${response.duration}"
|
binding.tvTotalDuration.text = " / ${response.duration}"
|
||||||
|
|
||||||
|
@ -741,12 +743,18 @@ class AudioContentDetailActivity : BaseActivity<ActivityAudioContentDetailBindin
|
||||||
binding.ivPlayOrPause.visibility = View.VISIBLE
|
binding.ivPlayOrPause.visibility = View.VISIBLE
|
||||||
binding.ivPlayOrPause.setOnClickListener {
|
binding.ivPlayOrPause.setOnClickListener {
|
||||||
startService(
|
startService(
|
||||||
Intent(applicationContext, AudioContentPlayerService::class.java).apply {
|
Intent(
|
||||||
|
applicationContext,
|
||||||
|
AudioContentPlayerService::class.java
|
||||||
|
).apply {
|
||||||
action = "STOP_SERVICE"
|
action = "STOP_SERVICE"
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
startService(
|
startService(
|
||||||
Intent(this, AudioContentPlayService::class.java).apply {
|
Intent(
|
||||||
|
applicationContext,
|
||||||
|
AudioContentPlayService::class.java
|
||||||
|
).apply {
|
||||||
putExtra(
|
putExtra(
|
||||||
Constants.EXTRA_AUDIO_CONTENT_COVER_IMAGE_URL,
|
Constants.EXTRA_AUDIO_CONTENT_COVER_IMAGE_URL,
|
||||||
response.coverImageUrl
|
response.coverImageUrl
|
||||||
|
@ -775,6 +783,33 @@ class AudioContentDetailActivity : BaseActivity<ActivityAudioContentDetailBindin
|
||||||
R.drawable.btn_audio_content_preview_play
|
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) {
|
} else if (response.releaseDate == null) {
|
||||||
binding.tvPreviewNo.visibility = View.VISIBLE
|
binding.tvPreviewNo.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,6 +109,17 @@
|
||||||
android:contentDescription="@null"
|
android:contentDescription="@null"
|
||||||
android:scaleType="centerCrop" />
|
android:scaleType="centerCrop" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/iv_seek_backward_10"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_marginEnd="24dp"
|
||||||
|
android:layout_toStartOf="@+id/iv_play_or_pause"
|
||||||
|
android:contentDescription="@null"
|
||||||
|
android:src="@drawable/ic_player_prev_10"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/iv_play_or_pause"
|
android:id="@+id/iv_play_or_pause"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -118,6 +129,17 @@
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
tools:src="@drawable/btn_audio_content_play" />
|
tools:src="@drawable/btn_audio_content_play" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/iv_seek_forward_10"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_marginStart="24dp"
|
||||||
|
android:layout_toEndOf="@+id/iv_play_or_pause"
|
||||||
|
android:contentDescription="@null"
|
||||||
|
android:src="@drawable/ic_player_next_10"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tv_preview_no"
|
android:id="@+id/tv_preview_no"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
Loading…
Reference in New Issue