콘텐츠 플레이어
- 10초 이전/이후로 이동하는 기능 추가
This commit is contained in:
@@ -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?,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user