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.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,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) {
|
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);
|
||||||
torrentStream.startStream(videoURL);
|
if (videoURL != null && videoURL.endsWith(".torrent")) {
|
||||||
return;
|
torrentStream.startStream(videoURL);
|
||||||
} else {
|
return;
|
||||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
} else {
|
||||||
int video_cache = sharedpreferences.getInt(Helper.SET_VIDEO_CACHE, Helper.DEFAULT_VIDEO_CACHE_MB);
|
ProgressiveMediaSource videoSource = null;
|
||||||
ProgressiveMediaSource videoSource;
|
HlsMediaSource hlsMediaSource = null;
|
||||||
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,
|
||||||
Util.getUserAgent(PeertubeActivity.this, null), null);
|
Util.getUserAgent(PeertubeActivity.this, null), null);
|
||||||
|
|
||||||
if (subtitles != null) {
|
if (subtitles != null) {
|
||||||
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 {
|
} else {
|
||||||
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
|
hlsMediaSource = new HlsMediaSource.Factory(dataSourceFactory)
|
||||||
MediaItem mediaItem = new MediaItem.Builder().setUri(videoURL).build();
|
|
||||||
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
|
|
||||||
.createMediaSource(mediaItem);
|
.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) {
|
} else {
|
||||||
MergingMediaSource mergedSource =
|
CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(PeertubeActivity.this);
|
||||||
new MergingMediaSource(videoSource, subtitleSource);
|
MediaItem mediaItem = new MediaItem.Builder().setUri(videoURL).build();
|
||||||
player.setMediaSource(mergedSource);
|
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 {
|
} else {
|
||||||
player.setMediaSource(videoSource);
|
hlsMediaSource = new HlsMediaSource.Factory(cacheDataSourceFactory)
|
||||||
|
.createMediaSource(mediaItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
if (lang != null && subtitleSource != null && videoSource != null) {
|
||||||
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.parse(videoURL)).build();
|
MergingMediaSource mergedSource =
|
||||||
HlsMediaSource hlsMediaSource = new HlsMediaSource.Factory(new DefaultHttpDataSourceFactory(System.getProperty("http.agent")))
|
new MergingMediaSource(videoSource, subtitleSource);
|
||||||
.createMediaSource(mediaItem);
|
player.setMediaSource(mergedSource);
|
||||||
player.setMediaSource(hlsMediaSource);
|
} 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();
|
player.prepare();
|
||||||
if (position > 0) {
|
if (position > 0) {
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue