Moves playback service startup to the IO Thread
This commit is contained in:
@@ -10,6 +10,9 @@ import androidx.media3.session.DefaultMediaNotificationProvider
|
|||||||
import androidx.media3.session.MediaSession
|
import androidx.media3.session.MediaSession
|
||||||
import androidx.media3.session.MediaSessionService
|
import androidx.media3.session.MediaSessionService
|
||||||
import com.vitorpamplona.amethyst.service.HttpClient
|
import com.vitorpamplona.amethyst.service.HttpClient
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@UnstableApi // Extend MediaSessionService
|
@UnstableApi // Extend MediaSessionService
|
||||||
class PlaybackService : MediaSessionService() {
|
class PlaybackService : MediaSessionService() {
|
||||||
@@ -32,25 +35,27 @@ class PlaybackService : MediaSessionService() {
|
|||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
|
||||||
managerHls = MultiPlayerPlaybackManager(newHslDataSource(), videoViewedPositionCache)
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
managerProgressive = MultiPlayerPlaybackManager(newProgressiveDataSource(), videoViewedPositionCache)
|
|
||||||
managerLocal = MultiPlayerPlaybackManager(cachedPositions = videoViewedPositionCache)
|
|
||||||
|
|
||||||
// Stop all videos and recreates all managers when the proxy changes.
|
|
||||||
HttpClient.proxyChangeListeners.add {
|
|
||||||
val toDestroyHls = managerHls
|
|
||||||
val toDestroyProgressive = managerProgressive
|
|
||||||
|
|
||||||
managerHls = MultiPlayerPlaybackManager(newHslDataSource(), videoViewedPositionCache)
|
managerHls = MultiPlayerPlaybackManager(newHslDataSource(), videoViewedPositionCache)
|
||||||
managerProgressive = MultiPlayerPlaybackManager(newProgressiveDataSource(), videoViewedPositionCache)
|
managerProgressive = MultiPlayerPlaybackManager(newProgressiveDataSource(), videoViewedPositionCache)
|
||||||
|
managerLocal = MultiPlayerPlaybackManager(cachedPositions = videoViewedPositionCache)
|
||||||
|
|
||||||
toDestroyHls?.releaseAppPlayers()
|
// Stop all videos and recreates all managers when the proxy changes.
|
||||||
toDestroyProgressive?.releaseAppPlayers()
|
HttpClient.proxyChangeListeners.add {
|
||||||
|
val toDestroyHls = managerHls
|
||||||
|
val toDestroyProgressive = managerProgressive
|
||||||
|
|
||||||
|
managerHls = MultiPlayerPlaybackManager(newHslDataSource(), videoViewedPositionCache)
|
||||||
|
managerProgressive = MultiPlayerPlaybackManager(newProgressiveDataSource(), videoViewedPositionCache)
|
||||||
|
|
||||||
|
toDestroyHls?.releaseAppPlayers()
|
||||||
|
toDestroyProgressive?.releaseAppPlayers()
|
||||||
|
}
|
||||||
|
|
||||||
|
setMediaNotificationProvider(
|
||||||
|
DefaultMediaNotificationProvider.Builder(applicationContext).build()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
setMediaNotificationProvider(
|
|
||||||
DefaultMediaNotificationProvider.Builder(applicationContext).build()
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
|||||||
Reference in New Issue
Block a user