Fixed Now playing viewpager lag
This commit is contained in:
parent
67d65a1532
commit
ad04c4e2ed
2 changed files with 13 additions and 5 deletions
|
@ -88,6 +88,7 @@ import com.bumptech.glide.request.target.Target
|
||||||
import com.bumptech.glide.request.transition.Transition
|
import com.bumptech.glide.request.transition.Transition
|
||||||
import com.google.android.gms.cast.framework.CastSession
|
import com.google.android.gms.cast.framework.CastSession
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
import kotlinx.coroutines.Dispatchers.Default
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
import kotlinx.coroutines.Dispatchers.Main
|
import kotlinx.coroutines.Dispatchers.Main
|
||||||
import org.koin.java.KoinJavaComponent.get
|
import org.koin.java.KoinJavaComponent.get
|
||||||
|
@ -792,11 +793,16 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
}
|
}
|
||||||
|
|
||||||
fun playSongAt(position: Int) {
|
fun playSongAt(position: Int) {
|
||||||
openTrackAndPrepareNextAt(position) { success ->
|
// Every chromecast method needs to run on main thread or you are greeted with IllegalStateException
|
||||||
if (success) {
|
// So it will use Main dispatcher
|
||||||
play()
|
// And by using Default dispatcher for local playback we are reduce the burden of main thread
|
||||||
} else {
|
serviceScope.launch(if(playbackManager.isLocalPlayback) Default else Main) {
|
||||||
showToast(resources.getString(R.string.unplayable_file))
|
openTrackAndPrepareNextAt(position) { success ->
|
||||||
|
if (success) {
|
||||||
|
play()
|
||||||
|
} else {
|
||||||
|
showToast(resources.getString(R.string.unplayable_file))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@ class PlaybackManager(val context: Context) {
|
||||||
var playback: Playback? = null
|
var playback: Playback? = null
|
||||||
private var playbackLocation = PlaybackLocation.LOCAL
|
private var playbackLocation = PlaybackLocation.LOCAL
|
||||||
|
|
||||||
|
val isLocalPlayback get() = playbackLocation== PlaybackLocation.LOCAL
|
||||||
|
|
||||||
val audioSessionId: Int
|
val audioSessionId: Int
|
||||||
get() = if (playback != null) {
|
get() = if (playback != null) {
|
||||||
playback!!.audioSessionId
|
playback!!.audioSessionId
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue