From 6e2d1e9036eeb4f986ab302c09d448db5960371a Mon Sep 17 00:00:00 2001 From: kunminx Date: Fri, 12 Aug 2022 15:53:03 +0800 Subject: [PATCH] update sample codes --- README.md | 2 +- README_EN.md | 2 +- .../puremusic/player/PlayerManager.java | 28 ++---- .../puremusic/ui/page/MainFragment.java | 7 +- .../puremusic/ui/page/PlayerFragment.java | 62 ++++++------- architecture/build.gradle | 8 +- build.gradle | 6 +- player/build.gradle | 2 +- .../kunminx/player/DefaultPlayerManager.java | 32 ++----- .../com/kunminx/player/PlayerController.java | 92 ++++++------------- .../player/bean/base/BaseAlbumItem.java | 2 - .../player/bean/base/BaseArtistItem.java | 2 - .../player/bean/base/BaseMusicItem.java | 2 - .../kunminx/player/bean/dto/ChangeMusic.java | 3 - .../kunminx/player/bean/dto/PlayingMusic.java | 2 - .../player/contract/IPlayController.java | 13 +-- .../player/contract/IPlayNotifier.java | 44 --------- .../kunminx/player/domain/PlayerEvent.java | 52 +++++++++++ .../player/domain/PlayerInfoDispatcher.java | 13 +++ 19 files changed, 154 insertions(+), 220 deletions(-) delete mode 100644 player/src/main/java/com/kunminx/player/contract/IPlayNotifier.java create mode 100644 player/src/main/java/com/kunminx/player/domain/PlayerEvent.java create mode 100644 player/src/main/java/com/kunminx/player/domain/PlayerInfoDispatcher.java diff --git a/README.md b/README.md index 1eae9c4..ae75b5e 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ Jetpack-MusicPlayer 目标是:**一行代码即可接入 音乐播放控制组 1.在 build.gradle 中添加依赖。 ```groovy -implementation 'com.kunminx.player:player:3.7.0' +implementation 'com.kunminx.player:player:4.0.0' ``` 提示:鉴于 Jcenter 关闭,我们已将仓库迁移至 Maven Central,请自行在根目录 build.gradle 添加 `mavenCentral()`。 diff --git a/README_EN.md b/README_EN.md index 5e219b8..8ab61cf 100644 --- a/README_EN.md +++ b/README_EN.md @@ -50,7 +50,7 @@ If you are thinking about [**how to choose the right architecture for your proje 1. Add a dependency on the library in build.gradle. ```groovy -implementation 'com.kunminx.player:player:3.7.0' +implementation 'com.kunminx.player:player:4.0.0' ``` Tip: 鉴于 Jcenter 的关闭,我们已将仓库迁移至 Maven Central,请自行在根目录 build.gradle 添加 `mavenCentral()`。 diff --git a/app/src/main/java/com/kunminx/puremusic/player/PlayerManager.java b/app/src/main/java/com/kunminx/puremusic/player/PlayerManager.java index b36ea0b..5459953 100644 --- a/app/src/main/java/com/kunminx/puremusic/player/PlayerManager.java +++ b/app/src/main/java/com/kunminx/puremusic/player/PlayerManager.java @@ -19,21 +19,17 @@ import android.content.Context; import android.content.Intent; -import androidx.lifecycle.LiveData; - import com.danikula.videocache.HttpProxyCacheServer; import com.kunminx.player.PlayerController; import com.kunminx.player.PlayingInfoManager; -import com.kunminx.player.bean.dto.ChangeMusic; -import com.kunminx.player.bean.dto.PlayingMusic; import com.kunminx.player.contract.ICacheProxy; import com.kunminx.player.contract.IPlayController; import com.kunminx.player.contract.IServiceNotifier; +import com.kunminx.player.domain.PlayerInfoDispatcher; import com.kunminx.puremusic.data.bean.TestAlbum; import com.kunminx.puremusic.player.helper.PlayerFileNameGenerator; import com.kunminx.puremusic.player.notification.PlayerService; -import java.util.ArrayList; import java.util.List; /** @@ -163,6 +159,11 @@ public String getTrackTime(int progress) { return mController.getTrackTime(progress); } + @Override + public PlayerInfoDispatcher getDispatcher() { + return mController.getDispatcher(); + } + @Override public TestAlbum getAlbum() { return mController.getAlbum(); @@ -183,23 +184,6 @@ public int getAlbumIndex() { return mController.getAlbumIndex(); } - public LiveData> getChangeMusicResult() { - return mController.getChangeMusicResult(); - } - - public LiveData> getPlayingMusicResult() { - return mController.getPlayingMusicResult(); - } - - public LiveData getPauseResult() { - return mController.getPauseResult(); - } - - @Override - public LiveData> getPlayModeResult() { - return mController.getPlayModeResult(); - } - @Override public Enum getRepeatMode() { return mController.getRepeatMode(); diff --git a/app/src/main/java/com/kunminx/puremusic/ui/page/MainFragment.java b/app/src/main/java/com/kunminx/puremusic/ui/page/MainFragment.java index 6245e6f..590015f 100755 --- a/app/src/main/java/com/kunminx/puremusic/ui/page/MainFragment.java +++ b/app/src/main/java/com/kunminx/puremusic/ui/page/MainFragment.java @@ -27,6 +27,7 @@ import com.kunminx.architecture.ui.page.BaseFragment; import com.kunminx.architecture.ui.page.DataBindingConfig; import com.kunminx.architecture.ui.page.State; +import com.kunminx.player.domain.PlayerEvent; import com.kunminx.puremusic.BR; import com.kunminx.puremusic.R; import com.kunminx.puremusic.data.bean.TestAlbum; @@ -73,8 +74,10 @@ protected DataBindingConfig getDataBindingConfig() { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - PlayerManager.getInstance().getChangeMusicResult().observe(getViewLifecycleOwner(), changeMusic -> { - mAdapter.notifyDataSetChanged(); + PlayerManager.getInstance().getDispatcher().output(this, playerEvent -> { + if (playerEvent.eventId == PlayerEvent.EVENT_CHANGE_MUSIC) { + mAdapter.notifyDataSetChanged(); + } }); mMusicRequester.getFreeMusicsResult().observe(getViewLifecycleOwner(), dataResult -> { diff --git a/app/src/main/java/com/kunminx/puremusic/ui/page/PlayerFragment.java b/app/src/main/java/com/kunminx/puremusic/ui/page/PlayerFragment.java index fe4125c..2c90413 100755 --- a/app/src/main/java/com/kunminx/puremusic/ui/page/PlayerFragment.java +++ b/app/src/main/java/com/kunminx/puremusic/ui/page/PlayerFragment.java @@ -32,6 +32,7 @@ import com.kunminx.architecture.utils.ToastUtils; import com.kunminx.architecture.utils.Utils; import com.kunminx.player.PlayingInfoManager; +import com.kunminx.player.domain.PlayerEvent; import com.kunminx.puremusic.BR; import com.kunminx.puremusic.R; import com.kunminx.puremusic.databinding.FragmentPlayerBinding; @@ -88,42 +89,31 @@ public void onPanelStateChanged( } }); - PlayerManager.getInstance().getChangeMusicResult().observe(getViewLifecycleOwner(), changeMusic -> { - mStates.title.set(changeMusic.getTitle()); - mStates.artist.set(changeMusic.getSummary()); - mStates.coverImg.set(changeMusic.getImg()); - - if (mListener != null) { - view.post(mListener::calculateTitleAndArtist); - } - }); - - PlayerManager.getInstance().getPlayingMusicResult().observe(getViewLifecycleOwner(), playingMusic -> { - mStates.maxSeekDuration.set(playingMusic.getDuration()); - mStates.currentSeekPosition.set(playingMusic.getPlayerPosition()); - }); - - PlayerManager.getInstance().getPauseResult().observe(getViewLifecycleOwner(), aBoolean -> { - mStates.isPlaying.set(!aBoolean); - }); - - PlayerManager.getInstance().getPlayModeResult().observe(getViewLifecycleOwner(), anEnum -> { - int tip; - if (anEnum == PlayingInfoManager.RepeatMode.LIST_CYCLE) { - mStates.playModeIcon.set(MaterialDrawableBuilder.IconValue.REPEAT); - tip = R.string.play_repeat; - } else if (anEnum == PlayingInfoManager.RepeatMode.SINGLE_CYCLE) { - mStates.playModeIcon.set(MaterialDrawableBuilder.IconValue.REPEAT_ONCE); - tip = R.string.play_repeat_once; - } else { - mStates.playModeIcon.set(MaterialDrawableBuilder.IconValue.SHUFFLE); - tip = R.string.play_shuffle; - } - if (view.getParent().getParent() instanceof SlidingUpPanelLayout) { - SlidingUpPanelLayout sliding = (SlidingUpPanelLayout) view.getParent().getParent(); - if (sliding.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) { - ToastUtils.showShortToast(getApplicationContext(), getString(tip)); - } + PlayerManager.getInstance().getDispatcher().output(this, playerEvent -> { + switch (playerEvent.eventId) { + case PlayerEvent.EVENT_CHANGE_MUSIC: + mStates.title.set(playerEvent.param.changeMusic.getTitle()); + mStates.artist.set(playerEvent.param.changeMusic.getSummary()); + mStates.coverImg.set(playerEvent.param.changeMusic.getImg()); + if (mListener != null) view.post(mListener::calculateTitleAndArtist); + break; + case PlayerEvent.EVENT_PROGRESS: + mStates.maxSeekDuration.set(playerEvent.param.playingMusic.getDuration()); + mStates.currentSeekPosition.set(playerEvent.param.playingMusic.getPlayerPosition()); + break; + case PlayerEvent.EVENT_PLAY_STATUS: + mStates.isPlaying.set(!playerEvent.param.toPause); + break; + case PlayerEvent.EVENT_REPEAT_MODE: + Enum anEnum = playerEvent.param.repeatMode; + if (anEnum == PlayingInfoManager.RepeatMode.LIST_CYCLE) { + mStates.playModeIcon.set(MaterialDrawableBuilder.IconValue.REPEAT); + } else if (anEnum == PlayingInfoManager.RepeatMode.SINGLE_CYCLE) { + mStates.playModeIcon.set(MaterialDrawableBuilder.IconValue.REPEAT_ONCE); + } else { + mStates.playModeIcon.set(MaterialDrawableBuilder.IconValue.SHUFFLE); + } + break; } }); diff --git a/architecture/build.gradle b/architecture/build.gradle index ccc713c..8fd8f43 100644 --- a/architecture/build.gradle +++ b/architecture/build.gradle @@ -43,9 +43,11 @@ dependencies { androidTestImplementation "androidx.test.ext:junit:1.1.3" androidTestImplementation "androidx.test.espresso:espresso-core:3.4.0" - api "androidx.appcompat:appcompat:1.4.2" - api "androidx.navigation:navigation-runtime:2.5.0" - + api "androidx.appcompat:appcompat:1.5.0" + api "androidx.navigation:navigation-runtime:2.5.1" + api('com.github.KunMinX:MVI-Dispatcher:6.1.0-beta') { + exclude group: 'com.kunminx.arch', module: 'unpeek-livedata' + } api 'com.github.KunMinX:UnPeek-LiveData:v7.6.0' api 'com.github.KunMinX:Smooth-Navigation:v4.0.0' api 'com.github.KunMinX.Strict-DataBinding:strict_databinding:5.3.0' diff --git a/build.gradle b/build.gradle index 9c80145..7bce513 100644 --- a/build.gradle +++ b/build.gradle @@ -2,10 +2,10 @@ apply plugin: 'io.codearte.nexus-staging' buildscript { ext { - appTargetSdk = 31 + appTargetSdk = 32 appMinSdk = 23 - appVersionCode = 30700 - appVersionName = "3.7.0" + appVersionCode = 40000 + appVersionName = "4.0.0" lifecycleVersion = "2.4.1" navigationVersion = "2.4.2" } diff --git a/player/build.gradle b/player/build.gradle index 4ab4077..40f7c38 100644 --- a/player/build.gradle +++ b/player/build.gradle @@ -79,9 +79,9 @@ dependencies { testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + implementation "androidx.appcompat:appcompat:1.5.0" api('com.github.KunMinX:MVI-Dispatcher:6.1.0-beta') { exclude group: 'com.kunminx.arch', module: 'unpeek-livedata' } implementation 'com.google.android.exoplayer:exoplayer:2.18.1' - implementation "androidx.lifecycle:lifecycle-livedata:2.4.1" } diff --git a/player/src/main/java/com/kunminx/player/DefaultPlayerManager.java b/player/src/main/java/com/kunminx/player/DefaultPlayerManager.java index 1e2121a..181ccc2 100644 --- a/player/src/main/java/com/kunminx/player/DefaultPlayerManager.java +++ b/player/src/main/java/com/kunminx/player/DefaultPlayerManager.java @@ -19,14 +19,11 @@ import android.annotation.SuppressLint; import android.content.Context; -import androidx.lifecycle.LiveData; - import com.kunminx.player.bean.DefaultAlbum; -import com.kunminx.player.bean.dto.ChangeMusic; -import com.kunminx.player.bean.dto.PlayingMusic; import com.kunminx.player.contract.ICacheProxy; import com.kunminx.player.contract.IPlayController; import com.kunminx.player.contract.IServiceNotifier; +import com.kunminx.player.domain.PlayerInfoDispatcher; import java.util.List; @@ -138,6 +135,11 @@ public String getTrackTime(int progress) { return mController.getTrackTime(progress); } + @Override + public PlayerInfoDispatcher getDispatcher() { + return mController.getDispatcher(); + } + @Override public DefaultAlbum getAlbum() { return mController.getAlbum(); @@ -158,28 +160,6 @@ public int getAlbumIndex() { return mController.getAlbumIndex(); } - public LiveData> getChangeMusicResult() { - return mController.getChangeMusicResult(); - } - - public LiveData> getPlayingMusicResult() { - return mController.getPlayingMusicResult(); - } - - public LiveData getPauseResult() { - return mController.getPauseResult(); - } - - - @Override - public LiveData> getPlayModeResult() { - return mController.getPlayModeResult(); - } - @Override public Enum getRepeatMode() { return mController.getRepeatMode(); diff --git a/player/src/main/java/com/kunminx/player/PlayerController.java b/player/src/main/java/com/kunminx/player/PlayerController.java index 792256a..471b565 100644 --- a/player/src/main/java/com/kunminx/player/PlayerController.java +++ b/player/src/main/java/com/kunminx/player/PlayerController.java @@ -21,9 +21,6 @@ import android.os.Handler; import android.text.TextUtils; -import androidx.lifecycle.LiveData; -import androidx.lifecycle.MutableLiveData; - import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.MediaItem; import com.kunminx.player.bean.base.BaseAlbumItem; @@ -33,6 +30,8 @@ import com.kunminx.player.bean.dto.PlayingMusic; import com.kunminx.player.contract.ICacheProxy; import com.kunminx.player.contract.IServiceNotifier; +import com.kunminx.player.domain.PlayerEvent; +import com.kunminx.player.domain.PlayerInfoDispatcher; import java.util.List; @@ -48,19 +47,15 @@ public class PlayerController< private boolean mIsChangingPlayingMusic; private ICacheProxy mICacheProxy; - - private final MutableLiveData> changeMusicLiveData = new MutableLiveData<>(); - private final MutableLiveData> playingMusicLiveData = new MutableLiveData<>(); - private final MutableLiveData pauseLiveData = new MutableLiveData<>(); - private final MutableLiveData> playModeLiveData = new MutableLiveData<>(); - private IServiceNotifier mIServiceNotifier; + private final PlayerInfoDispatcher mDispatcher = new PlayerInfoDispatcher(); private final PlayingMusic mCurrentPlay = new PlayingMusic<>("00:00", "00:00"); private final ChangeMusic mChangeMusic = new ChangeMusic<>(); private ExoPlayer mPlayer; - private Handler mHandler = new Handler(); + private final static Handler mHandler = new Handler(); + private final Runnable mProgressAction = this::updateProgress; public void init(Context context, IServiceNotifier iServiceNotifier, ICacheProxy iCacheProxy) { mIServiceNotifier = iServiceNotifier; @@ -81,7 +76,7 @@ private void updateProgress() { mCurrentPlay.setAllTime(calculateTime(mPlayer.getDuration() / 1000)); mCurrentPlay.setDuration((int) mPlayer.getDuration()); mCurrentPlay.setPlayerPosition((int) mPlayer.getCurrentPosition()); - playingMusicLiveData.postValue(mCurrentPlay); + mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_PROGRESS).setPlayingMusic(mCurrentPlay)); if (mCurrentPlay.getAllTime().equals(mCurrentPlay.getNowTime())) { if (getRepeatMode() == PlayingInfoManager.RepeatMode.SINGLE_CYCLE) playAgain(); else playNext(); @@ -89,8 +84,6 @@ private void updateProgress() { mHandler.postDelayed(mProgressAction, 1000); } - private Runnable mProgressAction = () -> updateProgress(); - private void setAlbum(B musicAlbum, int albumIndex) { mPlayingInfoManager.setMusicAlbum(musicAlbum); mPlayingInfoManager.setAlbumIndex(albumIndex); @@ -114,7 +107,6 @@ public void playAudio(int albumIndex) { if (isPlaying() && albumIndex == mPlayingInfoManager.getAlbumIndex()) { return; } - mPlayingInfoManager.setAlbumIndex(albumIndex); setChangingPlayingMusic(true); playAudio(); @@ -122,11 +114,8 @@ public void playAudio(int albumIndex) { public void playAudio() { - if (mIsChangingPlayingMusic) { - getUrlAndPlay(); - } else if (isPaused()) { - resumeAudio(); - } + if (mIsChangingPlayingMusic) getUrlAndPlay(); + else if (isPaused()) resumeAudio(); } private void getUrlAndPlay() { @@ -156,16 +145,14 @@ private void getUrlAndPlay() { private void afterPlay() { setChangingPlayingMusic(false); mHandler.post(mProgressAction); - pauseLiveData.postValue(false); - if (mIServiceNotifier != null) { - mIServiceNotifier.notifyService(true); - } + mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_PLAY_STATUS).setStatus(false)); + if (mIServiceNotifier != null) mIServiceNotifier.notifyService(true); } public void requestLastPlayingInfo() { - playingMusicLiveData.postValue(mCurrentPlay); - changeMusicLiveData.postValue(mChangeMusic); - pauseLiveData.postValue(isPaused()); + mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_PROGRESS).setPlayingMusic(mCurrentPlay)); + mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_CHANGE_MUSIC).setChangeMusic(mChangeMusic)); + mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_PLAY_STATUS).setStatus(isPaused())); } public void setSeek(int progress) { @@ -186,9 +173,7 @@ private String calculateTime(long _time) { return (minute < 10 ? "0" + minute : "" + minute) + (second < 10 ? ":0" + second : ":" + second); } else { second = time; - if (second < 10) { - return "00:0" + second; - } + if (second < 10) return "00:0" + second; return "00:" + second; } } @@ -213,29 +198,23 @@ public void playAgain() { public void pauseAudio() { mPlayer.pause(); mHandler.removeCallbacks(mProgressAction); - pauseLiveData.postValue(true); - if (mIServiceNotifier != null) { - mIServiceNotifier.notifyService(true); - } + mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_PLAY_STATUS).setStatus(true)); + if (mIServiceNotifier != null) mIServiceNotifier.notifyService(true); } public void resumeAudio() { mPlayer.play(); mHandler.post(mProgressAction); - pauseLiveData.postValue(false); - if (mIServiceNotifier != null) { - mIServiceNotifier.notifyService(true); - } + mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_PLAY_STATUS).setStatus(false)); + if (mIServiceNotifier != null) mIServiceNotifier.notifyService(true); } public void clear() { mPlayer.stop(); mPlayer.clearMediaItems(); - pauseLiveData.postValue(true); + mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_PLAY_STATUS).setStatus(true)); resetIsChangingPlayingChapter(); - if (mIServiceNotifier != null) { - mIServiceNotifier.notifyService(false); - } + if (mIServiceNotifier != null) mIServiceNotifier.notifyService(false); } public void resetIsChangingPlayingChapter() { @@ -244,7 +223,7 @@ public void resetIsChangingPlayingChapter() { } public void changeMode() { - playModeLiveData.postValue(mPlayingInfoManager.changeMode()); + mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_REPEAT_MODE).setRepeatMode(mPlayingInfoManager.changeMode())); } public B getAlbum() { @@ -259,7 +238,7 @@ public void setChangingPlayingMusic(boolean changingPlayingMusic) { mIsChangingPlayingMusic = changingPlayingMusic; if (mIsChangingPlayingMusic) { mChangeMusic.setBaseInfo(mPlayingInfoManager.getMusicAlbum(), getCurrentPlayingMusic()); - changeMusicLiveData.postValue(mChangeMusic); + mDispatcher.input(new PlayerEvent(PlayerEvent.EVENT_CHANGE_MUSIC).setChangeMusic(mChangeMusic)); mCurrentPlay.setBaseInfo(mPlayingInfoManager.getMusicAlbum(), getCurrentPlayingMusic()); mCurrentPlay.setNowTime("00:00"); mCurrentPlay.setAllTime("00:00"); @@ -272,35 +251,20 @@ public int getAlbumIndex() { return mPlayingInfoManager.getAlbumIndex(); } - public LiveData> getChangeMusicResult() { - return changeMusicLiveData; - } - - public LiveData> getPlayingMusicResult() { - return playingMusicLiveData; - } - - public LiveData getPauseResult() { - return pauseLiveData; - } - - public LiveData> getPlayModeResult() { - return playModeLiveData; - } - public Enum getRepeatMode() { return mPlayingInfoManager.getRepeatMode(); } public void togglePlay() { - if (isPlaying()) { - pauseAudio(); - } else { - playAudio(); - } + if (isPlaying()) pauseAudio(); + else playAudio(); } public M getCurrentPlayingMusic() { return mPlayingInfoManager.getCurrentPlayingMusic(); } + + public PlayerInfoDispatcher getDispatcher() { + return mDispatcher; + } } diff --git a/player/src/main/java/com/kunminx/player/bean/base/BaseAlbumItem.java b/player/src/main/java/com/kunminx/player/bean/base/BaseAlbumItem.java index c73ecc3..1706f1b 100644 --- a/player/src/main/java/com/kunminx/player/bean/base/BaseAlbumItem.java +++ b/player/src/main/java/com/kunminx/player/bean/base/BaseAlbumItem.java @@ -20,8 +20,6 @@ import java.util.List; /** - * 音乐专辑实体, music album bean - *

* Create by KunMinX at 18/9/24 */ public class BaseAlbumItem< diff --git a/player/src/main/java/com/kunminx/player/bean/base/BaseArtistItem.java b/player/src/main/java/com/kunminx/player/bean/base/BaseArtistItem.java index 456bd63..05e9523 100644 --- a/player/src/main/java/com/kunminx/player/bean/base/BaseArtistItem.java +++ b/player/src/main/java/com/kunminx/player/bean/base/BaseArtistItem.java @@ -19,8 +19,6 @@ import java.io.Serializable; /** - * 作者实体,music artist bean - *

* Create by KunMinX at 19/10/31 */ public class BaseArtistItem implements Serializable { diff --git a/player/src/main/java/com/kunminx/player/bean/base/BaseMusicItem.java b/player/src/main/java/com/kunminx/player/bean/base/BaseMusicItem.java index 305931c..e028443 100644 --- a/player/src/main/java/com/kunminx/player/bean/base/BaseMusicItem.java +++ b/player/src/main/java/com/kunminx/player/bean/base/BaseMusicItem.java @@ -19,8 +19,6 @@ import java.io.Serializable; /** - * 音乐实体,music bean - *

* Create by KunMinX at 18/9/24 */ public class BaseMusicItem implements Serializable { diff --git a/player/src/main/java/com/kunminx/player/bean/dto/ChangeMusic.java b/player/src/main/java/com/kunminx/player/bean/dto/ChangeMusic.java index f9f7ce3..0872cf3 100644 --- a/player/src/main/java/com/kunminx/player/bean/dto/ChangeMusic.java +++ b/player/src/main/java/com/kunminx/player/bean/dto/ChangeMusic.java @@ -23,8 +23,6 @@ import java.io.Serializable; /** - * provide music info when music changed - *

* Create by KunMinX at 18/9/24 */ public class ChangeMusic< @@ -69,7 +67,6 @@ public ChangeMusic(B musicAlbum, int playIndex) { } public void setBaseInfo(B musicAlbum, M music) { - //要用当前实际播放列表,因为不同模式存在不同播放列表 this.title = music.getTitle(); this.summary = musicAlbum.getSummary(); this.albumId = musicAlbum.getAlbumId(); diff --git a/player/src/main/java/com/kunminx/player/bean/dto/PlayingMusic.java b/player/src/main/java/com/kunminx/player/bean/dto/PlayingMusic.java index cd79a23..e3e5122 100644 --- a/player/src/main/java/com/kunminx/player/bean/dto/PlayingMusic.java +++ b/player/src/main/java/com/kunminx/player/bean/dto/PlayingMusic.java @@ -24,8 +24,6 @@ import java.io.Serializable; /** - * provide play info of playing music - *

* Create by KunMinX at 18/9/24 */ public class PlayingMusic< diff --git a/player/src/main/java/com/kunminx/player/contract/IPlayController.java b/player/src/main/java/com/kunminx/player/contract/IPlayController.java index 6b2a9a6..ab0a51e 100644 --- a/player/src/main/java/com/kunminx/player/contract/IPlayController.java +++ b/player/src/main/java/com/kunminx/player/contract/IPlayController.java @@ -21,26 +21,27 @@ import com.kunminx.player.bean.base.BaseAlbumItem; import com.kunminx.player.bean.base.BaseArtistItem; import com.kunminx.player.bean.base.BaseMusicItem; +import com.kunminx.player.domain.PlayerInfoDispatcher; /** * Create by KunMinX at 18/9/24 */ -public interface IPlayController, M extends BaseMusicItem, A extends BaseArtistItem> - extends IPlayNotifier, IPlayInfoManager { +public interface IPlayController< + B extends BaseAlbumItem, + M extends BaseMusicItem, + A extends BaseArtistItem> + extends IPlayInfoManager { - //程序启动时就初始化 void init(Context context, IServiceNotifier iServiceNotifier, ICacheProxy iCacheProxy); void loadAlbum(B musicAlbum); - //切换专辑时。只在从新专辑进入播放页面时切换。 void loadAlbum(B musicAlbum, int playIndex); void playAudio(); void playAudio(int albumIndex); - //手动点击,和自动next,都调用这个 void playNext(); void playPrevious(); @@ -55,7 +56,6 @@ public interface IPlayController, M extends BaseMu void clear(); - //切换循环模式 void changeMode(); boolean isPlaying(); @@ -68,4 +68,5 @@ public interface IPlayController, M extends BaseMu String getTrackTime(int progress); + PlayerInfoDispatcher getDispatcher(); } diff --git a/player/src/main/java/com/kunminx/player/contract/IPlayNotifier.java b/player/src/main/java/com/kunminx/player/contract/IPlayNotifier.java deleted file mode 100644 index b58c20f..0000000 --- a/player/src/main/java/com/kunminx/player/contract/IPlayNotifier.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2018-2019 KunMinX - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.kunminx.player.contract; - -import androidx.lifecycle.LiveData; - -import com.kunminx.player.PlayingInfoManager; -import com.kunminx.player.bean.base.BaseAlbumItem; -import com.kunminx.player.bean.base.BaseArtistItem; -import com.kunminx.player.bean.base.BaseMusicItem; -import com.kunminx.player.bean.dto.ChangeMusic; -import com.kunminx.player.bean.dto.PlayingMusic; - -/** - * Create by KunMinX at 19/11/1 - */ -public interface IPlayNotifier< - B extends BaseAlbumItem, - M extends BaseMusicItem, - A extends BaseArtistItem> { - - LiveData> getChangeMusicResult(); - - LiveData> getPlayingMusicResult(); - - LiveData getPauseResult(); - - LiveData> getPlayModeResult(); - -} diff --git a/player/src/main/java/com/kunminx/player/domain/PlayerEvent.java b/player/src/main/java/com/kunminx/player/domain/PlayerEvent.java new file mode 100644 index 0000000..7581827 --- /dev/null +++ b/player/src/main/java/com/kunminx/player/domain/PlayerEvent.java @@ -0,0 +1,52 @@ +package com.kunminx.player.domain; + +import com.kunminx.architecture.domain.event.Event; +import com.kunminx.player.PlayingInfoManager; +import com.kunminx.player.bean.dto.ChangeMusic; +import com.kunminx.player.bean.dto.PlayingMusic; + +/** + * Create by KunMinX at 2022/7/4 + */ +public class PlayerEvent extends Event { + public final static int EVENT_CHANGE_MUSIC = 1; + public final static int EVENT_PROGRESS = 2; + public final static int EVENT_PLAY_STATUS = 3; + public final static int EVENT_REPEAT_MODE = 4; + + public PlayerEvent(int eventId) { + this.eventId = eventId; + this.param = new Param(); + this.result = new Result(); + } + + public static class Param { + public ChangeMusic changeMusic; + public PlayingMusic playingMusic; + public boolean toPause; + public Enum repeatMode; + } + + public PlayerEvent setPlayingMusic(PlayingMusic music) { + param.playingMusic = music; + return this; + } + + public PlayerEvent setChangeMusic(ChangeMusic music) { + param.changeMusic = music; + return this; + } + + public PlayerEvent setStatus(boolean toPause) { + param.toPause = toPause; + return this; + } + + public PlayerEvent setRepeatMode(Enum repeatMode) { + param.repeatMode = repeatMode; + return this; + } + + public static class Result { + } +} diff --git a/player/src/main/java/com/kunminx/player/domain/PlayerInfoDispatcher.java b/player/src/main/java/com/kunminx/player/domain/PlayerInfoDispatcher.java new file mode 100644 index 0000000..34ab4cd --- /dev/null +++ b/player/src/main/java/com/kunminx/player/domain/PlayerInfoDispatcher.java @@ -0,0 +1,13 @@ +package com.kunminx.player.domain; + +import com.kunminx.architecture.domain.dispatch.MviDispatcher; + +/** + * Create by KunMinX at 2022/8/12 + */ +public class PlayerInfoDispatcher extends MviDispatcher { + @Override + protected void onHandle(PlayerEvent event) { + sendResult(event); + } +}