diff --git a/app/src/main/java/com/futo/platformplayer/casting/StateCasting.kt b/app/src/main/java/com/futo/platformplayer/casting/StateCasting.kt index 44b5167f..69477dcb 100644 --- a/app/src/main/java/com/futo/platformplayer/casting/StateCasting.kt +++ b/app/src/main/java/com/futo/platformplayer/casting/StateCasting.kt @@ -174,7 +174,7 @@ abstract class StateCasting { Logger.i(TAG, "Casting connecting to [${device.name}]"); UIDialogs.toast(it, "Connecting to device...") synchronized(_castingDialogLock) { - if (_currentDialog == null) { + if(_currentDialog == null) { _currentDialog = UIDialogs.showDialog(context, R.drawable.ic_loader_animated, true, "Connecting to [${device.name}]", "Make sure you are on the same network\n\nVPNs and guest networks can cause issues", null, -2, @@ -182,16 +182,12 @@ abstract class StateCasting { try { device.disconnect() } catch (e: Throwable) { - Logger.e( - TAG, "Failed to disconnect from device: $e" - ) + Logger.e(TAG, "Failed to disconnect from device: $e") } - }) - ) + })); } } } - CastConnectionState.DISCONNECTED -> { UIDialogs.toast(it, "Disconnected from device") synchronized(_castingDialogLock) { @@ -229,7 +225,7 @@ abstract class StateCasting { device.onTimeChanged.clear(); device.onVolumeChanged.clear(); device.onDurationChanged.clear(); - return + return; } activeDevice = device @@ -242,7 +238,7 @@ abstract class StateCasting { ) } - suspend fun castIfAvailable(contentResolver: ContentResolver, video: IPlatformVideoDetails, videoSource: IVideoSource?, audioSource: IAudioSource?, subtitleSource: ISubtitleSource?, ms: Long, speed: Double?, onLoadingEstimate: ((Int) -> Unit)?, onLoading: ((Boolean) -> Unit)?): Boolean { + suspend fun castIfAvailable(contentResolver: ContentResolver, video: IPlatformVideoDetails, videoSource: IVideoSource?, audioSource: IAudioSource?, subtitleSource: ISubtitleSource?, ms: Long = -1, speed: Double?, onLoadingEstimate: ((Int) -> Unit)? = null, onLoading: ((Boolean) -> Unit)? = null): Boolean { return withContext(Dispatchers.IO) { val ad = activeDevice ?: return@withContext false; if (ad.connectionState != CastConnectionState.CONNECTED) { @@ -298,47 +294,21 @@ abstract class StateCasting { if (videoSource is IVideoUrlSource) { val videoPath = "/video-${id}" - val videoUrl = if (proxyStreams) url + videoPath else videoSource.getVideoUrl(); + val videoUrl = if(proxyStreams) url + videoPath else videoSource.getVideoUrl(); Logger.i(TAG, "Casting as singular video"); - ad.loadVideo( - if (video.isLive) "LIVE" else "BUFFERED", - videoSource.container, - videoUrl, - resumePosition, - video.duration.toDouble(), - speed, - metadataFromVideo(video) - ); + ad.loadVideo(if (video.isLive) "LIVE" else "BUFFERED", videoSource.container, videoUrl, resumePosition, video.duration.toDouble(), speed, metadataFromVideo(video)); } else if (audioSource is IAudioUrlSource) { val audioPath = "/audio-${id}" - val audioUrl = if (proxyStreams) url + audioPath else audioSource.getAudioUrl(); + val audioUrl = if(proxyStreams) url + audioPath else audioSource.getAudioUrl(); Logger.i(TAG, "Casting as singular audio"); - ad.loadVideo( - if (video.isLive) "LIVE" else "BUFFERED", - audioSource.container, - audioUrl, - resumePosition, - video.duration.toDouble(), - speed, - metadataFromVideo(video) - ); + ad.loadVideo(if (video.isLive) "LIVE" else "BUFFERED", audioSource.container, audioUrl, resumePosition, video.duration.toDouble(), speed, metadataFromVideo(video)); } else if (videoSource is IHLSManifestSource) { if (proxyStreams || deviceProto == CastProtocolType.CHROMECAST) { Logger.i(TAG, "Casting as proxied HLS"); - castProxiedHls( - video, videoSource.url, videoSource.codec, resumePosition, speed - ); + castProxiedHls(video, videoSource.url, videoSource.codec, resumePosition, speed); } else { Logger.i(TAG, "Casting as non-proxied HLS"); - ad.loadVideo( - if (video.isLive) "LIVE" else "BUFFERED", - videoSource.container, - videoSource.url, - resumePosition, - video.duration.toDouble(), - speed, - metadataFromVideo(video) - ); + ad.loadVideo(if (video.isLive) "LIVE" else "BUFFERED", videoSource.container, videoSource.url, resumePosition, video.duration.toDouble(), speed, metadataFromVideo(video)); } } else if (audioSource is IHLSManifestAudioSource) { if (proxyStreams || deviceProto == CastProtocolType.CHROMECAST) { @@ -346,15 +316,7 @@ abstract class StateCasting { castProxiedHls(video, audioSource.url, audioSource.codec, resumePosition, speed); } else { Logger.i(TAG, "Casting as non-proxied audio HLS"); - ad.loadVideo( - if (video.isLive) "LIVE" else "BUFFERED", - audioSource.container, - audioSource.url, - resumePosition, - video.duration.toDouble(), - speed, - metadataFromVideo(video) - ); + ad.loadVideo(if (video.isLive) "LIVE" else "BUFFERED", audioSource.container, audioSource.url, resumePosition, video.duration.toDouble(), speed, metadataFromVideo(video)); } } else if (videoSource is LocalVideoSource) { Logger.i(TAG, "Casting as local video"); @@ -437,7 +399,7 @@ abstract class StateCasting { return listOf(videoUrl); } - private fun castLocalAudio(video: IPlatformVideoDetails, audioSource: LocalAudioSource, resumePosition: Double, speed: Double?): List { + private fun castLocalAudio(video: IPlatformVideoDetails, audioSource: LocalAudioSource, resumePosition: Double, speed: Double?) : List { val ad = activeDevice ?: return listOf(); val url = getLocalUrl(ad);