Add logic
This commit is contained in:
parent
7c40060438
commit
1932913793
|
@ -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)));
|
||||
|
||||
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)));
|
||||
if (uri != null)
|
||||
subtitleSource = new SingleSampleMediaSource(uri, cacheDataSourceFactory, subtitleFormat, C.TIME_UNSET);
|
||||
}
|
||||
|
||||
playerView.setPlayer(player);
|
||||
if (which > 0 && subtitleSource != null) {
|
||||
MergingMediaSource mergedSource =
|
||||
new MergingMediaSource(videoSource, subtitleSource);
|
||||
playerView.setPlayer(player);
|
||||
player.prepare(mergedSource);
|
||||
} else {
|
||||
player.prepare(videoSource);
|
||||
}
|
||||
player.seekTo(0, position);
|
||||
player.setPlayWhenReady(true);
|
||||
|
||||
|
|
Loading…
Reference in New Issue