aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-10-14 11:46:28 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-10-14 11:46:28 +0000
commitc8c3c23093bad7302acdfd587a1be2cd0290f851 (patch)
tree99a7c848e96036ce109244b3e5a07a1916df2780 /app/src/main
parentbc9cfc8183886398f2baa1745311a5ae4970b4e5 (diff)
downloadinfinity-for-reddit-c8c3c23093bad7302acdfd587a1be2cd0290f851.tar
infinity-for-reddit-c8c3c23093bad7302acdfd587a1be2cd0290f851.tar.gz
infinity-for-reddit-c8c3c23093bad7302acdfd587a1be2cd0290f851.tar.bz2
infinity-for-reddit-c8c3c23093bad7302acdfd587a1be2cd0290f851.tar.lz
infinity-for-reddit-c8c3c23093bad7302acdfd587a1be2cd0290f851.tar.xz
infinity-for-reddit-c8c3c23093bad7302acdfd587a1be2cd0290f851.tar.zst
infinity-for-reddit-c8c3c23093bad7302acdfd587a1be2cd0290f851.zip
Zoomable ViewVideoActivity.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java46
-rw-r--r--app/src/main/res/layout/activity_view_video.xml16
2 files changed, 52 insertions, 10 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java
index 0942dbef..5a473d29 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java
@@ -46,7 +46,7 @@ import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
-import com.google.android.exoplayer2.ui.PlayerView;
+import com.google.android.exoplayer2.ui.PlayerControlView;
import com.google.android.exoplayer2.ui.TrackSelectionDialogBuilder;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
@@ -54,8 +54,10 @@ import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
import com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory;
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
import com.google.android.exoplayer2.util.Util;
+import com.google.android.exoplayer2.video.VideoListener;
import com.google.android.material.bottomappbar.BottomAppBar;
import com.google.android.material.snackbar.Snackbar;
+import com.otaliastudios.zoom.ZoomSurfaceView;
import org.apache.commons.io.FilenameUtils;
@@ -131,8 +133,10 @@ public class ViewVideoActivity extends AppCompatActivity {
CoordinatorLayout coordinatorLayout;
@BindView(R.id.progress_bar_view_video_activity)
ProgressBar progressBar;
- @BindView(R.id.player_view_view_video_activity)
- PlayerView videoPlayerView;
+ @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)
ImageButton muteButton;
@BindView(R.id.hd_exo_playback_control_view)
@@ -325,7 +329,7 @@ public class ViewVideoActivity extends AppCompatActivity {
}
}
- videoPlayerView.setControllerVisibilityListener(visibility -> {
+ playerControlView.setVisibilityListener(visibility -> {
switch (visibility) {
case View.GONE:
getWindow().getDecorView().setSystemUiVisibility(
@@ -347,7 +351,35 @@ public class ViewVideoActivity extends AppCompatActivity {
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory();
trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
- videoPlayerView.setPlayer(player);
+
+ playerControlView.setPlayer(player);
+
+ player.addVideoListener(new VideoListener() {
+ @Override
+ public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) {
+ zoomSurfaceView.setContentSize(width, height);
+ }
+ });
+ zoomSurfaceView.addCallback(new ZoomSurfaceView.Callback() {
+ @Override
+ public void onZoomSurfaceCreated(@NonNull ZoomSurfaceView zoomSurfaceView) {
+ player.setVideoSurface(zoomSurfaceView.getSurface());
+ }
+
+ @Override
+ public void onZoomSurfaceDestroyed(@NonNull ZoomSurfaceView zoomSurfaceView) {
+
+ }
+ });
+
+ zoomSurfaceView.setOnClickListener(view -> {
+ if (playerControlView.isVisible()) {
+ playerControlView.hide();
+ } else {
+ playerControlView.show();
+ }
+ });
+
if (savedInstanceState == null) {
mVideoUri = intent.getData();
videoType = getIntent().getIntExtra(EXTRA_VIDEO_TYPE, VIDEO_TYPE_NORMAL);
@@ -507,8 +539,8 @@ public class ViewVideoActivity extends AppCompatActivity {
dataSourceFactory = new CacheDataSourceFactory(mSimpleCache,
new DefaultDataSourceFactory(ViewVideoActivity.this,
Util.getUserAgent(ViewVideoActivity.this, "Infinity")));
- player.prepare(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri));
preparePlayer(savedInstanceState);
+ player.prepare(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri));
}
@Override
@@ -586,8 +618,8 @@ public class ViewVideoActivity extends AppCompatActivity {
Util.getUserAgent(ViewVideoActivity.this,
"Infinity")));
// Prepare the player with the source.
- player.prepare(new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri));
preparePlayer(savedInstanceState);
+ player.prepare(new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri));
} else {
Toast.makeText(ViewVideoActivity.this, R.string.error_fetching_v_redd_it_video_cannot_get_video_url, Toast.LENGTH_LONG).show();
}
diff --git a/app/src/main/res/layout/activity_view_video.xml b/app/src/main/res/layout/activity_view_video.xml
index 85117f3f..bc828a7c 100644
--- a/app/src/main/res/layout/activity_view_video.xml
+++ b/app/src/main/res/layout/activity_view_video.xml
@@ -20,11 +20,21 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
- <com.google.android.exoplayer2.ui.PlayerView
- android:id="@+id/player_view_view_video_activity"
+ <com.otaliastudios.zoom.ZoomSurfaceView
+ android:id="@+id/zoom_surface_view_view_video_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
- app:controller_layout_id="@layout/exo_playback_control_view"/>
+ app:horizontalPanEnabled="true"
+ app:verticalPanEnabled="true"
+ app:zoomEnabled="true" />
+
+ <com.google.android.exoplayer2.ui.PlayerControlView
+ android:id="@+id/player_control_view_view_video_activity"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="bottom"
+ app:controller_layout_id="@layout/exo_playback_control_view"
+ app:show_timeout="1500" />
<ProgressBar
android:id="@+id/progress_bar_view_video_activity"