Add play controller - part 2

pull/4/head^2
FongMi 4 years ago
parent afe8ce9dc5
commit 63ba729456
  1. 5
      app/src/main/java/com/fongmi/bear/player/Players.java
  2. 2
      app/src/main/java/com/fongmi/bear/ui/activity/PlayActivity.java
  3. 4
      app/src/main/java/com/fongmi/bear/ui/presenter/VodPresenter.java
  4. 4
      app/src/main/java/com/fongmi/bear/utils/ResUtil.java
  5. 1
      app/src/main/res/layout/activity_play.xml
  6. 13
      app/src/main/res/layout/view_controller.xml

@ -74,6 +74,11 @@ public class Players implements Player.Listener {
}); });
} }
public void toggle() {
if (exoPlayer.isPlaying()) exoPlayer.pause();
else exoPlayer.play();
}
public void pause() { public void pause() {
if (exoPlayer != null) { if (exoPlayer != null) {
exoPlayer.pause(); exoPlayer.pause();

@ -77,7 +77,7 @@ public class PlayActivity extends BaseActivity implements KeyDownImpl {
@Override @Override
public void onKeyCenter() { public void onKeyCenter() {
mBinding.video.showController(); Players.get().toggle();
} }
@Override @Override

@ -31,8 +31,8 @@ public class VodPresenter extends Presenter {
@Override @Override
public Presenter.ViewHolder onCreateViewHolder(ViewGroup parent) { public Presenter.ViewHolder onCreateViewHolder(ViewGroup parent) {
ViewHolder holder = new ViewHolder(AdapterVodBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); ViewHolder holder = new ViewHolder(AdapterVodBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
holder.binding.getRoot().getLayoutParams().width = ResUtil.dp2px(mCount == 5 ? 150 : 144); holder.binding.getRoot().getLayoutParams().width = ResUtil.getScreenWidthPx() / mCount - mCount * ResUtil.dp2px(4);
holder.binding.getRoot().getLayoutParams().height = ResUtil.dp2px(mCount == 5 ? 200 : 192); holder.binding.getRoot().getLayoutParams().height = (int) (holder.binding.getRoot().getLayoutParams().width / 0.75f);
return holder; return holder;
} }

@ -12,6 +12,10 @@ public class ResUtil {
return App.get().getResources().getDisplayMetrics(); return App.get().getResources().getDisplayMetrics();
} }
public static int getScreenWidthPx() {
return getDisplayMetrics().widthPixels;
}
public static int dp2px(int dpValue) { public static int dp2px(int dpValue) {
return Math.round(dpValue * getDisplayMetrics().density); return Math.round(dpValue * getDisplayMetrics().density);
} }

@ -10,6 +10,7 @@
android:id="@+id/video" android:id="@+id/video"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:auto_show="false"
app:controller_layout_id="@layout/view_controller" app:controller_layout_id="@layout/view_controller"
app:resize_mode="fill" /> app:resize_mode="fill" />

@ -27,18 +27,24 @@
android:textSize="16sp" /> android:textSize="16sp" />
<TextView <TextView
android:id="@+id/next"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:background="@drawable/selector_text" android:background="@drawable/selector_text"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="下一集" android:text="下一集"
android:textColor="@color/white" /> android:textColor="@color/white" />
<TextView <TextView
android:id="@+id/prev"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:background="@drawable/selector_text" android:background="@drawable/selector_text"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="上一集" android:text="上一集"
android:textColor="@color/white" /> android:textColor="@color/white" />
@ -47,6 +53,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:background="@drawable/selector_text" android:background="@drawable/selector_text"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="重播本集" android:text="重播本集"
android:textColor="@color/white" /> android:textColor="@color/white" />
@ -63,6 +71,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:background="@drawable/selector_text" android:background="@drawable/selector_text"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="x1.0" android:text="x1.0"
android:textColor="@color/white" /> android:textColor="@color/white" />
@ -79,6 +89,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:background="@drawable/selector_text" android:background="@drawable/selector_text"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="預設" android:text="預設"
android:textColor="@color/white" /> android:textColor="@color/white" />
@ -107,6 +119,7 @@
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:layout_weight="1" android:layout_weight="1"
android:nextFocusUp="@+id/next"
app:buffered_color="@color/grey_700" app:buffered_color="@color/grey_700"
app:played_color="@color/grey_900" app:played_color="@color/grey_900"
app:scrubber_color="@color/blue_500" app:scrubber_color="@color/blue_500"

Loading…
Cancel
Save