|
|
|
|
@ -11,12 +11,14 @@ import androidx.viewbinding.ViewBinding; |
|
|
|
|
import com.fongmi.bear.R; |
|
|
|
|
import com.fongmi.bear.bean.Vod; |
|
|
|
|
import com.fongmi.bear.databinding.ActivityPlayBinding; |
|
|
|
|
import com.fongmi.bear.databinding.ViewControllerBinding; |
|
|
|
|
import com.fongmi.bear.event.PlayerEvent; |
|
|
|
|
import com.fongmi.bear.impl.KeyDownImpl; |
|
|
|
|
import com.fongmi.bear.model.SiteViewModel; |
|
|
|
|
import com.fongmi.bear.player.Players; |
|
|
|
|
import com.fongmi.bear.utils.KeyDown; |
|
|
|
|
import com.fongmi.bear.utils.Notify; |
|
|
|
|
import com.fongmi.bear.utils.Prefers; |
|
|
|
|
import com.fongmi.bear.utils.ResUtil; |
|
|
|
|
import com.fongmi.bear.utils.Utils; |
|
|
|
|
import com.google.android.exoplayer2.Player; |
|
|
|
|
@ -27,6 +29,7 @@ import org.greenrobot.eventbus.ThreadMode; |
|
|
|
|
|
|
|
|
|
public class PlayActivity extends BaseActivity implements KeyDownImpl { |
|
|
|
|
|
|
|
|
|
private ViewControllerBinding mControl; |
|
|
|
|
private ActivityPlayBinding mBinding; |
|
|
|
|
private SiteViewModel mSiteViewModel; |
|
|
|
|
private Vod.Flag mVodFlag; |
|
|
|
|
@ -52,7 +55,13 @@ public class PlayActivity extends BaseActivity implements KeyDownImpl { |
|
|
|
|
protected void initView() { |
|
|
|
|
mKeyDown = KeyDown.create(this); |
|
|
|
|
mVodFlag = Vod.Flag.objectFrom(getFlag()); |
|
|
|
|
mControl = ViewControllerBinding.bind(mBinding.video.findViewById(R.id.control)); |
|
|
|
|
mControl.scale.setText(ResUtil.getStringArray(R.array.select_scale)[Prefers.getScale()]); |
|
|
|
|
mBinding.video.setPlayer(Players.get().callback(this).exo()); |
|
|
|
|
mBinding.video.setControllerHideOnTouch(false); |
|
|
|
|
mBinding.video.setControllerShowTimeoutMs(0); |
|
|
|
|
mBinding.video.setResizeMode(Prefers.getScale()); |
|
|
|
|
mControl.speed.setText(Players.get().getSpeed()); |
|
|
|
|
setViewModel(); |
|
|
|
|
findCurrent(); |
|
|
|
|
} |
|
|
|
|
@ -60,22 +69,18 @@ public class PlayActivity extends BaseActivity implements KeyDownImpl { |
|
|
|
|
@Override |
|
|
|
|
protected void initEvent() { |
|
|
|
|
EventBus.getDefault().register(this); |
|
|
|
|
mBinding.video.findViewById(R.id.next).setOnClickListener(view -> { |
|
|
|
|
int max = mVodFlag.getEpisodes().size() - 1; |
|
|
|
|
mCurrent = ++mCurrent > max ? max : mCurrent; |
|
|
|
|
if (mVodFlag.getEpisodes().get(mCurrent).isActivated()) Notify.show(R.string.error_play_next); |
|
|
|
|
else getPlayer(); |
|
|
|
|
}); |
|
|
|
|
mBinding.video.findViewById(R.id.prev).setOnClickListener(view -> { |
|
|
|
|
mCurrent = --mCurrent < 0 ? 0 : mCurrent; |
|
|
|
|
if (mVodFlag.getEpisodes().get(mCurrent).isActivated()) Notify.show(R.string.error_play_prev); |
|
|
|
|
else getPlayer(); |
|
|
|
|
}); |
|
|
|
|
mControl.next.setOnClickListener(view -> onNext()); |
|
|
|
|
mControl.prev.setOnClickListener(view -> onPrev()); |
|
|
|
|
mControl.replay.setOnClickListener(view -> getPlayer()); |
|
|
|
|
mControl.speed.setOnClickListener(view -> mControl.speed.setText(Players.get().addSpeed())); |
|
|
|
|
mControl.scale.setOnClickListener(view -> onScale()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void setViewModel() { |
|
|
|
|
mSiteViewModel = new ViewModelProvider(this).get(SiteViewModel.class); |
|
|
|
|
mSiteViewModel.player.observe(this, object -> Players.get().setMediaSource(object)); |
|
|
|
|
mSiteViewModel.player.observe(this, object -> { |
|
|
|
|
if (object != null) Players.get().setMediaSource(object); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void findCurrent() { |
|
|
|
|
@ -88,11 +93,31 @@ public class PlayActivity extends BaseActivity implements KeyDownImpl { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void getPlayer() { |
|
|
|
|
Vod.Flag.Episode episode = mVodFlag.getEpisodes().get(mCurrent); |
|
|
|
|
mVodFlag.setActivated(episode); |
|
|
|
|
mBinding.progress.getRoot().setVisibility(View.VISIBLE); |
|
|
|
|
Vod.Flag.Episode episode = mVodFlag.getEpisodes().get(mCurrent); |
|
|
|
|
mSiteViewModel.playerContent(mVodFlag.getFlag(), episode.getUrl()); |
|
|
|
|
Notify.show(ResUtil.getString(R.string.play_ready, episode.getName())); |
|
|
|
|
mVodFlag.setActivated(episode); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void onNext() { |
|
|
|
|
int max = mVodFlag.getEpisodes().size() - 1; |
|
|
|
|
mCurrent = ++mCurrent > max ? max : mCurrent; |
|
|
|
|
if (mVodFlag.getEpisodes().get(mCurrent).isActivated()) Notify.show(R.string.error_play_next); |
|
|
|
|
else getPlayer(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void onPrev() { |
|
|
|
|
mCurrent = --mCurrent < 0 ? 0 : mCurrent; |
|
|
|
|
if (mVodFlag.getEpisodes().get(mCurrent).isActivated()) Notify.show(R.string.error_play_prev); |
|
|
|
|
else getPlayer(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void onScale() { |
|
|
|
|
int scale = mBinding.video.getResizeMode(); |
|
|
|
|
mBinding.video.setResizeMode(scale = scale >= 4 ? 0 : scale + 1); |
|
|
|
|
mControl.scale.setText(ResUtil.getStringArray(R.array.select_scale)[scale]); |
|
|
|
|
Prefers.putScale(scale); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN) |
|
|
|
|
|