diff options
| author | Andrew Dolgov <fox@fakecake.org> | 2026-02-13 21:20:54 +0300 |
|---|---|---|
| committer | Andrew Dolgov <fox@fakecake.org> | 2026-02-13 21:20:54 +0300 |
| commit | deee6a47af8ebbf82a008af06cdd3dabc7cc90a1 (patch) | |
| tree | 10ea81b8ddec37f0344ca936a109341c575930a8 /org.fox.ttrss | |
| parent | f6dd06b536c238f448e10ea65e8fe7a1620157ee (diff) | |
| download | tt-rss-android-deee6a47af8ebbf82a008af06cdd3dabc7cc90a1.tar.gz tt-rss-android-deee6a47af8ebbf82a008af06cdd3dabc7cc90a1.tar.xz | |
switch to exoplayer/media3 for videos
Diffstat (limited to 'org.fox.ttrss')
| -rwxr-xr-x | org.fox.ttrss/build.gradle | 3 | ||||
| -rwxr-xr-x | org.fox.ttrss/src/main/java/org/fox/ttrss/GalleryVideoFragment.java | 192 | ||||
| -rw-r--r-- | org.fox.ttrss/src/main/res/layout/fragment_gallery_entry.xml | 25 |
3 files changed, 43 insertions, 177 deletions
diff --git a/org.fox.ttrss/build.gradle b/org.fox.ttrss/build.gradle index 030b7d1c..d7917d41 100755 --- a/org.fox.ttrss/build.gradle +++ b/org.fox.ttrss/build.gradle @@ -160,6 +160,9 @@ dependencies { implementation 'androidx.preference:preference:1.2.1' implementation 'ch.acra:acra-mail:5.12.0' implementation 'ch.acra:acra-dialog:5.12.0' + implementation "androidx.media3:media3-exoplayer:1.9.2" + implementation "androidx.media3:media3-ui:1.9.2" + implementation "androidx.media3:media3-common:1.9.2" } java { toolchain { diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/GalleryVideoFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/GalleryVideoFragment.java index fc206543..bbcd1dd1 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/GalleryVideoFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/GalleryVideoFragment.java @@ -1,23 +1,22 @@ package org.fox.ttrss; -import android.content.res.Configuration; -import android.graphics.Rect; -import android.graphics.SurfaceTexture; import android.media.MediaPlayer; import android.os.Bundle; import android.util.Log; -import android.view.Display; import android.view.LayoutInflater; -import android.view.Surface; -import android.view.TextureView; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; -import android.widget.MediaController; +import android.widget.TextView; +import androidx.annotation.OptIn; import androidx.core.view.ViewCompat; - -import java.io.IOException; +import androidx.media3.common.MediaItem; +import androidx.media3.common.PlaybackException; +import androidx.media3.common.Player; +import androidx.media3.common.util.UnstableApi; +import androidx.media3.exoplayer.ExoPlayer; +import androidx.media3.ui.PlayerView; public class GalleryVideoFragment extends GalleryBaseFragment { private final String TAG = this.getClass().getSimpleName(); @@ -54,7 +53,7 @@ public class GalleryVideoFragment extends GalleryBaseFragment { // ActivityCompat.startPostponedEnterTransition(m_activity); - view.findViewById(R.id.flavor_image_progress).setVisibility(View.VISIBLE); + view.findViewById(R.id.flavor_image).setVisibility(View.GONE); initializeVideoPlayer(view); @@ -62,136 +61,39 @@ public class GalleryVideoFragment extends GalleryBaseFragment { } private void initializeVideoPlayer(final View view) { - final MediaController mediaController = new MediaController(m_activity); - final TextureView textureView = view.findViewById(R.id.flavor_video); - - registerForContextMenu(textureView); - - textureView.setOnClickListener(v -> { - try { - - if (mediaController.isShowing()) - mediaController.hide(); - else - mediaController.show(); + final PlayerView playerView = view.findViewById(R.id.video_view); - } catch (Exception e) { - e.printStackTrace(); - } - }); + ExoPlayer player = new ExoPlayer.Builder(getContext()).build(); - mediaController.setAnchorView(textureView); + playerView.setPlayer(player); - textureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() { + player.setMediaItem(MediaItem.fromUri(m_url)); + player.prepare(); + player.setPlayWhenReady(true); + player.setRepeatMode(Player.REPEAT_MODE_ONE); + player.addListener(new Player.Listener() { @Override - public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { - Surface s = new Surface(surface); - - m_mediaPlayer = new MediaPlayer(); - - mediaController.setMediaPlayer(new MediaController.MediaPlayerControl() { - @Override - public void start() { - m_mediaPlayer.start(); - } - - @Override - public void pause() { - m_mediaPlayer.pause(); - } - - @Override - public int getDuration() { - return m_mediaPlayer.getDuration(); - } - - @Override - public int getCurrentPosition() { - return m_mediaPlayer.getCurrentPosition(); - } - - @Override - public void seekTo(int pos) { - m_mediaPlayer.seekTo(pos); - } - - @Override - public boolean isPlaying() { - return m_mediaPlayer.isPlaying(); - } - - @Override - public int getBufferPercentage() { - return 0; - } - - @Override - public boolean canPause() { - return true; - } - - @Override - public boolean canSeekBackward() { - return true; - } - - @Override - public boolean canSeekForward() { - return true; - } - - @Override - public int getAudioSessionId() { - return 0; - } - }); - - m_mediaPlayer.setSurface(s); - - try { - m_mediaPlayer.setDataSource(m_url); - } catch (IOException e) { - view.findViewById(R.id.flavor_image_error).setVisibility(View.VISIBLE); - e.printStackTrace(); - } - - m_mediaPlayer.setOnPreparedListener(mp -> { - view.findViewById(R.id.flavor_image_progress).setVisibility(View.GONE); + public void onPlayerError(PlaybackException error) { + Log.d(TAG, "onPlayerError:" + error); - try { - resizeSurface(textureView); - mp.setLooping(true); - - mp.start(); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - }); - - m_mediaPlayer.prepareAsync(); - } - - @Override - public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { - - } + TextView errorView = view.findViewById(R.id.flavor_image_error); - @Override - public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { - try { - m_mediaPlayer.release(); - } catch (Exception e) { - e.printStackTrace(); + if (errorView != null) { + errorView.setText(error.getMessage()); + errorView.setVisibility(View.VISIBLE); } - return false; } + @UnstableApi @Override - public void onSurfaceTextureUpdated(SurfaceTexture surface) { + public void onIsLoadingChanged(boolean isLoading) { + Log.d(TAG, "onIsLoadingChanged" + isLoading); + + view.findViewById(R.id.flavor_image_progress).setVisibility(isLoading ? View.VISIBLE : View.GONE); + playerView.hideController(); } }); - } public void initialize(String url, String coverUrl) { @@ -199,40 +101,4 @@ public class GalleryVideoFragment extends GalleryBaseFragment { m_coverUrl = coverUrl; } - protected void resizeSurface(View surfaceView) { - // get the dimensions of the video (only valid when surfaceView is set) - float videoWidth = m_mediaPlayer.getVideoWidth(); - float videoHeight = m_mediaPlayer.getVideoHeight(); - - Rect rectangle = new Rect(); - m_activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rectangle); - - int actionBarHeight = m_activity.isPortrait() ? m_activity.getSupportActionBar().getHeight() : 0; - - Display display = m_activity.getWindowManager().getDefaultDisplay(); - float containerWidth = display.getWidth(); - float containerHeight = display.getHeight() - rectangle.top - actionBarHeight; - - // set dimensions to surfaceView's layout params (maintaining aspect ratio) - android.view.ViewGroup.LayoutParams lp = surfaceView.getLayoutParams(); - lp.width = (int) containerWidth; - lp.height = (int) ((videoHeight / videoWidth) * containerWidth); - if (lp.height > containerHeight) { - lp.width = (int) ((videoWidth / videoHeight) * containerHeight); - lp.height = (int) containerHeight; - } - surfaceView.setLayoutParams(lp); - } - - @Override - public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - - try { - resizeSurface(getView().findViewById(R.id.flavor_video)); - } catch (Exception e) { - e.printStackTrace(); - } - } - } diff --git a/org.fox.ttrss/src/main/res/layout/fragment_gallery_entry.xml b/org.fox.ttrss/src/main/res/layout/fragment_gallery_entry.xml index 3c507cba..d18f78d2 100644 --- a/org.fox.ttrss/src/main/res/layout/fragment_gallery_entry.xml +++ b/org.fox.ttrss/src/main/res/layout/fragment_gallery_entry.xml @@ -4,21 +4,10 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - <TextView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_gravity="center" - android:visibility="invisible" - android:text="@string/error_loading_image" - android:id="@+id/flavor_image_error" /> - - <TextureView - android:id="@+id/flavor_video" + <androidx.media3.ui.PlayerView + android:id="@+id/video_view" android:layout_width="match_parent" - android:layout_height="match_parent" - android:adjustViewBounds="true" - android:layout_gravity="center" - android:scaleType="fitCenter" /> + android:layout_height="match_parent"/> <ImageView android:id="@+id/flavor_image" @@ -34,4 +23,12 @@ android:layout_gravity="center" android:id="@+id/flavor_image_progress" /> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:visibility="invisible" + android:text="@string/error_loading_image" + android:id="@+id/flavor_image_error" /> + </FrameLayout> \ No newline at end of file |
