크리에이터 커뮤니티 게시글 오디오 재생
- 크리에이터 커뮤니티 게시글 오디오 재생시 백그라운드에서 재생 중인 오디오 콘텐츠 일시정지
This commit is contained in:
parent
14c72e8259
commit
81faf3f7ee
|
@ -1,10 +1,12 @@
|
||||||
package kr.co.vividnext.sodalive.explorer.profile.creator_community.all.player
|
package kr.co.vividnext.sodalive.explorer.profile.creator_community.all.player
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
import android.media.AudioAttributes
|
import android.media.AudioAttributes
|
||||||
import android.media.MediaPlayer
|
import android.media.MediaPlayer
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
import kr.co.vividnext.sodalive.audio_content.AudioContentPlayService
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
data class CreatorCommunityContentItem(val contentId: Long, val url: String)
|
data class CreatorCommunityContentItem(val contentId: Long, val url: String)
|
||||||
|
@ -17,7 +19,49 @@ class CreatorCommunityMediaPlayerManager(
|
||||||
private var currentPlayingContentId: Long? = null
|
private var currentPlayingContentId: Long? = null
|
||||||
private var isPaused: Boolean = false
|
private var isPaused: Boolean = false
|
||||||
|
|
||||||
|
fun pauseContent() {
|
||||||
|
mediaPlayer?.pause()
|
||||||
|
isPaused = true
|
||||||
|
updateUI()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun resumeContent() {
|
||||||
|
pauseAudioContentService()
|
||||||
|
mediaPlayer?.start()
|
||||||
|
isPaused = false
|
||||||
|
updateUI()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stopContent() {
|
||||||
|
mediaPlayer?.let {
|
||||||
|
it.stop()
|
||||||
|
it.release()
|
||||||
|
mediaPlayer = null
|
||||||
|
}
|
||||||
|
currentPlayingContentId = null
|
||||||
|
isPaused = false
|
||||||
|
updateUI()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toggleContent(creatorCommunityContentItem: CreatorCommunityContentItem) {
|
||||||
|
if (currentPlayingContentId == creatorCommunityContentItem.contentId) {
|
||||||
|
if (mediaPlayer?.isPlaying == true) {
|
||||||
|
pauseContent()
|
||||||
|
} else {
|
||||||
|
resumeContent()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
playContent(creatorCommunityContentItem)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isPlayingContent(contentId: Long): Boolean {
|
||||||
|
return currentPlayingContentId == contentId && mediaPlayer?.isPlaying == true
|
||||||
|
}
|
||||||
|
|
||||||
private fun playContent(creatorCommunityContentItem: CreatorCommunityContentItem) {
|
private fun playContent(creatorCommunityContentItem: CreatorCommunityContentItem) {
|
||||||
|
pauseAudioContentService()
|
||||||
|
|
||||||
if (currentPlayingContentId == creatorCommunityContentItem.contentId && isPaused) {
|
if (currentPlayingContentId == creatorCommunityContentItem.contentId && isPaused) {
|
||||||
resumeContent()
|
resumeContent()
|
||||||
return
|
return
|
||||||
|
@ -56,42 +100,14 @@ class CreatorCommunityMediaPlayerManager(
|
||||||
updateUI()
|
updateUI()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pauseContent() {
|
private fun pauseAudioContentService() {
|
||||||
mediaPlayer?.pause()
|
context.startService(
|
||||||
isPaused = true
|
Intent(
|
||||||
updateUI()
|
context,
|
||||||
|
AudioContentPlayService::class.java
|
||||||
|
).apply {
|
||||||
|
action = AudioContentPlayService.MusicAction.PAUSE.name
|
||||||
}
|
}
|
||||||
|
)
|
||||||
private fun resumeContent() {
|
|
||||||
mediaPlayer?.start()
|
|
||||||
isPaused = false
|
|
||||||
updateUI()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun stopContent() {
|
|
||||||
mediaPlayer?.let {
|
|
||||||
it.stop()
|
|
||||||
it.release()
|
|
||||||
mediaPlayer = null
|
|
||||||
}
|
|
||||||
currentPlayingContentId = null
|
|
||||||
isPaused = false
|
|
||||||
updateUI()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun toggleContent(creatorCommunityContentItem: CreatorCommunityContentItem) {
|
|
||||||
if (currentPlayingContentId == creatorCommunityContentItem.contentId) {
|
|
||||||
if (mediaPlayer?.isPlaying == true) {
|
|
||||||
pauseContent()
|
|
||||||
} else {
|
|
||||||
resumeContent()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
playContent(creatorCommunityContentItem)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun isPlayingContent(contentId: Long): Boolean {
|
|
||||||
return currentPlayingContentId == contentId && mediaPlayer?.isPlaying == true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue