1
0
mirror of https://framagit.org/tom79/fedilab-tube synced 2025-04-05 06:11:06 +02:00
This commit is contained in:
Thomas 2020-12-26 17:34:30 +01:00
parent 4dbd191c4f
commit 325a239b86

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.ui.PlayerControlView;
import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; 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.MimeTypes;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoListener; import com.google.android.exoplayer2.video.VideoListener;
@ -299,7 +298,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams( LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
ConstraintLayout.LayoutParams.MATCH_PARENT, ConstraintLayout.LayoutParams.MATCH_PARENT,
0, 0,
3.0f 4.0f
); );
binding.videoContainer.setLayoutParams(param); 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) { private void stream(VideoData.Video video, String resolution, boolean autoPlay, long position, Uri subtitles, String lang) {
String videoURL = video.getFileUrl(resolution, PeertubeActivity.this); String videoURL = video.getFileUrl(resolution, PeertubeActivity.this);
if (videoURL != null && !videoURL.endsWith("m3u8")) { SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
if (videoURL.endsWith(".torrent")) { int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB);
if (videoURL != null && videoURL.endsWith(".torrent")) {
torrentStream.startStream(videoURL); torrentStream.startStream(videoURL);
return; return;
} else { } else {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); ProgressiveMediaSource videoSource = null;
int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB); HlsMediaSource hlsMediaSource = null;
ProgressiveMediaSource videoSource;
SingleSampleMediaSource subtitleSource = null; SingleSampleMediaSource subtitleSource = null;
if (video_cache == 0) { if (video_cache == 0) {
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this, 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); MediaItem.Subtitle mediaSubtitle = new MediaItem.Subtitle(subtitles, MimeTypes.TEXT_VTT, lang);
subtitleSource = new SingleSampleMediaSource.Factory(dataSourceFactory).createMediaSource(mediaSubtitle, C.TIME_UNSET); 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); videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(mediaItem);
} else {
hlsMediaSource = new HlsMediaSource.Factory(dataSourceFactory)
.createMediaSource(mediaItem);
}
} else { } else {
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this); CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
MediaItem mediaItem = new MediaItem.Builder().setUri(videoURL).build(); 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); MediaItem.Subtitle mediaSubtitle = new MediaItem.Subtitle(subtitles, MimeTypes.TEXT_VTT, lang, Format.NO_VALUE);
subtitleSource = new SingleSampleMediaSource.Factory(cacheDataSourceFactory).createMediaSource(mediaSubtitle, C.TIME_UNSET); 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 = MergingMediaSource mergedSource =
new MergingMediaSource(videoSource, subtitleSource); new MergingMediaSource(videoSource, subtitleSource);
player.setMediaSource(mergedSource); 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); player.setMediaSource(videoSource);
}
}
} else { } 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.setMediaSource(hlsMediaSource);
} }
}
player.prepare(); player.prepare();
if (position > 0) { if (position > 0) {
player.seekTo(0, position); player.seekTo(0, position);
@ -1454,7 +1464,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams( LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
ConstraintLayout.LayoutParams.MATCH_PARENT, ConstraintLayout.LayoutParams.MATCH_PARENT,
0, 0,
3.0f 4.0f
); );
binding.videoContainer.setLayoutParams(param); binding.videoContainer.setLayoutParams(param);
} }