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) -> {
|
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);
|
int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB);
|
||||||
|
|
||||||
long position = player.getCurrentPosition();
|
long position = player.getCurrentPosition();
|
||||||
|
@ -706,29 +711,36 @@ public class PeertubeActivity extends AppCompatActivity {
|
||||||
TrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(bandwidthMeter));
|
TrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(bandwidthMeter));
|
||||||
player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this, trackSelector);
|
player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this, trackSelector);
|
||||||
ProgressiveMediaSource videoSource;
|
ProgressiveMediaSource videoSource;
|
||||||
MediaSource subtitleSource;
|
MediaSource subtitleSource = null;
|
||||||
Format subtitleFormat = Format.createTextSampleFormat(
|
Format subtitleFormat = Format.createTextSampleFormat(
|
||||||
null,
|
null,
|
||||||
MimeTypes.APPLICATION_SUBRIP,
|
MimeTypes.TEXT_VTT,
|
||||||
Format.NO_VALUE,
|
Format.NO_VALUE,
|
||||||
"en");
|
itemsKeyLanguage[which]);
|
||||||
|
|
||||||
if (video_cache == 0) {
|
if (video_cache == 0) {
|
||||||
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this,
|
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this,
|
||||||
Util.getUserAgent(PeertubeActivity.this, null), null);
|
Util.getUserAgent(PeertubeActivity.this, null), null);
|
||||||
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
|
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
|
||||||
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this)));
|
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this)));
|
||||||
|
if (uri != null)
|
||||||
subtitleSource = new SingleSampleMediaSource(uri, dataSourceFactory, subtitleFormat, C.TIME_UNSET);
|
subtitleSource = new SingleSampleMediaSource(uri, dataSourceFactory, subtitleFormat, C.TIME_UNSET);
|
||||||
} else {
|
} else {
|
||||||
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
|
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
|
||||||
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
|
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
|
||||||
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this)));
|
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, PeertubeActivity.this)));
|
||||||
|
if (uri != null)
|
||||||
subtitleSource = new SingleSampleMediaSource(uri, cacheDataSourceFactory, subtitleFormat, C.TIME_UNSET);
|
subtitleSource = new SingleSampleMediaSource(uri, cacheDataSourceFactory, subtitleFormat, C.TIME_UNSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
playerView.setPlayer(player);
|
||||||
|
if (which > 0 && subtitleSource != null) {
|
||||||
MergingMediaSource mergedSource =
|
MergingMediaSource mergedSource =
|
||||||
new MergingMediaSource(videoSource, subtitleSource);
|
new MergingMediaSource(videoSource, subtitleSource);
|
||||||
playerView.setPlayer(player);
|
|
||||||
player.prepare(mergedSource);
|
player.prepare(mergedSource);
|
||||||
|
} else {
|
||||||
|
player.prepare(videoSource);
|
||||||
|
}
|
||||||
player.seekTo(0, position);
|
player.seekTo(0, position);
|
||||||
player.setPlayWhenReady(true);
|
player.setPlayWhenReady(true);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue