clean
This commit is contained in:
parent
4dbd191c4f
commit
325a239b86
|
@ -101,7 +101,6 @@ import com.google.android.exoplayer2.ui.DefaultTimeBar;
|
|||
import com.google.android.exoplayer2.ui.PlayerControlView;
|
||||
import com.google.android.exoplayer2.upstream.DataSource;
|
||||
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
|
||||
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import com.google.android.exoplayer2.video.VideoListener;
|
||||
|
@ -299,7 +298,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
|
||||
ConstraintLayout.LayoutParams.MATCH_PARENT,
|
||||
0,
|
||||
3.0f
|
||||
4.0f
|
||||
);
|
||||
binding.videoContainer.setLayoutParams(param);
|
||||
}
|
||||
|
@ -1321,48 +1320,59 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||
|
||||
private void stream(VideoData.Video video, String resolution, boolean autoPlay, long position, Uri subtitles, String lang) {
|
||||
String videoURL = video.getFileUrl(resolution, PeertubeActivity.this);
|
||||
if (videoURL != null && !videoURL.endsWith("m3u8")) {
|
||||
if (videoURL.endsWith(".torrent")) {
|
||||
torrentStream.startStream(videoURL);
|
||||
return;
|
||||
} else {
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB);
|
||||
ProgressiveMediaSource videoSource;
|
||||
SingleSampleMediaSource subtitleSource = null;
|
||||
if (video_cache == 0) {
|
||||
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this,
|
||||
Util.getUserAgent(PeertubeActivity.this, null), null);
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB);
|
||||
if (videoURL != null && videoURL.endsWith(".torrent")) {
|
||||
torrentStream.startStream(videoURL);
|
||||
return;
|
||||
} else {
|
||||
ProgressiveMediaSource videoSource = null;
|
||||
HlsMediaSource hlsMediaSource = null;
|
||||
SingleSampleMediaSource subtitleSource = null;
|
||||
if (video_cache == 0) {
|
||||
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this,
|
||||
Util.getUserAgent(PeertubeActivity.this, null), null);
|
||||
|
||||
if (subtitles != null) {
|
||||
MediaItem.Subtitle mediaSubtitle = new MediaItem.Subtitle(subtitles, MimeTypes.TEXT_VTT, lang);
|
||||
subtitleSource = new SingleSampleMediaSource.Factory(dataSourceFactory).createMediaSource(mediaSubtitle, C.TIME_UNSET);
|
||||
}
|
||||
MediaItem mediaItem = new MediaItem.Builder().setUri(videoURL).build();
|
||||
if (subtitles != null) {
|
||||
MediaItem.Subtitle mediaSubtitle = new MediaItem.Subtitle(subtitles, MimeTypes.TEXT_VTT, lang);
|
||||
subtitleSource = new SingleSampleMediaSource.Factory(dataSourceFactory).createMediaSource(mediaSubtitle, C.TIME_UNSET);
|
||||
}
|
||||
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.parse(videoURL)).build();
|
||||
if (videoURL != null && !videoURL.endsWith("m3u8")) {
|
||||
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(mediaItem);
|
||||
} else {
|
||||
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
|
||||
MediaItem mediaItem = new MediaItem.Builder().setUri(videoURL).build();
|
||||
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
|
||||
hlsMediaSource = new HlsMediaSource.Factory(dataSourceFactory)
|
||||
.createMediaSource(mediaItem);
|
||||
if (subtitles != null) {
|
||||
MediaItem.Subtitle mediaSubtitle = new MediaItem.Subtitle(subtitles, MimeTypes.TEXT_VTT, lang, Format.NO_VALUE);
|
||||
subtitleSource = new SingleSampleMediaSource.Factory(cacheDataSourceFactory).createMediaSource(mediaSubtitle, C.TIME_UNSET);
|
||||
}
|
||||
}
|
||||
if (lang != null && subtitleSource != null) {
|
||||
MergingMediaSource mergedSource =
|
||||
new MergingMediaSource(videoSource, subtitleSource);
|
||||
player.setMediaSource(mergedSource);
|
||||
} else {
|
||||
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
|
||||
MediaItem mediaItem = new MediaItem.Builder().setUri(videoURL).build();
|
||||
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
|
||||
.createMediaSource(mediaItem);
|
||||
if (subtitles != null) {
|
||||
MediaItem.Subtitle mediaSubtitle = new MediaItem.Subtitle(subtitles, MimeTypes.TEXT_VTT, lang, Format.NO_VALUE);
|
||||
subtitleSource = new SingleSampleMediaSource.Factory(cacheDataSourceFactory).createMediaSource(mediaSubtitle, C.TIME_UNSET);
|
||||
}
|
||||
if (videoURL != null && !videoURL.endsWith("m3u8")) {
|
||||
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory).createMediaSource(mediaItem);
|
||||
} else {
|
||||
player.setMediaSource(videoSource);
|
||||
hlsMediaSource = new HlsMediaSource.Factory(cacheDataSourceFactory)
|
||||
.createMediaSource(mediaItem);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.parse(videoURL)).build();
|
||||
HlsMediaSource hlsMediaSource = new HlsMediaSource.Factory(new DefaultHttpDataSourceFactory(System.getProperty("http.agent")))
|
||||
.createMediaSource(mediaItem);
|
||||
player.setMediaSource(hlsMediaSource);
|
||||
if (lang != null && subtitleSource != null && videoSource != null) {
|
||||
MergingMediaSource mergedSource =
|
||||
new MergingMediaSource(videoSource, subtitleSource);
|
||||
player.setMediaSource(mergedSource);
|
||||
} else if (lang != null && subtitleSource != null) {
|
||||
MergingMediaSource mergedSource =
|
||||
new MergingMediaSource(hlsMediaSource, subtitleSource);
|
||||
player.setMediaSource(mergedSource);
|
||||
} else if (videoSource != null) {
|
||||
player.setMediaSource(videoSource);
|
||||
} else {
|
||||
player.setMediaSource(hlsMediaSource);
|
||||
}
|
||||
}
|
||||
player.prepare();
|
||||
if (position > 0) {
|
||||
|
@ -1454,7 +1464,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
|||
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
|
||||
ConstraintLayout.LayoutParams.MATCH_PARENT,
|
||||
0,
|
||||
3.0f
|
||||
4.0f
|
||||
);
|
||||
binding.videoContainer.setLayoutParams(param);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue