Skip to content

Commit

Permalink
update progress state get
Browse files Browse the repository at this point in the history
  • Loading branch information
KunMinX committed Sep 12, 2023
1 parent f47dcf8 commit 12a81c2
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 25 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ dependencies {

implementation "org.slf4j:slf4j-android:1.7.36"
implementation "com.sothree.slidinguppanel:library:3.4.0"
implementation 'com.github.KunMinX:Jetpack-MusicPlayer:4.2.0'
// implementation 'com.github.KunMinX:Jetpack-MusicPlayer:4.2.0'
implementation project(":player")
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.content.Intent;

import com.danikula.videocache.HttpProxyCacheServer;
import com.kunminx.architecture.ui.state.State;
import com.kunminx.player.PlayerController;
import com.kunminx.player.PlayingInfoManager;
import com.kunminx.player.contract.ICacheProxy;
Expand Down Expand Up @@ -171,6 +172,16 @@ public PlayerInfoDispatcher<TestAlbum, TestAlbum.TestMusic, TestAlbum.TestArtist
return mController.getDispatcher();
}

@Override
public State<Integer> getCurrentPositionState() {
return mController.mCurrentPositionState;
}

@Override
public State<Integer> getDurationState() {
return mController.mDurationState;
}

@Override
public TestAlbum getAlbum() {
return mController.getAlbum();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ protected void initViewModel() {
@Override
protected DataBindingConfig getDataBindingConfig() {
return new DataBindingConfig(R.layout.fragment_player, BR.vm, mStates)
.addBindingParam(BR.panelVm, mAnimatorStates)
.addBindingParam(BR.click, new ClickProxy())
.addBindingParam(BR.listener, new ListenerHandler());
.addBindingParam(BR.panelVm, mAnimatorStates)
.addBindingParam(BR.player, PlayerManager.getInstance())
.addBindingParam(BR.click, new ClickProxy())
.addBindingParam(BR.listener, new ListenerHandler());
}

@Override
Expand All @@ -83,11 +84,11 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
sliding.addPanelSlideListener(new DefaultInterface.PanelSlideListener() {
@Override
public void onPanelStateChanged(
View view, SlidingUpPanelLayout.PanelState panelState,
SlidingUpPanelLayout.PanelState panelState1) {
View view, SlidingUpPanelLayout.PanelState panelState,
SlidingUpPanelLayout.PanelState panelState1) {
DrawerCoordinateManager.getInstance().requestToUpdateDrawerMode(
panelState1 == SlidingUpPanelLayout.PanelState.EXPANDED,
this.getClass().getSimpleName()
panelState1 == SlidingUpPanelLayout.PanelState.EXPANDED,
this.getClass().getSimpleName()
);
}
});
Expand Down Expand Up @@ -116,10 +117,6 @@ public void onPanelStateChanged(
mStates.coverImg.set(playerEvent.changeMusic.getImg());
if (mListener != null) view.post(mListener::calculateTitleAndArtist);
break;
case PlayerEvent.EVENT_PROGRESS:
mStates.maxSeekDuration.set(playerEvent.playingMusic.getDuration());
mStates.currentSeekPosition.set(playerEvent.playingMusic.getPlayerPosition());
break;
case PlayerEvent.EVENT_PLAY_STATUS:
mStates.isPlaying.set(!playerEvent.toPause);
break;
Expand Down Expand Up @@ -166,8 +163,6 @@ public static class PlayerStates extends StateHolder {
public final State<String> artist = new State<>(Utils.getApp().getString(R.string.app_name));
public final State<String> coverImg = new State<>("");
public final State<Drawable> placeHolder = new State<>(Res.getDrawable(R.drawable.bg_album_default));
public final State<Integer> maxSeekDuration = new State<>(0);
public final State<Integer> currentSeekPosition = new State<>(0);
public final State<Boolean> isPlaying = new State<>(false, true);
public final State<MaterialDrawableBuilder.IconValue> playModeIcon = new State<>(PlayerManager.getInstance().getModeIcon());
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout-land/fragment_player.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@
android:background="@color/transparent"
android:clickable="true"
android:focusable="true"
android:max="@{vm.maxSeekDuration}"
android:max="@{player.durationState}"
android:minHeight="6dp"
android:paddingTop="24dp"
android:progress="@{vm.currentSeekPosition}"
android:progress="@{player.currentPositionState}"
android:progressDrawable="@drawable/progressbar_color"
android:thumb="@null"
android:visibility="visible"
Expand Down
12 changes: 8 additions & 4 deletions app/src/main/res/layout/fragment_player.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
name="panelVm"
type="com.kunminx.puremusic.ui.view.PlayerSlideListener.SlideAnimatorStates" />

<variable
name="player"
type="com.kunminx.puremusic.domain.proxy.PlayerManager" />

</data>

<androidx.coordinatorlayout.widget.CoordinatorLayout
Expand Down Expand Up @@ -110,9 +114,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:max="@{vm.maxSeekDuration}"
android:max="@{player.durationState}"
android:minHeight="4dp"
android:progress="@{vm.currentSeekPosition}"
android:progress="@{player.currentPositionState}"
android:progressDrawable="@drawable/progressbar_color"
android:progressTint="@color/transparent" />

Expand Down Expand Up @@ -246,10 +250,10 @@
android:background="@color/transparent"
android:clickable="true"
android:focusable="true"
android:max="@{vm.maxSeekDuration}"
android:max="@{player.durationState}"
android:minHeight="6dp"
android:paddingTop="24dp"
android:progress="@{vm.currentSeekPosition}"
android:progress="@{player.currentPositionState}"
android:progressDrawable="@drawable/progressbar_color"
android:thumb="@null"
app:onSeekBarChangeListener="@{listener}" />
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ buildscript {
ext {
appTargetSdk = 33
appMinSdk = 15
appVersionCode = 40200
appVersionName = "4.2.0"
appVersionCode = 40300
appVersionName = "4.3.0"
lifecycleVersion = "2.4.1"
navigationVersion = "2.4.2"
}
Expand Down
1 change: 1 addition & 0 deletions player/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation "androidx.appcompat:appcompat:1.5.0"
implementation "com.github.KunMinX:MVI-Dispatcher:7.5.0"
implementation 'com.github.KunMinX.Strict-DataBinding:binding_state:5.6.0'
implementation "com.google.android.exoplayer:exoplayer:2.18.5"
}
11 changes: 11 additions & 0 deletions player/src/main/java/com/kunminx/player/DefaultPlayerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.annotation.SuppressLint;
import android.content.Context;

import com.kunminx.architecture.ui.state.State;
import com.kunminx.player.bean.DefaultAlbum;
import com.kunminx.player.contract.ICacheProxy;
import com.kunminx.player.contract.IPlayController;
Expand Down Expand Up @@ -140,6 +141,16 @@ public PlayerInfoDispatcher<DefaultAlbum, DefaultAlbum.DefaultMusic, DefaultAlbu
return mController.getDispatcher();
}

@Override
public State<Integer> getCurrentPositionState() {
return mController.mCurrentPositionState;
}

@Override
public State<Integer> getDurationState() {
return mController.mDurationState;
}

@Override
public DefaultAlbum getAlbum() {
return mController.getAlbum();
Expand Down
17 changes: 14 additions & 3 deletions player/src/main/java/com/kunminx/player/PlayerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem;
import com.kunminx.architecture.ui.state.State;
import com.kunminx.player.bean.base.BaseAlbumItem;
import com.kunminx.player.bean.base.BaseArtistItem;
import com.kunminx.player.bean.base.BaseMusicItem;
Expand All @@ -49,6 +50,8 @@ public class PlayerController<
private ICacheProxy mICacheProxy;
private IServiceNotifier mIServiceNotifier;
private final PlayerInfoDispatcher<B, M, A> mDispatcher = new PlayerInfoDispatcher<>();
public final State<Integer> mCurrentPositionState = new State<>(0);
public final State<Integer> mDurationState = new State<>(0);

private final PlayingMusic<B, M, A> mCurrentPlay = new PlayingMusic<>("00:00", "00:00");
private final ChangeMusic<B, M, A> mChangeMusic = new ChangeMusic<>();
Expand All @@ -57,10 +60,15 @@ public class PlayerController<
private final static Handler mHandler = new Handler();
private final Runnable mProgressAction = this::updateProgress;

public void init(Context context, IServiceNotifier iServiceNotifier, ICacheProxy iCacheProxy) {
public void init(Context context, IServiceNotifier iServiceNotifier, ICacheProxy iCacheProxy, int dispatcherQueueLength) {
mIServiceNotifier = iServiceNotifier;
mICacheProxy = iCacheProxy;
mPlayer = new ExoPlayer.Builder(context).build();
mDispatcher.initQueueMaxLength(dispatcherQueueLength);
}

public void init(Context context, IServiceNotifier iServiceNotifier, ICacheProxy iCacheProxy) {
init(context, iServiceNotifier, iCacheProxy, 10);
}

public boolean isInit() {
Expand All @@ -76,7 +84,8 @@ private void updateProgress() {
mCurrentPlay.setAllTime(calculateTime(mPlayer.getDuration() / 1000));
mCurrentPlay.setDuration((int) mPlayer.getDuration());
mCurrentPlay.setPlayerPosition((int) mPlayer.getCurrentPosition());
mDispatcher.input(new PlayerEvent<>(PlayerEvent.EVENT_PROGRESS, mCurrentPlay));
mCurrentPositionState.set(mCurrentPlay.getPlayerPosition());
mDurationState.set(mCurrentPlay.getDuration());
if (mCurrentPlay.getAllTime().equals(mCurrentPlay.getNowTime())) {
if (getRepeatMode() == PlayingInfoManager.RepeatMode.SINGLE_CYCLE) playAgain();
else playNext();
Expand Down Expand Up @@ -149,7 +158,8 @@ private void afterPlay() {
}

public void requestLastPlayingInfo() {
mDispatcher.input(new PlayerEvent<>(PlayerEvent.EVENT_PROGRESS, mCurrentPlay));
mCurrentPositionState.set(mCurrentPlay.getPlayerPosition());
mDurationState.set(mCurrentPlay.getDuration());
mDispatcher.input(new PlayerEvent<>(PlayerEvent.EVENT_CHANGE_MUSIC, mChangeMusic));
mDispatcher.input(new PlayerEvent<>(PlayerEvent.EVENT_PLAY_STATUS, isPaused()));
}
Expand Down Expand Up @@ -266,4 +276,5 @@ public M getCurrentPlayingMusic() {
public PlayerInfoDispatcher<B, M, A> getDispatcher() {
return mDispatcher;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import android.content.Context;

import com.kunminx.architecture.ui.state.State;
import com.kunminx.player.bean.base.BaseAlbumItem;
import com.kunminx.player.bean.base.BaseArtistItem;
import com.kunminx.player.bean.base.BaseMusicItem;
Expand Down Expand Up @@ -69,4 +70,8 @@ public interface IPlayController<
String getTrackTime(int progress);

PlayerInfoDispatcher<B, M, A> getDispatcher();

State<Integer> getCurrentPositionState();

State<Integer> getDurationState();
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ public class PlayerInfoDispatcher<
B extends BaseAlbumItem<M, A>,
M extends BaseMusicItem<A>,
A extends BaseArtistItem> extends MviDispatcher<PlayerEvent<B, M, A>> {

private int mLength = 10;

public void initQueueMaxLength(int length) {
mLength = length;
}

@Override
protected int initQueueMaxLength() {
return mLength;
}

@Override
protected void onHandle(PlayerEvent<B, M, A> event) {
sendResult(event);
Expand Down

0 comments on commit 12a81c2

Please sign in to comment.