Support video size

pull/123/head
FongMi 3 years ago
parent f80ff49965
commit e491300a27
  1. 21
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/DetailActivity.java
  2. 40
      app/src/leanback/res/layout/view_widget_vod.xml
  3. 59
      app/src/main/java/com/fongmi/android/tv/player/Players.java
  4. 15
      ijkplayer/src/main/java/tv/danmaku/ijk/media/player/ui/IjkVideoView.java

@ -368,11 +368,10 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis
}
private void exitFullscreen() {
mBinding.widget.info.setVisibility(View.GONE);
mBinding.widget.center.setVisibility(View.GONE);
mBinding.video.setForeground(ResUtil.getDrawable(R.drawable.selector_video));
mBinding.video.setLayoutParams(mFrameParams);
mFullscreen = false;
hideInfo();
}
private void onDesc() {
@ -503,6 +502,17 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis
mBinding.widget.error.setVisibility(View.GONE);
}
private void showInfo() {
mBinding.widget.size.setText(mPlayers.getSizeText());
mBinding.widget.center.setVisibility(View.VISIBLE);
mBinding.widget.info.setVisibility(View.VISIBLE);
}
private void hideInfo() {
mBinding.widget.center.setVisibility(View.GONE);
mBinding.widget.info.setVisibility(View.GONE);
}
private void showControl() {
mBinding.control.getRoot().setVisibility(View.VISIBLE);
}
@ -587,7 +597,7 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis
public void run() {
mBinding.widget.action.setImageResource(R.drawable.ic_play);
mBinding.widget.center.setVisibility(View.GONE);
mBinding.widget.info.setVisibility(View.GONE);
hideInfo();
}
};
@ -652,8 +662,7 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis
private void onPause(boolean visible) {
mBinding.widget.exoDuration.setText(mPlayers.getDurationTime());
mBinding.widget.exoPosition.setText(mPlayers.getPositionTime(0));
mBinding.widget.info.setVisibility(visible ? View.VISIBLE : View.GONE);
mBinding.widget.center.setVisibility(visible ? View.VISIBLE : View.GONE);
if (visible) showInfo(); else hideInfo();
mPlayers.pause();
}
@ -664,7 +673,7 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (mFullscreen && mBinding.control.tracks.getVisibility() == View.VISIBLE && Utils.isMenuKey(event)) onTracks();
if (mFullscreen && mBinding.control.tracks.getVisibility() == View.VISIBLE && Utils.isMenuKey(event)) onToggle();
else if (mFullscreen && isGone(mBinding.control.getRoot()) && mKeyDown.hasEvent(event)) return mKeyDown.onKeyDown(event);
return super.dispatchKeyEvent(event);
}

@ -4,22 +4,19 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
<RelativeLayout
android:id="@+id/info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_info_vod"
android:orientation="horizontal"
android:padding="16dp"
android:visibility="gone"
tools:visibility="visible">
android:layout_height="wrap_content">
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_weight="1"
android:layout_toStartOf="@+id/time"
android:letterSpacing="0.02"
android:shadowColor="@color/grey_700"
android:shadowDx="2"
@ -27,22 +24,41 @@
android:shadowRadius="1"
android:singleLine="true"
android:textColor="@color/white"
android:textSize="20sp"
android:textSize="18sp"
tools:text="慶餘年第一季:第一集" />
<TextView
android:id="@+id/size"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_alignStart="@+id/title"
android:layout_marginTop="4dp"
android:layout_marginBottom="16dp"
android:shadowColor="@color/grey_700"
android:shadowDx="2"
android:shadowDy="2"
android:shadowRadius="1"
android:textColor="@color/white"
android:textSize="14sp"
tools:text="1920 x 1080" />
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:shadowColor="@color/grey_700"
android:shadowDx="2"
android:shadowDy="2"
android:shadowRadius="1"
android:textColor="@color/white"
android:textSize="20sp"
android:textSize="18sp"
tools:text="09:20:00" />
</LinearLayout>
</RelativeLayout>
<include
android:id="@+id/progress"

@ -1,5 +1,7 @@
package com.fongmi.android.tv.player;
import android.util.Size;
import androidx.annotation.NonNull;
import com.fongmi.android.tv.App;
@ -36,7 +38,6 @@ public class Players implements Player.Listener, IMediaPlayer.OnInfoListener, IM
private ExoPlayer exoPlayer;
private int errorCode;
private int retry;
private float speed;
public boolean isExo() {
return Prefers.getPlayer() == 0;
@ -47,7 +48,6 @@ public class Players implements Player.Listener, IMediaPlayer.OnInfoListener, IM
}
public Players init() {
speed = 1;
builder = new StringBuilder();
formatter = new Formatter(builder, Locale.getDefault());
setupExo();
@ -90,15 +90,45 @@ public class Players implements Player.Listener, IMediaPlayer.OnInfoListener, IM
return retry;
}
public String stringToTime(long time) {
return Util.getStringForTime(builder, formatter, time);
}
public float getSpeed() {
return speed;
return isExo() ? exoPlayer.getPlaybackParameters().speed : ijkPlayer.getSpeed();
}
public long getPosition() {
return isExo() ? exoPlayer.getCurrentPosition() : ijkPlayer.getCurrentPosition();
}
public long getDuration() {
return isExo() ? exoPlayer.getDuration() : ijkPlayer.getDuration();
}
public long getBuffered() {
return isExo() ? exoPlayer.getBufferedPosition() : ijkPlayer.getBufferedPosition();
}
public boolean isPlaying() {
return isExo() ? exoPlayer.isPlaying() : ijkPlayer.isPlaying();
}
public Size getSize() {
return isExo() ? new Size(exoPlayer.getVideoSize().width, exoPlayer.getVideoSize().height) : ijkPlayer.getSize();
}
public String getSizeText() {
Size size = getSize();
return size.getWidth() + " x " + size.getHeight();
}
public String getSpeedText() {
return String.format(Locale.getDefault(), "%.2f", speed);
return String.format(Locale.getDefault(), "%.2f", getSpeed());
}
public String addSpeed() {
float speed = getSpeed();
float addon = speed >= 2 ? 1f : 0.25f;
speed = speed == 5 ? 0.25f : speed + addon;
exoPlayer.setPlaybackSpeed(speed);
@ -107,6 +137,7 @@ public class Players implements Player.Listener, IMediaPlayer.OnInfoListener, IM
}
public String toggleSpeed() {
float speed = getSpeed();
speed = speed == 1 ? 3f : 1f;
exoPlayer.setPlaybackSpeed(speed);
ijkPlayer.setSpeed(speed);
@ -126,22 +157,6 @@ public class Players implements Player.Listener, IMediaPlayer.OnInfoListener, IM
return stringToTime(time);
}
public String stringToTime(long time) {
return Util.getStringForTime(builder, formatter, time);
}
public long getPosition() {
return isExo() ? exoPlayer.getCurrentPosition() : ijkPlayer.getCurrentPosition();
}
public long getDuration() {
return isExo() ? exoPlayer.getDuration() : ijkPlayer.getDuration();
}
public long getBuffered() {
return isExo() ? exoPlayer.getBufferedPosition() : ijkPlayer.getBufferedPosition();
}
public void seekTo(int time) {
if (time == 0) return;
if (isExo()) exoPlayer.seekTo(getPosition() + time);
@ -154,10 +169,6 @@ public class Players implements Player.Listener, IMediaPlayer.OnInfoListener, IM
else if (isIjk()) ijkPlayer.seekTo(time);
}
public boolean isPlaying() {
return isExo() ? exoPlayer.isPlaying() : ijkPlayer.isPlaying();
}
public boolean isVod() {
return getDuration() > 5 * 60 * 1000;
}

@ -8,6 +8,7 @@ import android.net.Uri;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Size;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
@ -46,6 +47,7 @@ public class IjkVideoView extends FrameLayout implements MediaController.MediaPl
public static final int RENDER_SURFACE_VIEW = 0;
public static final int RENDER_TEXTURE_VIEW = 1;
private float mCurrentSpeed = 1;
private int mCurrentAspectRatio;
private int mCurrentRender;
@ -185,6 +187,7 @@ public class IjkVideoView extends FrameLayout implements MediaController.MediaPl
try {
createPlayer();
fixUserAgent();
setSpeed(mCurrentSpeed);
setRender(mCurrentRender);
mCurrentBufferPosition = 0;
mCurrentBufferPercentage = 0;
@ -428,7 +431,17 @@ public class IjkVideoView extends FrameLayout implements MediaController.MediaPl
}
public void setSpeed(float speed) {
mIjkPlayer.setSpeed(speed);
if (mIjkPlayer != null) mIjkPlayer.setSpeed(speed);
mCurrentSpeed = speed;
}
public float getSpeed() {
if (mIjkPlayer != null) return mIjkPlayer.getSpeed();
return mCurrentSpeed;
}
public Size getSize() {
return new Size(mVideoWidth, mVideoHeight);
}
@Override

Loading…
Cancel
Save