diff options
| author | fox <fox@fakecake.org> | 2026-02-13 21:43:37 +0300 |
|---|---|---|
| committer | fox <fox@fakecake.org> | 2026-02-13 21:43:37 +0300 |
| commit | 80957742a0f3baa9c29f887ac395d06a5a1b5f6a (patch) | |
| tree | 8b583cf941cd48f32b9fc00c02197472d143409c | |
| parent | 9a7329c767dc855bebfb6dbfe339ec65951128c9 (diff) | |
| parent | 81b35beebf0984e37bd708a810fc6da011f5446d (diff) | |
| download | tt-rss-android-80957742a0f3baa9c29f887ac395d06a5a1b5f6a.tar.gz tt-rss-android-80957742a0f3baa9c29f887ac395d06a5a1b5f6a.tar.xz | |
Merge branch 'dev' into 'master' 26.02-80957742-signed
Dev See merge request git/tt-rss/tt-rss-android!62
6 files changed, 104 insertions, 207 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/java/org/fox/ttrss/HeadlinesFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java index 0b291e4a..295a6dd7 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java @@ -29,7 +29,6 @@ import android.view.Display; import android.view.LayoutInflater; import android.view.MenuInflater; import android.view.MenuItem; -import android.view.TextureView; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; @@ -48,6 +47,12 @@ import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; import androidx.core.view.ViewCompat; import androidx.lifecycle.ViewModelProvider; +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; import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.DefaultItemAnimator; import androidx.recyclerview.widget.ItemTouchHelper; @@ -118,7 +123,6 @@ public class HeadlinesFragment extends androidx.fragment.app.Fragment { private HeadlinesFragmentModel m_headlinesFragmentModel; private MediaPlayer m_mediaPlayer; - private TextureView m_activeTexture; public void initialize(Feed feed) { m_feed = feed; @@ -579,7 +583,7 @@ public class HeadlinesFragment extends androidx.fragment.app.Fragment { public ImageView textChecked; public View headlineHeader; public View flavorImageOverflow; - public TextureView flavorVideoView; + public PlayerView flavorVideoView; public MaterialButton attachmentsView; public TextView linkHost; @@ -1122,10 +1126,58 @@ public class HeadlinesFragment extends androidx.fragment.app.Fragment { } } - /* if (m_prefs.getBoolean("inline_video_player", false) && article.flavorImage != null && - "video".equalsIgnoreCase(article.flavorImage.tagName()) && article.flavorStreamUri != null) { + if (m_prefs.getBoolean("inline_video_player", false) && article.flavorImage != null && + "video".equalsIgnoreCase(article.flavorImage.tagName()) && article.flavorStreamUri != null) { - holder.flavorVideoView.setOnLongClickListener(v -> { + Log.d(TAG, "inline exoplayer init for " + article.flavorStreamUri); + + PlayerView playerView = holder.flavorVideoView; + + ExoPlayer player = new ExoPlayer.Builder(getContext()).build(); + + playerView.setPlayer(player); + playerView.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View view) { + openGalleryForType(article, holder, holder.flavorImageView); + return true; + } + }); + + player.setMediaItem(MediaItem.fromUri(article.flavorStreamUri)); + player.prepare(); + player.setPlayWhenReady(false); + player.setRepeatMode(Player.REPEAT_MODE_ONE); + + holder.flavorVideoView.setVisibility(View.VISIBLE); + + final ProgressBar bar = holder.flavorImageLoadingBar; + + bar.setIndeterminate(true); + bar.setVisibility(View.VISIBLE); + + player.addListener(new Player.Listener() { + @Override + public void onPlayerError(PlaybackException error) { + Log.d(TAG, "onPlayerError:" + error); + + m_activity.toast(error.getMessage()); + } + + @UnstableApi + @Override + public void onIsLoadingChanged(boolean isLoading) { + Log.d(TAG, "onIsLoadingChanged" + isLoading); + + bar.setVisibility(isLoading ? View.VISIBLE : View.GONE); + + holder.flavorImageView.setVisibility(View.INVISIBLE); + + playerView.hideController(); + } + }); + + /* holder.flavorVideoView.setOnLongClickListener(v -> { releaseSurface(); openGalleryForType(article, holder, holder.flavorImageView); return true; @@ -1215,11 +1267,11 @@ public class HeadlinesFragment extends androidx.fragment.app.Fragment { } ); - }); + }); */ } else { holder.flavorImageView.setOnClickListener(view -> openGalleryForType(article, holder, holder.flavorImageView)); - } */ + } } } @@ -1557,24 +1609,6 @@ public class HeadlinesFragment extends androidx.fragment.app.Fragment { } } - private void releaseSurface() { - try { - if (m_mediaPlayer != null) { - m_mediaPlayer.release(); - } - } catch (IllegalStateException e) { - e.printStackTrace(); - } - - try { - if (m_activeTexture != null) { - m_activeTexture.setVisibility(View.GONE); - } - } catch (IllegalStateException e) { - e.printStackTrace(); - } - } - public void scrollToArticle(Article article) { int position = Application.getArticles().indexOf(article); @@ -1590,8 +1624,6 @@ public class HeadlinesFragment extends androidx.fragment.app.Fragment { @Override public void onPause() { super.onPause(); - - releaseSurface(); } private void syncToSharedArticles() { 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 diff --git a/org.fox.ttrss/src/main/res/layout/headlines_row.xml b/org.fox.ttrss/src/main/res/layout/headlines_row.xml index 943e7073..562e3e97 100755 --- a/org.fox.ttrss/src/main/res/layout/headlines_row.xml +++ b/org.fox.ttrss/src/main/res/layout/headlines_row.xml @@ -129,7 +129,7 @@ tools:src="@drawable/ic_launcher_background" android:visibility="visible" /> - <TextureView + <androidx.media3.ui.PlayerView android:id="@+id/flavor_video" android:layout_width="match_parent" android:layout_height="wrap_content" diff --git a/org.fox.ttrss/src/main/res/xml/preferences.xml b/org.fox.ttrss/src/main/res/xml/preferences.xml index fe9f1477..9688a3c3 100755 --- a/org.fox.ttrss/src/main/res/xml/preferences.xml +++ b/org.fox.ttrss/src/main/res/xml/preferences.xml @@ -160,7 +160,6 @@ android:summary="@string/prefs_always_downsample_images_long" /> <SwitchPreferenceCompat - android:enabled="false" android:defaultValue="false" android:key="inline_video_player" android:summary="@string/prefs_inline_video_player" |
