pull/586/head
FongMi 2 years ago
parent 3dd80ccb3c
commit 6c02e9ddcb
  1. 28
      app/src/main/java/com/fongmi/android/tv/player/Players.java
  2. 4
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/LiveActivity.java
  3. 4
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/VideoActivity.java
  4. 9
      app/src/mobile/java/com/fongmi/android/tv/utils/PiP.java

@ -98,7 +98,7 @@ public class Players implements Player.Listener, AnalyticsListener, ParseCallbac
}
private void setPlayer(PlayerView view) {
player = new ExoPlayer.Builder(App.get()).setLoadControl(ExoUtil.buildLoadControl()).setRenderersFactory(ExoUtil.buildRenderersFactory(getDecode())).setTrackSelector(ExoUtil.buildTrackSelector()).build();
player = new ExoPlayer.Builder(App.get()).setLoadControl(ExoUtil.buildLoadControl()).setRenderersFactory(ExoUtil.buildRenderersFactory(decode)).setTrackSelector(ExoUtil.buildTrackSelector()).build();
player.setAudioAttributes(AudioAttributes.DEFAULT, true);
player.addAnalyticsListener(new EventLogger());
player.setHandleAudioBecomingNoisy(true);
@ -151,6 +151,14 @@ public class Players implements Player.Listener, AnalyticsListener, ParseCallbac
return Util.format(builder, formatter, time);
}
public int getVideoWidth() {
return player == null ? 0 : player.getVideoSize().width;
}
public int getVideoHeight() {
return player == null ? 0 : player.getVideoSize().height;
}
public float getSpeed() {
return player == null ? 1.0f : player.getPlaybackParameters().speed;
}
@ -200,7 +208,7 @@ public class Players implements Player.Listener, AnalyticsListener, ParseCallbac
}
public boolean isHard() {
return getDecode() == HARD;
return decode == HARD;
}
public boolean isPortrait() {
@ -208,7 +216,7 @@ public class Players implements Player.Listener, AnalyticsListener, ParseCallbac
}
public String getSizeText() {
return getVideoWidth() + " x " + getVideoHeight();
return getVideoWidth() == 0 && getVideoHeight() == 0 ? "" : getVideoWidth() + " x " + getVideoHeight();
}
public String getSpeedText() {
@ -216,7 +224,7 @@ public class Players implements Player.Listener, AnalyticsListener, ParseCallbac
}
public String getDecodeText() {
return ResUtil.getStringArray(R.array.select_decode)[getDecode()];
return ResUtil.getStringArray(R.array.select_decode)[decode];
}
public String setSpeed(float speed) {
@ -333,18 +341,6 @@ public class Players implements Player.Listener, AnalyticsListener, ParseCallbac
}
}
private int getDecode() {
return decode;
}
private int getVideoWidth() {
return player.getVideoSize().width;
}
private int getVideoHeight() {
return player.getVideoSize().height;
}
private void startParse(Result result, boolean useParse) {
stopParse();
parseJob = ParseJob.create(this).start(result, useParse);

@ -494,6 +494,7 @@ public class LiveActivity extends BaseActivity implements CustomKeyDownLive.List
mBinding.control.bottom.setVisibility(isLock() ? View.GONE : View.VISIBLE);
mBinding.control.top.setVisibility(isLock() ? View.GONE : View.VISIBLE);
mBinding.control.getRoot().setVisibility(View.VISIBLE);
mBinding.control.size.setText(mPlayers.getSizeText());
setR1Callback();
hideInfo();
hideEpg();
@ -760,7 +761,6 @@ public class LiveActivity extends BaseActivity implements CustomKeyDownLive.List
mPlayers.reset();
setTrackVisible(true);
checkPlayImg(mPlayers.isPlaying());
mBinding.control.size.setText(mPlayers.getSizeText());
if (isVisible(mBinding.control.getRoot())) showControl();
break;
case Player.STATE_ENDED:
@ -1043,7 +1043,7 @@ public class LiveActivity extends BaseActivity implements CustomKeyDownLive.List
super.onUserLeaveHint();
if (isRedirect()) return;
if (isLock()) App.post(this::onLock, 500);
if (mPlayers.haveTrack(C.TRACK_TYPE_VIDEO)) mPiP.enter(this, mPlayers.get().getVideoSize(), Setting.getLiveScale());
if (mPlayers.haveTrack(C.TRACK_TYPE_VIDEO)) mPiP.enter(this, mPlayers.getVideoWidth(), mPlayers.getVideoHeight(), Setting.getLiveScale());
}
@Override

@ -911,6 +911,7 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo
mBinding.control.bottom.setVisibility(isLock() ? View.GONE : View.VISIBLE);
mBinding.control.top.setVisibility(isLock() ? View.GONE : View.VISIBLE);
mBinding.control.getRoot().setVisibility(View.VISIBLE);
mBinding.control.size.setText(mPlayers.getSizeText());
checkPlayImg(mPlayers.isPlaying());
setR1Callback();
}
@ -1100,7 +1101,6 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo
setDefaultTrack();
setTrackVisible(true);
checkPlayImg(mPlayers.isPlaying());
mBinding.control.size.setText(mPlayers.getSizeText());
if (isVisible(mBinding.control.getRoot())) showControl();
break;
case Player.STATE_ENDED:
@ -1489,7 +1489,7 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo
super.onUserLeaveHint();
if (isRedirect()) return;
if (isLock()) App.post(this::onLock, 500);
if (mPlayers.haveTrack(C.TRACK_TYPE_VIDEO)) mPiP.enter(this, mPlayers.get().getVideoSize(), getScale());
if (mPlayers.haveTrack(C.TRACK_TYPE_VIDEO)) mPiP.enter(this, mPlayers.getVideoWidth(), mPlayers.getVideoHeight(), getScale());
}
@Override

@ -13,7 +13,6 @@ import android.view.View;
import androidx.annotation.DrawableRes;
import androidx.annotation.StringRes;
import androidx.media3.common.VideoSize;
import androidx.media3.ui.R;
import com.fongmi.android.tv.App;
@ -72,24 +71,24 @@ public class PiP {
}
}
public void enter(Activity activity, VideoSize size, int scale) {
public void enter(Activity activity, int width, int height, int scale) {
try {
if (noPiP() || activity.isInPictureInPictureMode() || !Setting.isBackgroundPiP()) return;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) builder.setAutoEnterEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) builder.setSeamlessResizeEnabled(true);
if (scale == 1) builder.setAspectRatio(new Rational(16, 9));
else if (scale == 2) builder.setAspectRatio(new Rational(4, 3));
else builder.setAspectRatio(getRational(size));
else builder.setAspectRatio(getRational(width, height));
activity.enterPictureInPictureMode(builder.build());
} catch (Exception e) {
e.printStackTrace();
}
}
private Rational getRational(VideoSize size) {
private Rational getRational(int width, int height) {
Rational limitWide = new Rational(239, 100);
Rational limitTall = new Rational(100, 239);
Rational rational = new Rational(size.width, size.height);
Rational rational = new Rational(width, height);
if (rational.isInfinite()) return new Rational(16, 9);
if (rational.floatValue() > limitWide.floatValue()) return limitWide;
if (rational.floatValue() < limitTall.floatValue()) return limitTall;

Loading…
Cancel
Save