clean code

This commit is contained in:
Thomas 2023-03-20 14:06:58 +01:00
parent f698b414a5
commit b6a8df9410

View file

@ -110,9 +110,8 @@ import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
import com.google.android.exoplayer2.ui.DefaultTimeBar; 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.DefaultDataSource;
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.video.VideoSize; import com.google.android.exoplayer2.video.VideoSize;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
@ -1379,12 +1378,12 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
SingleSampleMediaSource subtitleSource = null; SingleSampleMediaSource subtitleSource = null;
DataSource.Factory dataSourceFactory; DataSource.Factory dataSourceFactory;
if (video_cache == 0 || video.isLive()) { if (video_cache == 0 || video.isLive()) {
dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this, dataSourceFactory = new DefaultDataSource.Factory(PeertubeActivity.this);
Util.getUserAgent(PeertubeActivity.this, null), null);
if (subtitles != null) { if (subtitles != null) {
MediaItem.Subtitle mediaSubtitle = new MediaItem.Subtitle(subtitles, MimeTypes.TEXT_VTT, lang); MediaItem.SubtitleConfiguration subtitleConfiguration = new MediaItem.SubtitleConfiguration.Builder(subtitles)
subtitleSource = new SingleSampleMediaSource.Factory(dataSourceFactory).createMediaSource(mediaSubtitle, C.TIME_UNSET); .setMimeType(MimeTypes.TEXT_VTT)
.setLanguage(lang).build();
subtitleSource = new SingleSampleMediaSource.Factory(dataSourceFactory).createMediaSource(subtitleConfiguration, C.TIME_UNSET);
} }
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.parse(videoURL)).build(); MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.parse(videoURL)).build();
if (videoURL != null && !videoURL.endsWith("m3u8")) { if (videoURL != null && !videoURL.endsWith("m3u8")) {
@ -1397,8 +1396,11 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
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();
if (subtitles != null) { if (subtitles != null) {
MediaItem.Subtitle mediaSubtitle = new MediaItem.Subtitle(subtitles, MimeTypes.TEXT_VTT, lang, Format.NO_VALUE); MediaItem.SubtitleConfiguration subtitleConfiguration = new MediaItem.SubtitleConfiguration.Builder(subtitles)
subtitleSource = new SingleSampleMediaSource.Factory(cacheDataSourceFactory).createMediaSource(mediaSubtitle, C.TIME_UNSET); .setMimeType(MimeTypes.TEXT_VTT)
.setSelectionFlags(Format.NO_VALUE)
.setLanguage(lang).build();
subtitleSource = new SingleSampleMediaSource.Factory(cacheDataSourceFactory).createMediaSource(subtitleConfiguration, C.TIME_UNSET);
} }
if (videoURL != null && !videoURL.endsWith("m3u8")) { if (videoURL != null && !videoURL.endsWith("m3u8")) {
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory).createMediaSource(mediaItem); videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory).createMediaSource(mediaItem);
@ -1720,28 +1722,6 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
} }
/* private void toogleFullscreen(boolean fullscreen) {
if (fullscreen) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN |
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Objects.requireNonNull(getSupportActionBar()).hide();
binding.bottomVideo.setVisibility(View.GONE);
Log.v(TAG,"videoOrientationType: " + videoOrientationType);
if (videoOrientationType == videoOrientation.LANDSCAPE) {
if (getResources().getConfiguration().orientation != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
setRequestedOrientationCustom(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
} else {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
Objects.requireNonNull(getSupportActionBar()).show();
binding.bottomVideo.setVisibility(View.VISIBLE);
Objects.requireNonNull(getSupportActionBar()).show();
}
}*/
public void openCommentThread(Comment comment) { public void openCommentThread(Comment comment) {
@ -1829,32 +1809,6 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
List<MenuItemView> items = new ArrayList<>(); List<MenuItemView> items = new ArrayList<>();
switch (action) { switch (action) {
case RESOLUTION: case RESOLUTION:
/*binding.subMenuTitle.setText(R.string.pickup_resolution);
int position = 0;
for (File file : peertube.getAllFile(PeertubeActivity.this)) {
if (file.getResolutions() == null) {
MenuItemView item = new MenuItemView();
item.setId(0);
item.setLabel(file.getResolutions().getLabel());
if (file.getResolutions().getLabel().compareTo(currentResolution) == 0) {
item.setSelected(true);
}
items.add(item);
position++;
} else if (file.getResolutions() != null) {
if (file.getResolutions().getLabel().compareTo("0p") != 0) {
MenuItemView item = new MenuItemView();
item.setId(position);
item.setLabel(file.getResolutions().getLabel());
if (file.getResolutions().getLabel().compareTo(currentResolution) == 0) {
item.setSelected(true);
}
items.add(item);
position++;
}
}
}*/
if (!isShowingTrackSelectionDialog if (!isShowingTrackSelectionDialog
&& TrackSelectionDialog.willHaveContent(player)) { && TrackSelectionDialog.willHaveContent(player)) {
isShowingTrackSelectionDialog = true; isShowingTrackSelectionDialog = true;
@ -2250,11 +2204,6 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
if (playButton != null) { if (playButton != null) {
playButton.setOnClickListener(v -> { playButton.setOnClickListener(v -> {
if (autoFullscreen && !fullScreenMode) { if (autoFullscreen && !fullScreenMode) {
/*if (getResources().getConfiguration().orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE && videoOrientationType == videoOrientation.PORTRAIT) {
setRequestedOrientationCustom(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
} else if (getResources().getConfiguration().orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT && videoOrientationType == videoOrientation.LANDSCAPE) {
setRequestedOrientationCustom(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
}*/
setFullScreen(); setFullScreen();
} }
player.setPlayWhenReady(true); player.setPlayWhenReady(true);
@ -2492,7 +2441,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
@Override @Override
public void onPlayerError(PlaybackException error) { public void onPlayerError(@NonNull PlaybackException error) {
Player.Listener.super.onPlayerError(error); Player.Listener.super.onPlayerError(error);
} }