Skip to content

Commit

Permalink
fix: mistake about change stream not work by shortcut.
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyroid committed Dec 30, 2023
1 parent 8164499 commit b3145d0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ class PlayerManagerImpl @Inject constructor(

override fun play(url: String) {
player.update { prev ->
if (prev != null) {
stop()
}
if (prev != null) stop()
_url.update { url }
createPlayer(payload.value).also {
it.addListener(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import com.m3u.core.architecture.pref.Pref
import com.m3u.core.architecture.pref.observeAsFlow
import com.m3u.core.architecture.viewmodel.BaseViewModel
import com.m3u.core.wrapper.chain
import com.m3u.core.wrapper.chainmap
import com.m3u.core.wrapper.eventOf
import com.m3u.core.wrapper.failure
import com.m3u.core.wrapper.success
Expand Down Expand Up @@ -159,8 +158,7 @@ class PlaylistViewModel @Inject constructor(
mediaRepository
.savePicture(url)
.chain()
.chainmap { StreamCoverSaved(it.absolutePath) }
.success { onMessage(it) }
.success { onMessage(StreamCoverSaved(it.absolutePath)) }
.failure(logger::log)
.launchIn(this)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.m3u.features.stream

import android.app.PictureInPictureParams
import android.content.Intent
import android.content.res.Configuration
import android.graphics.Color
import android.graphics.Rect
Expand All @@ -17,6 +18,7 @@ import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.compose.runtime.Composable
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.lifecycleScope
import com.m3u.core.Contracts
import com.m3u.core.architecture.logger.Logger
Expand Down Expand Up @@ -68,10 +70,12 @@ class PlayerActivity : ComponentActivity() {
@Inject
lateinit var playerManager: PlayerManager

private val shortcutStreamUrlLiveData = MutableLiveData<String?>(null)
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
val shortcutStreamUrl = intent.getStringExtra(Contracts.PLAYER_SHORTCUT_STREAM_URL)
shortcutStreamUrlLiveData.value =
intent.getStringExtra(Contracts.PLAYER_SHORTCUT_STREAM_URL)
setContent {
M3ULocalProvider(
helper = helper,
Expand All @@ -82,11 +86,19 @@ class PlayerActivity : ComponentActivity() {
)
}
}
if (!shortcutStreamUrl.isNullOrEmpty()) {
helper.play(shortcutStreamUrl)
shortcutStreamUrlLiveData.observe(this) { url ->
if (!url.isNullOrEmpty()) {
helper.play(url)
}
}
}

override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
shortcutStreamUrlLiveData.value =
intent?.getStringExtra(Contracts.PLAYER_SHORTCUT_STREAM_URL)
}

private fun helper(): Helper = object : Helper {
init {
addOnPictureInPictureModeChangedListener { info ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,13 @@ class StreamViewModel @Inject constructor(
started = SharingStarted.WhileSubscribed(5_000),
initialValue = StreamState.PlayerState()
)

init {
playerManager
.url
.onEach { url ->
url?: return@onEach
val stream = streamRepository.getByUrl(url)?: return@onEach
url ?: return@onEach
val stream = streamRepository.getByUrl(url) ?: return@onEach
streamRepository.reportPlayed(stream.id)
}
.launchIn(viewModelScope)
Expand Down Expand Up @@ -149,6 +150,7 @@ class StreamViewModel @Inject constructor(

private fun disconnectDlnaDevice(device: Device<*, *, *>) {
controlPoint?.stop()
controlPoint = null
DLNACastManager.disconnectDevice(device)
}

Expand Down Expand Up @@ -194,7 +196,6 @@ class StreamViewModel @Inject constructor(
title = title,
callback = object : ServiceActionCallback<Unit> {
override fun onSuccess(result: Unit) {
logger.log("ok: url=$url, title=$title")
controlPoint?.play()
}

Expand Down

0 comments on commit b3145d0

Please sign in to comment.