콘텐츠 플레이어 - 재생 목록
- 현재 재생 중이지 않은 콘텐츠 터치시 터치한 콘텐츠를 재생하는 기능 추가
This commit is contained in:
		@@ -116,7 +116,16 @@ class AudioContentPlayerFragment(
 | 
			
		||||
            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
 | 
			
		||||
        recyclerView.setHasFixedSize(true)
 | 
			
		||||
 
 | 
			
		||||
@@ -128,6 +128,7 @@ class AudioContentPlayerService : MediaSessionService() {
 | 
			
		||||
                        .add(SessionCommand("UPDATE_PLAYLIST", Bundle.EMPTY))
 | 
			
		||||
                        .add(SessionCommand("PLAY_NEXT_CONTENT", Bundle.EMPTY))
 | 
			
		||||
                        .add(SessionCommand("PLAY_PREVIOUS_CONTENT", Bundle.EMPTY))
 | 
			
		||||
                        .add(SessionCommand("PLAY_SELECTED_CONTENT", Bundle.EMPTY))
 | 
			
		||||
                        .add(SessionCommand("GET_PLAYLIST", Bundle.EMPTY))
 | 
			
		||||
                        .build()
 | 
			
		||||
 | 
			
		||||
@@ -169,6 +170,12 @@ class AudioContentPlayerService : MediaSessionService() {
 | 
			
		||||
                            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" -> {
 | 
			
		||||
                            val extras = Bundle().apply {
 | 
			
		||||
                                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) {
 | 
			
		||||
        if (contentId <= 0) {
 | 
			
		||||
            onFailure()
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,13 @@ class AudioContentPlaylistManager(private val playlist: List<AudioContentPlaylis
 | 
			
		||||
        return null
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun findByContentId(contentId: Long): AudioContentPlaylistContent? {
 | 
			
		||||
        if (playlist.isNotEmpty()) {
 | 
			
		||||
            return playlist.first { it.id == contentId }
 | 
			
		||||
        }
 | 
			
		||||
        return null
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun hasNextContent(): Boolean {
 | 
			
		||||
        return currentIndex + 1 < playlist.size
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -203,7 +203,7 @@ class AudioContentPlaylistDetailActivity : BaseActivity<ActivityAudioContentPlay
 | 
			
		||||
 | 
			
		||||
    override fun setupView() {
 | 
			
		||||
        loadingDialog = LoadingDialog(this, layoutInflater)
 | 
			
		||||
        adapter = AudioContentPlaylistDetailAdapter()
 | 
			
		||||
        adapter = AudioContentPlaylistDetailAdapter {}
 | 
			
		||||
 | 
			
		||||
        val recyclerView = binding.rvPlaylistDetail
 | 
			
		||||
        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.extensions.dpToPx
 | 
			
		||||
 | 
			
		||||
class AudioContentPlaylistDetailAdapter :
 | 
			
		||||
    RecyclerView.Adapter<AudioContentPlaylistDetailAdapter.ViewHolder>() {
 | 
			
		||||
class AudioContentPlaylistDetailAdapter(
 | 
			
		||||
    private val onClickContent: (Long) -> Unit
 | 
			
		||||
) : RecyclerView.Adapter<AudioContentPlaylistDetailAdapter.ViewHolder>() {
 | 
			
		||||
 | 
			
		||||
    private val items = mutableListOf<AudioContentPlaylistContent>()
 | 
			
		||||
    private var currentPlayingContentId = 0L
 | 
			
		||||
@@ -36,6 +37,12 @@ class AudioContentPlaylistDetailAdapter :
 | 
			
		||||
            } else {
 | 
			
		||||
                binding.root.setBackgroundResource(0)
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            binding.root.setOnClickListener {
 | 
			
		||||
                if (currentPlayingContentId != item.id) {
 | 
			
		||||
                    onClickContent(item.id)
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user