Do not render ZoomSurfaceView when pinch to to zoom video is disabled.

This commit is contained in:
Docile-Alligator 2023-05-03 23:24:29 +08:00
parent 3c1ecfdee0
commit c3cd162092

View File

@ -61,6 +61,7 @@ import com.google.android.exoplayer2.source.hls.HlsMediaSource;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelectionOverride; import com.google.android.exoplayer2.trackselection.TrackSelectionOverride;
import com.google.android.exoplayer2.ui.PlayerControlView; import com.google.android.exoplayer2.ui.PlayerControlView;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.ui.TrackSelectionDialogBuilder; import com.google.android.exoplayer2.ui.TrackSelectionDialogBuilder;
import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource; import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
@ -159,10 +160,6 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
CoordinatorLayout coordinatorLayout; CoordinatorLayout coordinatorLayout;
@BindView(R.id.progress_bar_view_video_activity) @BindView(R.id.progress_bar_view_video_activity)
ProgressBar progressBar; ProgressBar progressBar;
@BindView(R.id.zoom_surface_view_view_video_activity)
ZoomSurfaceView zoomSurfaceView;
@BindView(R.id.player_control_view_view_video_activity)
PlayerControlView playerControlView;
@BindView(R.id.mute_exo_playback_control_view) @BindView(R.id.mute_exo_playback_control_view)
ImageButton muteButton; ImageButton muteButton;
@BindView(R.id.hd_exo_playback_control_view) @BindView(R.id.hd_exo_playback_control_view)
@ -293,7 +290,12 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
getTheme().applyStyle(ContentFontFamily.valueOf(mSharedPreferences getTheme().applyStyle(ContentFontFamily.valueOf(mSharedPreferences
.getString(SharedPreferencesUtils.CONTENT_FONT_FAMILY_KEY, ContentFontFamily.Default.name())).getResId(), true); .getString(SharedPreferencesUtils.CONTENT_FONT_FAMILY_KEY, ContentFontFamily.Default.name())).getResId(), true);
setContentView(R.layout.activity_view_video); boolean zoomable = mSharedPreferences.getBoolean(SharedPreferencesUtils.PINCH_TO_ZOOM_VIDEO, false);
if (zoomable) {
setContentView(R.layout.activity_view_video_zoomable);
} else {
setContentView(R.layout.activity_view_video);
}
ButterKnife.bind(this); ButterKnife.bind(this);
setVolumeControlStream(AudioManager.STREAM_MUSIC); setVolumeControlStream(AudioManager.STREAM_MUSIC);
@ -406,25 +408,6 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
String postTitle = intent.getStringExtra(EXTRA_POST_TITLE); String postTitle = intent.getStringExtra(EXTRA_POST_TITLE);
setSmallTitle(postTitle); setSmallTitle(postTitle);
playerControlView.addVisibilityListener(visibility -> {
switch (visibility) {
case View.GONE:
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE);
break;
case View.VISIBLE:
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
});
trackSelector = new DefaultTrackSelector(this); trackSelector = new DefaultTrackSelector(this);
if (videoType == VIDEO_TYPE_NORMAL && isDataSavingMode && dataSavingModeDefaultResolution > 0) { if (videoType == VIDEO_TYPE_NORMAL && isDataSavingMode && dataSavingModeDefaultResolution > 0) {
trackSelector.setParameters( trackSelector.setParameters(
@ -433,26 +416,46 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
} }
player = new ExoPlayer.Builder(this).setTrackSelector(trackSelector).build(); player = new ExoPlayer.Builder(this).setTrackSelector(trackSelector).build();
playerControlView.setPlayer(player); if (zoomable) {
PlayerControlView playerControlView = findViewById(R.id.player_control_view_view_video_activity);
playerControlView.addVisibilityListener(visibility -> {
switch (visibility) {
case View.GONE:
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE);
break;
case View.VISIBLE:
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
});
playerControlView.setPlayer(player);
player.addListener(new Player.Listener() { ZoomSurfaceView zoomSurfaceView = findViewById(R.id.zoom_surface_view_view_video_activity);
@Override player.addListener(new Player.Listener() {
public void onVideoSizeChanged(VideoSize videoSize) { @Override
zoomSurfaceView.setContentSize(videoSize.width, videoSize.height); public void onVideoSizeChanged(VideoSize videoSize) {
} zoomSurfaceView.setContentSize(videoSize.width, videoSize.height);
}); }
zoomSurfaceView.addCallback(new ZoomSurfaceView.Callback() { });
@Override zoomSurfaceView.addCallback(new ZoomSurfaceView.Callback() {
public void onZoomSurfaceCreated(@NonNull ZoomSurfaceView zoomSurfaceView) { @Override
player.setVideoSurface(zoomSurfaceView.getSurface()); public void onZoomSurfaceCreated(@NonNull ZoomSurfaceView zoomSurfaceView) {
} player.setVideoSurface(zoomSurfaceView.getSurface());
}
@Override @Override
public void onZoomSurfaceDestroyed(@NonNull ZoomSurfaceView zoomSurfaceView) { public void onZoomSurfaceDestroyed(@NonNull ZoomSurfaceView zoomSurfaceView) {
} }
}); });
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.PINCH_TO_ZOOM_VIDEO, false)) {
zoomSurfaceView.getEngine().addListener(new ZoomEngine.Listener() { zoomSurfaceView.getEngine().addListener(new ZoomEngine.Listener() {
@Override @Override
public void onUpdate(@NonNull ZoomEngine zoomEngine, @NonNull Matrix matrix) { public void onUpdate(@NonNull ZoomEngine zoomEngine, @NonNull Matrix matrix) {
@ -470,16 +473,35 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
} }
}); });
zoomSurfaceView.setOnClickListener(view -> {
if (playerControlView.isVisible()) {
playerControlView.hide();
} else {
playerControlView.show();
}
});
} else { } else {
zoomSurfaceView.setZoomEnabled(false); PlayerView videoPlayerView = findViewById(R.id.player_view_view_video_activity);
videoPlayerView.setPlayer(player);
videoPlayerView.setControllerVisibilityListener(visibility -> {
switch (visibility) {
case View.GONE:
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE);
break;
case View.VISIBLE:
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
});
} }
zoomSurfaceView.setOnClickListener(view -> {
if (playerControlView.isVisible()) {
playerControlView.hide();
} else {
playerControlView.show();
}
});
if (savedInstanceState == null) { if (savedInstanceState == null) {
mVideoUri = intent.getData(); mVideoUri = intent.getData();