This commit is contained in:
Thomas 2020-12-26 17:34:30 +01:00
parent 4dbd191c4f
commit 325a239b86
1 changed files with 47 additions and 37 deletions

View File

@ -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,14 +1320,14 @@ 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")) {
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 {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB);
ProgressiveMediaSource videoSource;
ProgressiveMediaSource videoSource = null;
HlsMediaSource hlsMediaSource = null;
SingleSampleMediaSource subtitleSource = null;
if (video_cache == 0) {
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this,
@ -1338,8 +1337,13 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
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();
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.parse(videoURL)).build();
if (videoURL != null && !videoURL.endsWith("m3u8")) {
videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(mediaItem);
} else {
hlsMediaSource = new HlsMediaSource.Factory(dataSourceFactory)
.createMediaSource(mediaItem);
}
} else {
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
MediaItem mediaItem = new MediaItem.Builder().setUri(videoURL).build();
@ -1349,21 +1353,27 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
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 {
hlsMediaSource = new HlsMediaSource.Factory(cacheDataSourceFactory)
.createMediaSource(mediaItem);
}
if (lang != null && subtitleSource != null) {
}
if (lang != null && subtitleSource != null && videoSource != null) {
MergingMediaSource mergedSource =
new MergingMediaSource(videoSource, subtitleSource);
player.setMediaSource(mergedSource);
} else {
} else if (lang != null && subtitleSource != null) {
MergingMediaSource mergedSource =
new MergingMediaSource(hlsMediaSource, subtitleSource);
player.setMediaSource(mergedSource);
} else if (videoSource != null) {
player.setMediaSource(videoSource);
}
}
} 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);
}
}
player.prepare();
if (position > 0) {
player.seekTo(0, position);
@ -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);
}