-
Notifications
You must be signed in to change notification settings - Fork 103
Open
Labels
Description
这里的几个事件:
private final MutableLiveData<ChangeMusic> changeMusicLiveData = new MutableLiveData<>();
private final MutableLiveData<PlayingMusic> playingMusicLiveData = new MutableLiveData<>();
private final MutableLiveData<Boolean> pauseLiveData = new MutableLiveData<>();
private final MutableLiveData<Enum> playModeLiveData = new MutableLiveData<>();
在分发时都是使用的setValue,但是我在项目里的音频资源来自网络,在进行PlayerManager.getInstance().loadAlbum(album, 0)时会耗一些时间造成界面会卡一下,网络不好时甚至更会出现ANR,所以我将此方法放入了子线程,把里面的事件分发更改为postValue(),这样是不是更好一点,这样无论在子线程还是主线程能能使用。
https://ws.stream.qqmusic.qq.com/C400003nGa8A3ysktw.m4a?guid=3710892&vkey=D9C0E0E81420C49A1B5346C3F6BF0A832DBE61A32F6E990C4C95A0EB0F17D91B58550AE7D018DF8EEBA47DAAE11CCE398531632F3A77D8AD&uin=626567678&fromtag=143
将移动网络调为3G测试网络慢的情况。
MediaPlayerHelper里去掉对格式的判断
public boolean play(final String localPathOrURL) {
//if (!checkAvalable(localPathOrURL)) {
// return false;
//}
...
}MainFragment对资源进行替换:
mState.musicRequest.getFreeMusicsLiveData().observe(getViewLifecycleOwner(), dataResult -> {
if (!dataResult.getResponseStatus().isSuccess()) return;
TestAlbum musicAlbum = dataResult.getResult();
for(TestAlbum.TestMusic music:musicAlbum.getMusics()){
music.setUrl(URL);
}
.....
});如果这样,那么是否需要对格式进行判断,或者向外曝露一个额外的判断接口,是不是更好呢。