Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【建议】关于PlayerController里的几个事件分发将setValue更改为postValue #14

Open
Theoneee opened this issue Jan 7, 2022 · 5 comments
Labels

Comments

@Theoneee
Copy link
Contributor

Theoneee commented Jan 7, 2022

这里的几个事件:

  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);
      }
      .....
    });

如果这样,那么是否需要对格式进行判断,或者向外曝露一个额外的判断接口,是不是更好呢。

@KunMinX
Copy link
Owner

KunMinX commented Jan 7, 2022

感谢你的反馈

格式可以手动通过 getFormatList 方法在外部添加

@Theoneee
Copy link
Contributor Author

Theoneee commented Jan 10, 2022

格式可以手动通过 getFormatList 方法在外部添加

  /**
   * 检查是否可以播放
   */
  private boolean checkAvalable(String path) {
    boolean surport = false;
    for (int i = 0; i < ext.length; i++) {
      if (path.toLowerCase().endsWith(ext[i])) {
        surport = true;
      }
    }
    if (!surport) {
      callBack(CallBackState.FORMATE_NOT_SURPORT, uiHolder.player);
      return false;
    }
    return true;
  }

现在是用后缀名去判断,但是有些播放地址不是以那个结尾的,所以在

    if (!surport) {
       return  onCustomCheckAvailable(String url)
    }

这个地方,是不是可以再一次的自行去判断。

@KunMinX
Copy link
Owner

KunMinX commented Jan 10, 2022

感觉这个建议不错。加个

@Theoneee
Copy link
Contributor Author

感觉这个建议不错。加个

感谢~

@KunMinX KunMinX added the 精华 label Jan 11, 2022
@Theoneee
Copy link
Contributor Author

用这个框架写了个APP:

HifiNi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants