diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java index 2cdd5c7..d978bff 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java @@ -694,7 +694,12 @@ public class PeertubeActivity extends AppCompatActivity { } } dialogBuilder.setSingleChoiceItems(itemsLabelLanguage, i, (dialog, which) -> { - Uri uri = Uri.parse("https://" + getLiveInstance(PeertubeActivity.this) + captions.get(which).getCaptionPath()); + + Uri uri = null; + if (which > 0) { + uri = Uri.parse("https://" + getLiveInstance(PeertubeActivity.this) + captions.get(which - 1).getCaptionPath()); + } + int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB); long position = player.getCurrentPosition(); @@ -706,29 +711,36 @@ public class PeertubeActivity extends AppCompatActivity { TrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(bandwidthMeter)); player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this, trackSelector); ProgressiveMediaSource videoSource; - MediaSource subtitleSource; + MediaSource subtitleSource = null; Format subtitleFormat = Format.createTextSampleFormat( null, - MimeTypes.APPLICATION_SUBRIP, + MimeTypes.TEXT_VTT, Format.NO_VALUE, - "en"); + itemsKeyLanguage[which]); + if (video_cache == 0) { DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this, Util.getUserAgent(PeertubeActivity.this, null), null); videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory) .createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this))); - - subtitleSource = new SingleSampleMediaSource(uri, dataSourceFactory, subtitleFormat, C.TIME_UNSET); + if (uri != null) + subtitleSource = new SingleSampleMediaSource(uri, dataSourceFactory, subtitleFormat, C.TIME_UNSET); } else { CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this); videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory) .createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this))); - subtitleSource = new SingleSampleMediaSource(uri, cacheDataSourceFactory, subtitleFormat, C.TIME_UNSET); + if (uri != null) + subtitleSource = new SingleSampleMediaSource(uri, cacheDataSourceFactory, subtitleFormat, C.TIME_UNSET); } - MergingMediaSource mergedSource = - new MergingMediaSource(videoSource, subtitleSource); + playerView.setPlayer(player); - player.prepare(mergedSource); + if (which > 0 && subtitleSource != null) { + MergingMediaSource mergedSource = + new MergingMediaSource(videoSource, subtitleSource); + player.prepare(mergedSource); + } else { + player.prepare(videoSource); + } player.seekTo(0, position); player.setPlayWhenReady(true);