콘텐츠 플레이어

- 10초 이전/이후로 이동하는 기능 추가
This commit is contained in:
2025-02-25 21:50:41 +09:00
parent 9d042ff75f
commit cbda2b196a
7 changed files with 79 additions and 1 deletions

View File

@@ -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 {
override fun onProgressChanged(
seekBar: SeekBar?,

View File

@@ -130,6 +130,8 @@ class AudioContentPlayerService : MediaSessionService() {
.add(SessionCommand("PLAY_PREVIOUS_CONTENT", Bundle.EMPTY))
.add(SessionCommand("PLAY_SELECTED_CONTENT", Bundle.EMPTY))
.add(SessionCommand("GET_PLAYLIST", Bundle.EMPTY))
.add(SessionCommand("SEEK_FORWARD", Bundle.EMPTY))
.add(SessionCommand("SEEK_BACKWARD", Bundle.EMPTY))
.build()
return MediaSession.ConnectionResult.AcceptedResultBuilder(session)
@@ -176,6 +178,16 @@ class AudioContentPlayerService : MediaSessionService() {
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" -> {
val extras = Bundle().apply {
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(
content: AudioContentPlaylistContent,
contentUrl: String
@@ -318,4 +349,8 @@ class AudioContentPlayerService : MediaSessionService() {
)
)
}
companion object {
private const val SEEK_INTERVAL_MS = 10 * 1000
}
}