diff --git a/app/src/main/java/com/futo/platformplayer/downloads/VideoDownload.kt b/app/src/main/java/com/futo/platformplayer/downloads/VideoDownload.kt index 9dadb54e..10661d1a 100644 --- a/app/src/main/java/com/futo/platformplayer/downloads/VideoDownload.kt +++ b/app/src/main/java/com/futo/platformplayer/downloads/VideoDownload.kt @@ -337,8 +337,10 @@ class VideoDownload { }); } + var wasSuccesful = false; try { awaitAll(*sourcesToDownload.toTypedArray()); + wasSuccesful = true; } catch(runtimeEx: RuntimeException) { if(runtimeEx.cause != null) @@ -349,6 +351,29 @@ class VideoDownload { catch(ex: Throwable) { throw ex; } + finally { + if(!wasSuccesful) { + try { + if(videoFilePath != null) { + val remainingVideo = File(videoFilePath!!); + if (remainingVideo.exists()) { + Logger.i(TAG, "Deleting remaining video file"); + remainingVideo.delete(); + } + } + if(audioFilePath != null) { + val remainingAudio = File(audioFilePath!!); + if (remainingAudio.exists()) { + Logger.i(TAG, "Deleting remaining audio file"); + remainingAudio.delete(); + } + } + } + catch(iex: Throwable) { + Logger.e(TAG, "Failed to delete files after failure:\n${iex.message}", iex); + } + } + } } private suspend fun downloadHlsSource(context: Context, name: String, client: ManagedHttpClient, hlsUrl: String, targetFile: File, onProgress: (Long, Long, Long) -> Unit): Long { diff --git a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt index 8c4199bb..c878a40c 100644 --- a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt +++ b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt @@ -1484,12 +1484,12 @@ class VideoDetailView : ConstraintLayout { private fun loadCurrentVideo(resumePositionMs: Long = 0) { _didStop = false; - val video = video ?: return; + val video = (videoLocal ?: video) ?: return; try { val videoSource = _lastVideoSource ?: _player.getPreferredVideoSource(video, Settings.instance.playback.getCurrentPreferredQualityPixelCount()); val audioSource = _lastAudioSource ?: _player.getPreferredAudioSource(video, Settings.instance.playback.getPrimaryLanguage(context)); - val subtitleSource = _lastSubtitleSource; + val subtitleSource = _lastSubtitleSource ?: (if(video is VideoLocal) video.subtitlesSources.firstOrNull() else null); Logger.i(TAG, "loadCurrentVideo(videoSource=$videoSource, audioSource=$audioSource, subtitleSource=$subtitleSource, resumePositionMs=$resumePositionMs)") if(videoSource == null && audioSource == null) { @@ -1517,6 +1517,8 @@ class VideoDetailView : ConstraintLayout { _player.setArtwork(null); _player.setSource(videoSource, audioSource, _playWhenReady, false); + if(subtitleSource != null) + _player.swapSubtitles(fragment.lifecycleScope, subtitleSource); _player.seekTo(resumePositionMs); } else @@ -1524,6 +1526,7 @@ class VideoDetailView : ConstraintLayout { _lastVideoSource = videoSource; _lastAudioSource = audioSource; + _lastSubtitleSource = subtitleSource; } catch(ex: UnsupportedCastException) { Logger.e(TAG, "Failed to load cast media", ex); diff --git a/app/src/main/java/com/futo/platformplayer/states/StateApp.kt b/app/src/main/java/com/futo/platformplayer/states/StateApp.kt index 412abd55..14c75210 100644 --- a/app/src/main/java/com/futo/platformplayer/states/StateApp.kt +++ b/app/src/main/java/com/futo/platformplayer/states/StateApp.kt @@ -387,6 +387,10 @@ class StateApp { displayMetrics = context.resources.displayMetrics; ensureConnectivityManager(context); + Logger.i(TAG, "MainApp Starting: Cleaning up unused downloads"); + StateDownloads.instance.cleanupDownloads(); + + Logger.i(TAG, "MainApp Starting: Initializing [Telemetry]"); if (!BuildConfig.DEBUG) { StateTelemetry.instance.initialize(); diff --git a/app/src/main/java/com/futo/platformplayer/states/StateDownloads.kt b/app/src/main/java/com/futo/platformplayer/states/StateDownloads.kt index 543f62c8..a8b7ff52 100644 --- a/app/src/main/java/com/futo/platformplayer/states/StateDownloads.kt +++ b/app/src/main/java/com/futo/platformplayer/states/StateDownloads.kt @@ -352,7 +352,10 @@ class StateDownloads { fun cleanupDownloads(): Pair { val expected = getDownloadedVideos(); - val validFiles = HashSet(expected.flatMap { e -> e.videoSource.map { it.filePath } + e.audioSource.map { it.filePath } }); + val validFiles = HashSet(expected.flatMap { e -> + e.videoSource.map { it.filePath } + + e.audioSource.map { it.filePath } + + e.subtitlesSources.map { it.filePath }}); var totalDeleted: Long = 0; var totalDeletedCount = 0; diff --git a/app/src/stable/assets/sources/odysee b/app/src/stable/assets/sources/odysee index 206d9968..537ec496 160000 --- a/app/src/stable/assets/sources/odysee +++ b/app/src/stable/assets/sources/odysee @@ -1 +1 @@ -Subproject commit 206d996801b9734cae13093859375c70be980a8d +Subproject commit 537ec496637aa9206909e59dda3a4e80ef0da477 diff --git a/app/src/unstable/assets/sources/odysee b/app/src/unstable/assets/sources/odysee index 206d9968..537ec496 160000 --- a/app/src/unstable/assets/sources/odysee +++ b/app/src/unstable/assets/sources/odysee @@ -1 +1 @@ -Subproject commit 206d996801b9734cae13093859375c70be980a8d +Subproject commit 537ec496637aa9206909e59dda3a4e80ef0da477