replace runBlocking{} in setCurrentEpisode with suspend
this fixes the player frezzing for a few 100ms when loading a new episode
This commit is contained in:
parent
0a31c2fd88
commit
2004a3f483
|
@ -167,14 +167,14 @@ class PlayerViewModel(application: Application) : AndroidViewModel(application)
|
|||
*/
|
||||
fun playNextEpisode() = currentEpisode.nextEpisodeId?.let { nextEpisodeId ->
|
||||
updatePlayhead() // update playhead before switching to new episode
|
||||
setCurrentEpisode(nextEpisodeId, startPlayback = true)
|
||||
viewModelScope.launch { setCurrentEpisode(nextEpisodeId, startPlayback = true) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Set currentEpisodeCr to the episode of the given ID
|
||||
* @param episodeId The ID of the episode you want to set currentEpisodeCr to
|
||||
*/
|
||||
fun setCurrentEpisode(episodeId: String, startPlayback: Boolean = false) {
|
||||
suspend fun setCurrentEpisode(episodeId: String, startPlayback: Boolean = false) {
|
||||
currentEpisode = episodes.items.find { episode ->
|
||||
episode.id == episodeId
|
||||
} ?: NoneEpisode
|
||||
|
@ -193,7 +193,6 @@ class PlayerViewModel(application: Application) : AndroidViewModel(application)
|
|||
currentEpisodeChangedListener.forEach { it() }
|
||||
|
||||
// needs to be blocking, currentPlayback must be present when calling playCurrentMedia()
|
||||
runBlocking {
|
||||
joinAll(
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
currentPlayback = Crunchyroll.playback(currentEpisode.playback)
|
||||
|
@ -212,7 +211,6 @@ class PlayerViewModel(application: Application) : AndroidViewModel(application)
|
|||
currentIntroMetadata = Crunchyroll.datalabIntro(currentEpisode.id)
|
||||
}
|
||||
)
|
||||
}
|
||||
Log.d(classTag, "playback: ${currentEpisode.playback}")
|
||||
|
||||
if (startPlayback) {
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.PlayerEpisodesListBinding
|
||||
import org.mosad.teapod.ui.activity.player.PlayerViewModel
|
||||
|
@ -46,7 +47,10 @@ class EpisodeListDialogFragment : DialogFragment() {
|
|||
model.currentPlayheads.toMap(),
|
||||
EpisodeItemAdapter.OnClickListener { episode ->
|
||||
dismiss()
|
||||
// TODO make this none blocking, if necessary?
|
||||
runBlocking {
|
||||
model.setCurrentEpisode(episode.id, startPlayback = true)
|
||||
}
|
||||
},
|
||||
EpisodeItemAdapter.ViewType.PLAYER
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue