[mobile] live support speed and seek

pull/496/head
FongMi 2 years ago
parent 96811de6f9
commit 97939349ba
  1. 55
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/LiveActivity.java
  2. 2
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/VideoActivity.java
  3. 31
      app/src/mobile/java/com/fongmi/android/tv/ui/custom/CustomKeyDownLive.java
  4. 40
      app/src/mobile/res/layout/view_widget_live.xml

@ -158,7 +158,7 @@ public class LiveActivity extends BaseActivity implements CustomKeyDownLive.List
@Override
protected void initView(Bundle savedInstanceState) {
mKeyDown = CustomKeyDownLive.create(this, mBinding.video);
mClock = Clock.create(mBinding.widget.time);
mClock = Clock.create(mBinding.widget.clock);
setPadding(mBinding.control.getRoot());
setPadding(mBinding.widget.epg, true);
setPadding(mBinding.recycler, true);
@ -913,25 +913,20 @@ public class LiveActivity extends BaseActivity implements CustomKeyDownLive.List
}
private void prevLine() {
if (mChannel == null) return;
if (mChannel == null || mChannel.isOnly()) return;
mChannel.prevLine();
showInfo();
fetch();
}
private void nextLine(boolean show) {
if (mChannel == null) return;
if (mChannel == null || mChannel.isOnly()) return;
mChannel.nextLine();
if (show) showInfo();
else setInfo();
fetch();
}
private void seekTo() {
mPlayers.seekTo(Constant.INTERVAL_SEEK * 3);
showProgress();
}
private void onPaused() {
checkPlayImg(false);
mPlayers.pause();
@ -1007,6 +1002,21 @@ public class LiveActivity extends BaseActivity implements CustomKeyDownLive.List
public void onCasted() {
}
@Override
public void onSpeedUp() {
if (!mPlayers.isVod() || !mPlayers.isPlaying() || !mPlayers.canAdjustSpeed()) return;
mBinding.control.action.speed.setText(mPlayers.setSpeed(mPlayers.getSpeed() < 3 ? 3 : 5));
mBinding.widget.speed.startAnimation(ResUtil.getAnim(R.anim.forward));
mBinding.widget.speed.setVisibility(View.VISIBLE);
}
@Override
public void onSpeedEnd() {
mBinding.control.action.speed.setText(mPlayers.setSpeed(1.0f));
mBinding.widget.speed.setVisibility(View.GONE);
mBinding.widget.speed.clearAnimation();
}
@Override
public void onBright(int progress) {
mBinding.widget.bright.setVisibility(View.VISIBLE);
@ -1037,26 +1047,39 @@ public class LiveActivity extends BaseActivity implements CustomKeyDownLive.List
@Override
public void onFlingUp() {
prevChannel();
if (!mPlayers.isVod()) prevChannel();
}
@Override
public void onFlingDown() {
nextChannel();
if (!mPlayers.isVod()) nextChannel();
}
@Override
public void onFlingLeft() {
if (mChannel == null) return;
if (mChannel.isOnly() && mPlayers.isVod()) App.post(this::seekTo, 250);
else if (!mChannel.isOnly()) prevLine();
if (!mPlayers.isVod()) prevLine();
}
@Override
public void onFlingRight() {
if (mChannel == null) return;
if (mChannel.isOnly() && mPlayers.isVod()) App.post(this::seekTo, 250);
else if (!mChannel.isOnly()) nextLine(true);
if (!mPlayers.isVod()) nextLine(true);
}
@Override
public void onSeek(int time) {
if (!mPlayers.isVod()) return;
mBinding.widget.action.setImageResource(time > 0 ? R.drawable.ic_widget_forward : R.drawable.ic_widget_rewind);
mBinding.widget.time.setText(mPlayers.getPositionTime(time));
mBinding.widget.seek.setVisibility(View.VISIBLE);
hideProgress();
}
@Override
public void onSeekEnd(int time) {
mBinding.widget.seek.setVisibility(View.GONE);
mPlayers.seekTo(time);
showProgress();
onPlay();
}
@Override

@ -1510,8 +1510,8 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo
@Override
public void onSeek(int time) {
mBinding.widget.action.setImageResource(time > 0 ? R.drawable.ic_widget_forward : R.drawable.ic_widget_rewind);
mBinding.widget.seek.setVisibility(View.VISIBLE);
mBinding.widget.time.setText(mPlayers.getPositionTime(time));
mBinding.widget.seek.setVisibility(View.VISIBLE);
hideProgress();
}

@ -26,11 +26,14 @@ public class CustomKeyDownLive extends GestureDetector.SimpleOnGestureListener {
private final View videoView;
private boolean changeBright;
private boolean changeVolume;
private boolean changeSpeed;
private boolean changeTime;
private boolean center;
private boolean touch;
private boolean lock;
private float bright;
private float volume;
private int time;
public static CustomKeyDownLive create(Activity activity, View videoView) {
return new CustomKeyDownLive(activity, videoView);
@ -45,6 +48,8 @@ public class CustomKeyDownLive extends GestureDetector.SimpleOnGestureListener {
}
public boolean onTouchEvent(MotionEvent e) {
if (changeTime && e.getAction() == MotionEvent.ACTION_UP) onSeekEnd();
if (changeSpeed && e.getAction() == MotionEvent.ACTION_UP) listener.onSpeedEnd();
if (changeBright && e.getAction() == MotionEvent.ACTION_UP) listener.onBrightEnd();
if (changeVolume && e.getAction() == MotionEvent.ACTION_UP) listener.onVolumeEnd();
return e.getPointerCount() == 1 && detector.onTouchEvent(e);
@ -65,16 +70,27 @@ public class CustomKeyDownLive extends GestureDetector.SimpleOnGestureListener {
bright = Util.getBrightness(activity);
changeBright = false;
changeVolume = false;
changeSpeed = false;
changeTime = false;
center = false;
touch = true;
return true;
}
@Override
public void onLongPress(@NonNull MotionEvent e) {
if (isEdge(e) || lock) return;
changeSpeed = true;
listener.onSpeedUp();
}
@Override
public boolean onScroll(@NonNull MotionEvent e1, @NonNull MotionEvent e2, float distanceX, float distanceY) {
if (isEdge(e1) || lock) return true;
float deltaX = e2.getX() - e1.getX();
float deltaY = e1.getY() - e2.getY();
if (touch) checkFunc(distanceX, distanceY, e2);
if (changeTime) listener.onSeek(time = (int) deltaX * 50);
if (changeBright) setBright(deltaY);
if (changeVolume) setVolume(deltaY);
return true;
@ -101,10 +117,17 @@ public class CustomKeyDownLive extends GestureDetector.SimpleOnGestureListener {
return true;
}
private void onSeekEnd() {
listener.onSeekEnd(time);
changeTime = false;
time = 0;
}
private void checkFunc(float distanceX, float distanceY, MotionEvent e2) {
int four = ResUtil.getScreenWidthNav() / 4;
if (e2.getX() > four && e2.getX() < four * 3) center = true;
else if (Math.abs(distanceX) < Math.abs(distanceY)) checkSide(e2);
if (Math.abs(distanceX) >= Math.abs(distanceY)) changeTime = true;
touch = false;
}
@ -153,6 +176,10 @@ public class CustomKeyDownLive extends GestureDetector.SimpleOnGestureListener {
public interface Listener {
void onSpeedUp();
void onSpeedEnd();
void onBright(int progress);
void onBrightEnd();
@ -169,6 +196,10 @@ public class CustomKeyDownLive extends GestureDetector.SimpleOnGestureListener {
void onFlingRight();
void onSeek(int time);
void onSeekEnd(int time);
void onSingleTap();
void onDoubleTap();

@ -56,6 +56,44 @@
</LinearLayout>
<LinearLayout
android:id="@+id/seek"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:layout_marginTop="24dp"
android:background="@drawable/shape_widget"
android:gravity="center"
android:orientation="horizontal"
android:visibility="gone"
tools:visibility="visible">
<ImageView
android:id="@+id/action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:src="@drawable/ic_widget_rewind" />
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="14sp"
tools:text="00:00:00" />
</LinearLayout>
<ImageView
android:id="@+id/speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:layout_marginTop="24dp"
android:src="@drawable/ic_widget_forward"
android:visibility="gone" />
<LinearLayout
android:id="@+id/bright"
android:layout_width="wrap_content"
@ -173,7 +211,7 @@
tools:text="來源 1" />
<TextView
android:id="@+id/time"
android:id="@+id/clock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"

Loading…
Cancel
Save