use of com.lzx.musiclibrary.aidl.model.SongInfo in project NiceMusic by lizixian18.
the class SearchPresenter method searchMusic.
@Override
public void searchMusic(String keyword) {
Disposable disposable = RetrofitHelper.getMusicApi().searchMusic(keyword).map(responseBody -> {
JSONObject jsonObject = new JSONObject(responseBody.string());
JSONArray array = jsonObject.getJSONObject("showapi_res_body").getJSONObject("pagebean").getJSONArray("contentlist");
List<SongInfo> list = new ArrayList<>();
for (int i = 0; i < array.length(); i++) {
JSONObject object = array.getJSONObject(i);
SongInfo info = new Gson().fromJson(object.toString(), SongInfo.class);
list.add(info);
}
return list;
}).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(infoList -> mView.searchSuccess(infoList), throwable -> {
LogUtil.i("-->" + throwable.getMessage());
});
addSubscribe(disposable);
}
use of com.lzx.musiclibrary.aidl.model.SongInfo in project NiceMusic by lizixian18.
the class PlaybackManager method switchToPlayback.
public void switchToPlayback(Playback playback, boolean resumePlaying) {
if (playback == null) {
throw new IllegalArgumentException("Playback cannot be null");
}
// Suspends current state.
int oldState = mPlayback.getState();
long pos = mPlayback.getCurrentStreamPosition();
String currentMediaId = mPlayback.getCurrentMediaId();
mPlayback.stop(false);
playback.setCallback(this);
playback.setCurrentMediaId(currentMediaId);
playback.seekTo(pos < 0 ? 0 : pos);
playback.start();
// Swaps instance.
mPlayback = playback;
switch(oldState) {
case PlaybackStateCompat.STATE_BUFFERING:
case PlaybackStateCompat.STATE_CONNECTING:
case PlaybackStateCompat.STATE_PAUSED:
mPlayback.pause();
break;
case PlaybackStateCompat.STATE_PLAYING:
SongInfo currentMusic = mQueueManager.getCurrentMusic();
if (resumePlaying && currentMusic != null) {
mPlayback.play(currentMusic);
} else if (!resumePlaying) {
mPlayback.pause();
} else {
mPlayback.stop(true);
}
break;
case PlaybackStateCompat.STATE_NONE:
break;
default:
break;
}
}
use of com.lzx.musiclibrary.aidl.model.SongInfo in project NiceMusic by lizixian18.
the class PlaybackManager method handlePlayRequest.
/**
* 播放
*/
public void handlePlayRequest() {
SongInfo currentMusic = mQueueManager.getCurrentMusic();
if (currentMusic != null) {
String mediaId = currentMusic.getSongId();
boolean mediaHasChanged = !TextUtils.equals(mediaId, mCurrentMediaId);
if (mediaHasChanged) {
mCurrentMediaId = mediaId;
notifyPlaybackSwitch(currentMusic);
}
// 播放
mPlayback.play(currentMusic);
// 更新媒体信息
mQueueManager.updateMetadata();
updatePlaybackState(null);
}
}
use of com.lzx.musiclibrary.aidl.model.SongInfo in project MusicLibrary by lizixian18.
the class PlaybackManager method handlePlayRequest.
/**
* 播放
*/
public void handlePlayRequest() {
SongInfo currentMusic = mQueueManager.getCurrentMusic();
if (currentMusic != null) {
String mediaId = currentMusic.getSongId();
boolean mediaHasChanged = !TextUtils.equals(mediaId, mCurrentMediaId);
if (mediaHasChanged) {
mCurrentMediaId = mediaId;
notifyPlaybackSwitch(currentMusic);
}
// 播放
mPlayback.play(currentMusic);
// 更新媒体信息
mQueueManager.updateMetadata();
updatePlaybackState(null);
}
}
use of com.lzx.musiclibrary.aidl.model.SongInfo in project MusicLibrary by lizixian18.
the class PlaybackManager method updatePlaybackState.
public void updatePlaybackState(String error) {
long position = PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN;
if (mPlayback != null && mPlayback.isConnected()) {
position = mPlayback.getCurrentStreamPosition();
}
PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder().setActions(getAvailableActions());
// 获取播放状态
// int state = mPlayback.getState();
int state = mPlayback.getState();
// 如果是播放失败
if (error != null) {
// 设置错误信息
stateBuilder.setErrorMessage(error);
state = State.STATE_ERROR;
if (mServiceCallback != null) {
mServiceCallback.onPlaybackError(error);
}
}
// 设置播放状态
stateBuilder.setState(state == State.STATE_PLAYING ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED, position, 1.0f, SystemClock.elapsedRealtime());
// Set the activeQueueItemId if the current index is valid.
SongInfo currentMusic = mQueueManager.getCurrentMusic();
if (currentMusic != null) {
stateBuilder.setActiveQueueItemId(currentMusic.getTrackNumber());
}
if (mServiceCallback != null) {
// 回调状态更新
mServiceCallback.onPlaybackStateUpdated(state, stateBuilder.build());
// 播放/暂停状态就通知通知栏更新
if (state == State.STATE_PLAYING || state == State.STATE_PAUSED) {
mServiceCallback.onNotificationRequired();
}
}
}
Aggregations