콘텐츠 플레이어 - 재생 목록
- 현재 재생 중이지 않은 콘텐츠 터치시 터치한 콘텐츠를 재생하는 기능 추가
This commit is contained in:
parent
5d7db2d7e9
commit
9d042ff75f
|
@ -116,7 +116,16 @@ class AudioContentPlayerFragment(
|
||||||
viewModel.toggleShowPlayList()
|
viewModel.toggleShowPlayList()
|
||||||
}
|
}
|
||||||
|
|
||||||
adapter = AudioContentPlaylistDetailAdapter()
|
adapter = AudioContentPlaylistDetailAdapter { contentId ->
|
||||||
|
val extras = Bundle().apply {
|
||||||
|
putLong(
|
||||||
|
Constants.EXTRA_AUDIO_CONTENT_ID,
|
||||||
|
contentId
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val sessionCommand = SessionCommand("PLAY_SELECTED_CONTENT", Bundle.EMPTY)
|
||||||
|
mediaController!!.sendCustomCommand(sessionCommand, extras)
|
||||||
|
}
|
||||||
|
|
||||||
val recyclerView = binding.rvPlaylistContent
|
val recyclerView = binding.rvPlaylistContent
|
||||||
recyclerView.setHasFixedSize(true)
|
recyclerView.setHasFixedSize(true)
|
||||||
|
|
|
@ -128,6 +128,7 @@ class AudioContentPlayerService : MediaSessionService() {
|
||||||
.add(SessionCommand("UPDATE_PLAYLIST", Bundle.EMPTY))
|
.add(SessionCommand("UPDATE_PLAYLIST", Bundle.EMPTY))
|
||||||
.add(SessionCommand("PLAY_NEXT_CONTENT", Bundle.EMPTY))
|
.add(SessionCommand("PLAY_NEXT_CONTENT", Bundle.EMPTY))
|
||||||
.add(SessionCommand("PLAY_PREVIOUS_CONTENT", Bundle.EMPTY))
|
.add(SessionCommand("PLAY_PREVIOUS_CONTENT", Bundle.EMPTY))
|
||||||
|
.add(SessionCommand("PLAY_SELECTED_CONTENT", Bundle.EMPTY))
|
||||||
.add(SessionCommand("GET_PLAYLIST", Bundle.EMPTY))
|
.add(SessionCommand("GET_PLAYLIST", Bundle.EMPTY))
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
|
@ -169,6 +170,12 @@ class AudioContentPlayerService : MediaSessionService() {
|
||||||
Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS))
|
Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"PLAY_SELECTED_CONTENT" -> {
|
||||||
|
val selectedContentId = args.getLong(Constants.EXTRA_AUDIO_CONTENT_ID)
|
||||||
|
playSelectedContent(contentId = selectedContentId)
|
||||||
|
Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS))
|
||||||
|
}
|
||||||
|
|
||||||
"GET_PLAYLIST" -> {
|
"GET_PLAYLIST" -> {
|
||||||
val extras = Bundle().apply {
|
val extras = Bundle().apply {
|
||||||
putParcelableArrayList(
|
putParcelableArrayList(
|
||||||
|
@ -272,6 +279,18 @@ class AudioContentPlayerService : MediaSessionService() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun playSelectedContent(contentId: Long) {
|
||||||
|
val content = playlistManager?.findByContentId(contentId = contentId)
|
||||||
|
|
||||||
|
if (content != null) {
|
||||||
|
generateUrl(
|
||||||
|
content.id,
|
||||||
|
onSuccess = { urlGenerateSuccess(content, it) },
|
||||||
|
onFailure = { playPreviousContent() }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun generateUrl(contentId: Long, onSuccess: (String) -> Unit, onFailure: () -> Unit) {
|
private fun generateUrl(contentId: Long, onSuccess: (String) -> Unit, onFailure: () -> Unit) {
|
||||||
if (contentId <= 0) {
|
if (contentId <= 0) {
|
||||||
onFailure()
|
onFailure()
|
||||||
|
|
|
@ -21,6 +21,13 @@ class AudioContentPlaylistManager(private val playlist: List<AudioContentPlaylis
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun findByContentId(contentId: Long): AudioContentPlaylistContent? {
|
||||||
|
if (playlist.isNotEmpty()) {
|
||||||
|
return playlist.first { it.id == contentId }
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
fun hasNextContent(): Boolean {
|
fun hasNextContent(): Boolean {
|
||||||
return currentIndex + 1 < playlist.size
|
return currentIndex + 1 < playlist.size
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,7 +203,7 @@ class AudioContentPlaylistDetailActivity : BaseActivity<ActivityAudioContentPlay
|
||||||
|
|
||||||
override fun setupView() {
|
override fun setupView() {
|
||||||
loadingDialog = LoadingDialog(this, layoutInflater)
|
loadingDialog = LoadingDialog(this, layoutInflater)
|
||||||
adapter = AudioContentPlaylistDetailAdapter()
|
adapter = AudioContentPlaylistDetailAdapter {}
|
||||||
|
|
||||||
val recyclerView = binding.rvPlaylistDetail
|
val recyclerView = binding.rvPlaylistDetail
|
||||||
recyclerView.setHasFixedSize(true)
|
recyclerView.setHasFixedSize(true)
|
||||||
|
|
|
@ -10,8 +10,9 @@ import kr.co.vividnext.sodalive.R
|
||||||
import kr.co.vividnext.sodalive.databinding.ItemPlaylistContentBinding
|
import kr.co.vividnext.sodalive.databinding.ItemPlaylistContentBinding
|
||||||
import kr.co.vividnext.sodalive.extensions.dpToPx
|
import kr.co.vividnext.sodalive.extensions.dpToPx
|
||||||
|
|
||||||
class AudioContentPlaylistDetailAdapter :
|
class AudioContentPlaylistDetailAdapter(
|
||||||
RecyclerView.Adapter<AudioContentPlaylistDetailAdapter.ViewHolder>() {
|
private val onClickContent: (Long) -> Unit
|
||||||
|
) : RecyclerView.Adapter<AudioContentPlaylistDetailAdapter.ViewHolder>() {
|
||||||
|
|
||||||
private val items = mutableListOf<AudioContentPlaylistContent>()
|
private val items = mutableListOf<AudioContentPlaylistContent>()
|
||||||
private var currentPlayingContentId = 0L
|
private var currentPlayingContentId = 0L
|
||||||
|
@ -36,6 +37,12 @@ class AudioContentPlaylistDetailAdapter :
|
||||||
} else {
|
} else {
|
||||||
binding.root.setBackgroundResource(0)
|
binding.root.setBackgroundResource(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding.root.setOnClickListener {
|
||||||
|
if (currentPlayingContentId != item.id) {
|
||||||
|
onClickContent(item.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue