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