parent
9d042ff75f
commit
cbda2b196a
|
@ -353,6 +353,26 @@ class AudioContentPlayerFragment(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding.ivSeekForward10.setOnClickListener {
|
||||||
|
mediaController?.let {
|
||||||
|
val sessionCommand = SessionCommand(
|
||||||
|
"SEEK_FORWARD",
|
||||||
|
Bundle.EMPTY
|
||||||
|
)
|
||||||
|
it.sendCustomCommand(sessionCommand, Bundle.EMPTY)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.ivSeekBackward10.setOnClickListener {
|
||||||
|
mediaController?.let {
|
||||||
|
val sessionCommand = SessionCommand(
|
||||||
|
"SEEK_BACKWARD",
|
||||||
|
Bundle.EMPTY
|
||||||
|
)
|
||||||
|
it.sendCustomCommand(sessionCommand, Bundle.EMPTY)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
binding.sbProgress.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
binding.sbProgress.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
||||||
override fun onProgressChanged(
|
override fun onProgressChanged(
|
||||||
seekBar: SeekBar?,
|
seekBar: SeekBar?,
|
||||||
|
|
|
@ -130,6 +130,8 @@ class AudioContentPlayerService : MediaSessionService() {
|
||||||
.add(SessionCommand("PLAY_PREVIOUS_CONTENT", Bundle.EMPTY))
|
.add(SessionCommand("PLAY_PREVIOUS_CONTENT", Bundle.EMPTY))
|
||||||
.add(SessionCommand("PLAY_SELECTED_CONTENT", Bundle.EMPTY))
|
.add(SessionCommand("PLAY_SELECTED_CONTENT", Bundle.EMPTY))
|
||||||
.add(SessionCommand("GET_PLAYLIST", Bundle.EMPTY))
|
.add(SessionCommand("GET_PLAYLIST", Bundle.EMPTY))
|
||||||
|
.add(SessionCommand("SEEK_FORWARD", Bundle.EMPTY))
|
||||||
|
.add(SessionCommand("SEEK_BACKWARD", Bundle.EMPTY))
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
return MediaSession.ConnectionResult.AcceptedResultBuilder(session)
|
return MediaSession.ConnectionResult.AcceptedResultBuilder(session)
|
||||||
|
@ -176,6 +178,16 @@ class AudioContentPlayerService : MediaSessionService() {
|
||||||
Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS))
|
Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"SEEK_FORWARD" -> {
|
||||||
|
playSeekForward()
|
||||||
|
Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS))
|
||||||
|
}
|
||||||
|
|
||||||
|
"SEEK_BACKWARD" -> {
|
||||||
|
playSeekBackward()
|
||||||
|
Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS))
|
||||||
|
}
|
||||||
|
|
||||||
"GET_PLAYLIST" -> {
|
"GET_PLAYLIST" -> {
|
||||||
val extras = Bundle().apply {
|
val extras = Bundle().apply {
|
||||||
putParcelableArrayList(
|
putParcelableArrayList(
|
||||||
|
@ -227,6 +239,25 @@ class AudioContentPlayerService : MediaSessionService() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun playSeekForward() {
|
||||||
|
val currentPosition = player!!.currentPosition
|
||||||
|
val duration = player!!.duration
|
||||||
|
var newPosition = currentPosition + SEEK_INTERVAL_MS
|
||||||
|
if (newPosition > duration) {
|
||||||
|
newPosition = duration
|
||||||
|
}
|
||||||
|
player!!.seekTo(newPosition)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun playSeekBackward() {
|
||||||
|
val currentPosition = player!!.currentPosition
|
||||||
|
var newPosition = currentPosition - SEEK_INTERVAL_MS
|
||||||
|
if (newPosition < 0) {
|
||||||
|
newPosition = 0
|
||||||
|
}
|
||||||
|
player!!.seekTo(newPosition)
|
||||||
|
}
|
||||||
|
|
||||||
private fun urlGenerateSuccess(
|
private fun urlGenerateSuccess(
|
||||||
content: AudioContentPlaylistContent,
|
content: AudioContentPlaylistContent,
|
||||||
contentUrl: String
|
contentUrl: String
|
||||||
|
@ -318,4 +349,8 @@ class AudioContentPlayerService : MediaSessionService() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val SEEK_INTERVAL_MS = 10 * 1000
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
Binary file not shown.
Before Width: | Height: | Size: 2.8 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
Binary file not shown.
Before Width: | Height: | Size: 2.9 KiB |
|
@ -24,9 +24,9 @@
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:fontFamily="@font/gmarket_sans_medium"
|
android:fontFamily="@font/gmarket_sans_medium"
|
||||||
android:maxLines="2"
|
android:maxLines="2"
|
||||||
|
android:padding="5dp"
|
||||||
android:textColor="@color/color_eeeeee"
|
android:textColor="@color/color_eeeeee"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
android:padding="5dp"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/iv_close"
|
app:layout_constraintTop_toBottomOf="@+id/iv_close"
|
||||||
|
@ -142,6 +142,29 @@
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="@+id/iv_play_or_pause" />
|
app:layout_constraintTop_toTopOf="@+id/iv_play_or_pause" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/iv_seek_backward_10"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:contentDescription="@null"
|
||||||
|
android:src="@drawable/ic_player_prev_10"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/iv_play_or_pause"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/iv_play_or_pause"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/iv_skip_back"
|
||||||
|
app:layout_constraintTop_toTopOf="@+id/iv_play_or_pause" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/iv_seek_forward_10"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:contentDescription="@null"
|
||||||
|
android:src="@drawable/ic_player_next_10"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/iv_play_or_pause"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/iv_skip_forward"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/iv_play_or_pause"
|
||||||
|
app:layout_constraintTop_toTopOf="@+id/iv_play_or_pause" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/iv_playlist"
|
android:id="@+id/iv_playlist"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
Loading…
Reference in New Issue