Support next render

pull/496/head
FongMi 2 years ago
parent 4db28969c4
commit 0aeb472ecc
  1. 1
      app/build.gradle
  2. 17
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/CastActivity.java
  3. 21
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/LiveActivity.java
  4. 23
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/VideoActivity.java
  5. 13
      app/src/leanback/res/layout/activity_cast.xml
  6. 13
      app/src/leanback/res/layout/activity_live.xml
  7. 13
      app/src/leanback/res/layout/activity_video.xml
  8. 5
      app/src/main/java/com/fongmi/android/tv/player/ExoUtil.java
  9. 1
      app/src/main/java/com/fongmi/android/tv/player/Players.java
  10. 21
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/LiveActivity.java
  11. 23
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/VideoActivity.java
  12. 13
      app/src/mobile/res/layout-sw600dp/activity_video.xml
  13. 13
      app/src/mobile/res/layout/activity_live.xml
  14. 13
      app/src/mobile/res/layout/activity_video.xml

@ -112,6 +112,7 @@ dependencies {
implementation 'androidx.media:media:1.7.0'
implementation 'androidx.room:room-runtime:2.6.1'
implementation 'cat.ereza:customactivityoncrash:2.4.0'
implementation ('com.github.anilbeesetti.nextlib:nextlib-media3ext:0.7.1') { exclude group: 'androidx.media3', module: 'media3-exoplayer' }
implementation 'com.github.bassaer:materialdesigncolors:1.0.0'
implementation 'com.github.bumptech.glide:glide:4.16.0'
implementation 'com.github.bumptech.glide:annotations:4.16.0'

@ -15,7 +15,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.media3.common.C;
import androidx.media3.common.Player;
import androidx.media3.ui.PlayerView;
import androidx.viewbinding.ViewBinding;
import com.android.cast.dlna.dmr.CastAction;
@ -66,10 +65,6 @@ public class CastActivity extends BaseActivity implements CustomKeyDownCast.List
private long duration;
private int scale;
private PlayerView getExo() {
return Setting.getRender() == 0 ? mBinding.surface : mBinding.texture;
}
@Override
protected ViewBinding getBinding() {
return mBinding = ActivityCastBinding.inflate(getLayoutInflater());
@ -138,20 +133,20 @@ public class CastActivity extends BaseActivity implements CustomKeyDownCast.List
}
private void setVideoView() {
mPlayers.set(getExo());
mPlayers.set(mBinding.exo);
setSubtitle(Setting.getSubtitle());
getExo().setVisibility(View.VISIBLE);
mBinding.exo.setVisibility(View.VISIBLE);
setScale(scale = Setting.getScale());
findViewById(R.id.timeBar).setNextFocusUpId(R.id.reset);
mBinding.control.speed.setText(mPlayers.getSpeedText());
mBinding.control.speed.setEnabled(mPlayers.canAdjustSpeed());
getExo().getSubtitleView().setStyle(ExoUtil.getCaptionStyle());
mBinding.exo.getSubtitleView().setStyle(ExoUtil.getCaptionStyle());
mBinding.control.reset.setText(ResUtil.getStringArray(R.array.select_reset)[0]);
}
@Override
public void setSubtitle(int size) {
getExo().getSubtitleView().setFixedTextSize(Dimension.SP, size);
mBinding.exo.getSubtitleView().setFixedTextSize(Dimension.SP, size);
}
private void setDecode() {
@ -159,7 +154,7 @@ public class CastActivity extends BaseActivity implements CustomKeyDownCast.List
}
private void setScale(int scale) {
getExo().setResizeMode(scale);
mBinding.exo.setResizeMode(scale);
mBinding.control.scale.setText(ResUtil.getStringArray(R.array.select_scale)[scale]);
}
@ -196,7 +191,7 @@ public class CastActivity extends BaseActivity implements CustomKeyDownCast.List
private void onDecode() {
mPlayers.toggleDecode();
mPlayers.set(getExo());
mPlayers.set(mBinding.exo);
setDecode();
onReset();
}

@ -17,7 +17,6 @@ import androidx.leanback.widget.OnChildViewHolderSelectedListener;
import androidx.lifecycle.ViewModelProvider;
import androidx.media3.common.C;
import androidx.media3.common.Player;
import androidx.media3.ui.PlayerView;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewbinding.ViewBinding;
@ -99,10 +98,6 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
return getIntent().getBooleanExtra("empty", true);
}
private PlayerView getExo() {
return Setting.getRender() == 0 ? mBinding.surface : mBinding.texture;
}
private Group getKeep() {
return (Group) mGroupAdapter.get(0);
}
@ -182,10 +177,10 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
}
private void setVideoView() {
mPlayers.set(getExo());
mPlayers.set(mBinding.exo);
setScale(Setting.getLiveScale());
setSubtitle(Setting.getSubtitle());
getExo().setVisibility(View.VISIBLE);
mBinding.exo.setVisibility(View.VISIBLE);
findViewById(R.id.timeBar).setNextFocusUpId(R.id.player);
mBinding.control.invert.setActivated(Setting.isInvert());
mBinding.control.across.setActivated(Setting.isAcross());
@ -193,13 +188,13 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
mBinding.control.speed.setText(mPlayers.getSpeedText());
mBinding.control.decode.setText(mPlayers.getDecodeText());
mBinding.control.speed.setEnabled(mPlayers.canAdjustSpeed());
getExo().getSubtitleView().setStyle(ExoUtil.getCaptionStyle());
mBinding.exo.getSubtitleView().setStyle(ExoUtil.getCaptionStyle());
mBinding.control.home.setVisibility(LiveConfig.isOnly() ? View.GONE : View.VISIBLE);
}
@Override
public void setSubtitle(int size) {
getExo().getSubtitleView().setFixedTextSize(Dimension.SP, size);
mBinding.exo.getSubtitleView().setFixedTextSize(Dimension.SP, size);
}
private void setDecode() {
@ -207,7 +202,7 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
}
private void setScale(int scale) {
getExo().setResizeMode(scale);
mBinding.exo.setResizeMode(scale);
mBinding.control.scale.setText(ResUtil.getStringArray(R.array.select_scale)[scale]);
}
@ -385,7 +380,7 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
private void onDecode() {
mPlayers.toggleDecode();
mPlayers.set(getExo());
mPlayers.set(mBinding.exo);
setDecode();
fetch();
}
@ -503,13 +498,13 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
ImgUtil.load(url, R.drawable.radio, new CustomTarget<>() {
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
getExo().setDefaultArtwork(resource);
mBinding.exo.setDefaultArtwork(resource);
setMetadata();
}
@Override
public void onLoadFailed(@Nullable Drawable error) {
getExo().setDefaultArtwork(error);
mBinding.exo.setDefaultArtwork(error);
setMetadata();
}

@ -28,7 +28,6 @@ import androidx.leanback.widget.OnChildViewHolderSelectedListener;
import androidx.lifecycle.ViewModelProvider;
import androidx.media3.common.C;
import androidx.media3.common.Player;
import androidx.media3.ui.PlayerView;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewbinding.ViewBinding;
@ -261,10 +260,6 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
return mHistory != null && mHistory.getScale() != -1 ? mHistory.getScale() : Setting.getScale();
}
private PlayerView getExo() {
return Setting.getRender() == 0 ? mBinding.surface : mBinding.texture;
}
private boolean isReplay() {
return Setting.getReset() == 1;
}
@ -378,18 +373,18 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
}
private void setVideoView() {
mPlayers.set(getExo());
getExo().setVisibility(View.VISIBLE);
mPlayers.set(mBinding.exo);
mBinding.exo.setVisibility(View.VISIBLE);
mBinding.control.decode.setText(mPlayers.getDecodeText());
mBinding.control.speed.setEnabled(mPlayers.canAdjustSpeed());
getExo().getSubtitleView().setFixedTextSize(Dimension.SP, 16);
getExo().getSubtitleView().setStyle(ExoUtil.getCaptionStyle());
mBinding.exo.getSubtitleView().setFixedTextSize(Dimension.SP, 16);
mBinding.exo.getSubtitleView().setStyle(ExoUtil.getCaptionStyle());
mBinding.control.reset.setText(ResUtil.getStringArray(R.array.select_reset)[Setting.getReset()]);
}
@Override
public void setSubtitle(int size) {
getExo().getSubtitleView().setFixedTextSize(Dimension.SP, size);
mBinding.exo.getSubtitleView().setFixedTextSize(Dimension.SP, size);
}
private void setDecode() {
@ -397,7 +392,7 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
}
private void setScale(int scale) {
getExo().setResizeMode(scale);
mBinding.exo.setResizeMode(scale);
mBinding.control.scale.setText(ResUtil.getStringArray(R.array.select_scale)[scale]);
}
@ -842,7 +837,7 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
private void onDecode() {
mPlayers.toggleDecode();
mPlayers.set(getExo());
mPlayers.set(mBinding.exo);
setDecode();
onRefresh();
}
@ -938,13 +933,13 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
ImgUtil.load(url, R.drawable.radio, new CustomTarget<>() {
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
getExo().setDefaultArtwork(resource);
mBinding.exo.setDefaultArtwork(resource);
setMetadata();
}
@Override
public void onLoadFailed(@Nullable Drawable error) {
getExo().setDefaultArtwork(error);
mBinding.exo.setDefaultArtwork(error);
hideProgress();
setMetadata();
}

@ -8,20 +8,11 @@
android:keepScreenOn="true">
<androidx.media3.ui.PlayerView
android:id="@+id/surface"
android:id="@+id/exo"
style="@style/Player.Vod"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:surface_type="surface_view" />
<androidx.media3.ui.PlayerView
android:id="@+id/texture"
style="@style/Player.Vod"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:surface_type="texture_view" />
app:surface_type="none" />
<include
android:id="@+id/widget"

@ -15,20 +15,11 @@
android:focusable="true">
<androidx.media3.ui.PlayerView
android:id="@+id/surface"
android:id="@+id/exo"
style="@style/Player.Live"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:surface_type="surface_view" />
<androidx.media3.ui.PlayerView
android:id="@+id/texture"
style="@style/Player.Live"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:surface_type="texture_view" />
app:surface_type="none" />
</FrameLayout>

@ -22,20 +22,11 @@
android:nextFocusDown="@id/flag">
<androidx.media3.ui.PlayerView
android:id="@+id/surface"
android:id="@+id/exo"
style="@style/Player.Vod"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:surface_type="surface_view" />
<androidx.media3.ui.PlayerView
android:id="@+id/texture"
style="@style/Player.Vod"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:surface_type="texture_view" />
app:surface_type="none" />
<include
android:id="@+id/widget"

@ -56,6 +56,8 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import io.github.anilbeesetti.nextlib.media3ext.ffdecoder.NextRenderersFactory;
public class ExoUtil {
private static HttpDataSource.Factory httpDataSourceFactory;
@ -75,7 +77,8 @@ public class ExoUtil {
}
public static RenderersFactory buildRenderersFactory() {
return new DefaultRenderersFactory(App.get()).setEnableDecoderFallback(true).setExtensionRendererMode(Players.isSoft() ? DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER : DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON);
DefaultRenderersFactory factory = Players.isSoft() ? new NextRenderersFactory(App.get()) : new DefaultRenderersFactory(App.get());
return factory.setEnableDecoderFallback(true).setExtensionRendererMode(Players.isSoft() ? DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER : DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON);
}
public static CaptionStyleCompat getCaptionStyle() {

@ -108,6 +108,7 @@ public class Players implements Player.Listener, AnalyticsListener, ParseCallbac
player.setAudioAttributes(AudioAttributes.DEFAULT, true);
player.addAnalyticsListener(new EventLogger());
player.setHandleAudioBecomingNoisy(true);
view.setRender(Setting.getRender());
player.addAnalyticsListener(this);
player.setPlayWhenReady(true);
player.addListener(this);

@ -19,7 +19,6 @@ import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.media3.common.C;
import androidx.media3.common.Player;
import androidx.media3.ui.PlayerView;
import androidx.viewbinding.ViewBinding;
import com.bumptech.glide.request.target.CustomTarget;
@ -112,10 +111,6 @@ public class LiveActivity extends BaseActivity implements CustomKeyDownLive.List
return getIntent().getBooleanExtra("empty", true);
}
private PlayerView getExo() {
return Setting.getRender() == 0 ? mBinding.surface : mBinding.texture;
}
private Group getKeep() {
return mGroupAdapter.get(0);
}
@ -205,11 +200,11 @@ public class LiveActivity extends BaseActivity implements CustomKeyDownLive.List
}
private void setVideoView() {
mPlayers.set(getExo());
mPlayers.set(mBinding.exo);
setScale(Setting.getLiveScale());
setSubtitle(Setting.getSubtitle());
getExo().setVisibility(View.VISIBLE);
getExo().getSubtitleView().setStyle(ExoUtil.getCaptionStyle());
mBinding.exo.setVisibility(View.VISIBLE);
mBinding.exo.getSubtitleView().setStyle(ExoUtil.getCaptionStyle());
mBinding.control.action.invert.setActivated(Setting.isInvert());
mBinding.control.action.across.setActivated(Setting.isAcross());
mBinding.control.action.change.setActivated(Setting.isChange());
@ -222,7 +217,7 @@ public class LiveActivity extends BaseActivity implements CustomKeyDownLive.List
@Override
public void setSubtitle(int size) {
getExo().getSubtitleView().setFixedTextSize(Dimension.SP, size);
mBinding.exo.getSubtitleView().setFixedTextSize(Dimension.SP, size);
}
private void setDecode() {
@ -230,7 +225,7 @@ public class LiveActivity extends BaseActivity implements CustomKeyDownLive.List
}
private void setScale(int scale) {
getExo().setResizeMode(scale);
mBinding.exo.setResizeMode(scale);
mBinding.control.action.scale.setText(ResUtil.getStringArray(R.array.select_scale)[scale]);
}
@ -416,7 +411,7 @@ public class LiveActivity extends BaseActivity implements CustomKeyDownLive.List
private void onDecode() {
mPlayers.toggleDecode();
mPlayers.set(getExo());
mPlayers.set(mBinding.exo);
setR1Callback();
setDecode();
fetch();
@ -544,13 +539,13 @@ public class LiveActivity extends BaseActivity implements CustomKeyDownLive.List
ImgUtil.load(url, R.drawable.radio, new CustomTarget<>() {
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
getExo().setDefaultArtwork(resource);
mBinding.exo.setDefaultArtwork(resource);
setMetadata();
}
@Override
public void onLoadFailed(@Nullable Drawable error) {
getExo().setDefaultArtwork(error);
mBinding.exo.setDefaultArtwork(error);
setMetadata();
}

@ -34,7 +34,6 @@ import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.media3.common.C;
import androidx.media3.common.Player;
import androidx.media3.ui.PlayerView;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewbinding.ViewBinding;
@ -233,10 +232,6 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo
return mHistory != null && mHistory.getScale() != -1 ? mHistory.getScale() : Setting.getScale();
}
private PlayerView getExo() {
return Setting.getRender() == 0 ? mBinding.surface : mBinding.texture;
}
private boolean isReplay() {
return Setting.getReset() == 1;
}
@ -371,10 +366,10 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo
}
private void setVideoView() {
mPlayers.set(getExo());
getExo().setVisibility(View.VISIBLE);
getExo().getSubtitleView().setFixedTextSize(Dimension.SP, 14);
getExo().getSubtitleView().setStyle(ExoUtil.getCaptionStyle());
mPlayers.set(mBinding.exo);
mBinding.exo.setVisibility(View.VISIBLE);
mBinding.exo.getSubtitleView().setFixedTextSize(Dimension.SP, 14);
mBinding.exo.getSubtitleView().setStyle(ExoUtil.getCaptionStyle());
mBinding.control.action.decode.setText(mPlayers.getDecodeText());
mBinding.control.action.speed.setEnabled(mPlayers.canAdjustSpeed());
mBinding.control.action.reset.setText(ResUtil.getStringArray(R.array.select_reset)[Setting.getReset()]);
@ -385,7 +380,7 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo
@Override
public void setSubtitle(int size) {
getExo().getSubtitleView().setFixedTextSize(Dimension.SP, size);
mBinding.exo.getSubtitleView().setFixedTextSize(Dimension.SP, size);
}
private void setDecode() {
@ -393,7 +388,7 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo
}
private void setScale(int scale) {
getExo().setResizeMode(scale);
mBinding.exo.setResizeMode(scale);
mBinding.control.action.scale.setText(ResUtil.getStringArray(R.array.select_scale)[scale]);
}
@ -766,7 +761,7 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo
private void onDecode() {
mPlayers.toggleDecode();
mPlayers.set(getExo());
mPlayers.set(mBinding.exo);
setR1Callback();
setDecode();
onRefresh();
@ -941,13 +936,13 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo
ImgUtil.load(url, R.drawable.radio, new CustomTarget<>() {
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
getExo().setDefaultArtwork(resource);
mBinding.exo.setDefaultArtwork(resource);
setMetadata();
}
@Override
public void onLoadFailed(@Nullable Drawable error) {
getExo().setDefaultArtwork(error);
mBinding.exo.setDefaultArtwork(error);
hideProgress();
setMetadata();
}

@ -22,20 +22,11 @@
android:focusable="true">
<androidx.media3.ui.PlayerView
android:id="@+id/surface"
android:id="@+id/exo"
style="@style/Player.Vod"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:surface_type="surface_view" />
<androidx.media3.ui.PlayerView
android:id="@+id/texture"
style="@style/Player.Vod"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:surface_type="texture_view" />
app:surface_type="none" />
<include
android:id="@+id/widget"

@ -15,20 +15,11 @@
android:focusable="true">
<androidx.media3.ui.PlayerView
android:id="@+id/surface"
android:id="@+id/exo"
style="@style/Player.Live"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:surface_type="surface_view" />
<androidx.media3.ui.PlayerView
android:id="@+id/texture"
style="@style/Player.Live"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:surface_type="texture_view" />
app:surface_type="none" />
</FrameLayout>

@ -15,20 +15,11 @@
android:focusable="true">
<androidx.media3.ui.PlayerView
android:id="@+id/surface"
android:id="@+id/exo"
style="@style/Player.Vod"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:surface_type="surface_view" />
<androidx.media3.ui.PlayerView
android:id="@+id/texture"
style="@style/Player.Vod"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:surface_type="texture_view" />
app:surface_type="none" />
<include
android:id="@+id/widget"

Loading…
Cancel
Save