fix: downloaded subtitles don't show (#5004)

This commit is contained in:
Jānis 2023-10-19 16:06:49 +03:00 committed by GitHub
parent b17719feaa
commit 39d52ff4c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -167,7 +167,7 @@ class DownloadService : LifecycleService() {
val url = URL(item.url ?: return)
// only fetch the content length if it's not been returned by the API
if (item.downloadSize == 0L) {
if (item.downloadSize <= 0L) {
url.getContentLength()?.let { size ->
item.downloadSize = size
Database.downloadDao().updateDownloadItem(item)

View File

@ -18,6 +18,7 @@ import androidx.media3.datasource.FileDataSource
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.exoplayer.source.MergingMediaSource
import androidx.media3.exoplayer.source.ProgressiveMediaSource
import androidx.media3.exoplayer.source.SingleSampleMediaSource
import androidx.media3.exoplayer.trackselection.DefaultTrackSelector
import androidx.media3.ui.PlayerView
import com.github.libretube.compat.PictureInPictureCompat
@ -36,10 +37,11 @@ import com.github.libretube.ui.interfaces.TimeFrameReceiver
import com.github.libretube.ui.listeners.SeekbarPreviewListener
import com.github.libretube.ui.models.PlayerViewModel
import com.github.libretube.util.OfflineTimeFrameReceiver
import kotlin.io.path.exists
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlin.io.path.exists
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
class OfflinePlayerActivity : BaseActivity() {
@ -156,7 +158,8 @@ class OfflinePlayerActivity : BaseActivity() {
private fun setMediaSource(videoUri: Uri?, audioUri: Uri?, subtitleUri: Uri?) {
val subtitle = subtitleUri?.let {
SubtitleConfiguration.Builder(it)
.setMimeType(MimeTypes.APPLICATION_SUBRIP)
.setMimeType(MimeTypes.APPLICATION_TTML)
.setLanguage("en")
.build()
}
@ -175,7 +178,13 @@ class OfflinePlayerActivity : BaseActivity() {
val audioSource = ProgressiveMediaSource.Factory(FileDataSource.Factory())
.createMediaSource(MediaItem.fromUri(audioUri))
val mediaSource = MergingMediaSource(audioSource, videoSource)
var mediaSource = MergingMediaSource(audioSource, videoSource)
if (subtitle != null) {
val subtitleSource = SingleSampleMediaSource.Factory(FileDataSource.Factory())
.createMediaSource(subtitle, C.TIME_UNSET)
mediaSource = MergingMediaSource(subtitleSource, mediaSource)
}
player.setMediaSource(mediaSource)
}