use of com.lzx.musiclibrary.aidl.model.SongInfo in project NiceMusic by lizixian18.
the class QueueManager method updateMetadata.
/**
* 更新媒体信息
*/
public void updateMetadata() {
SongInfo currentMusic = getCurrentMusic();
if (currentMusic == null) {
if (mListener != null) {
mListener.onMetadataRetrieveError();
}
return;
}
final String musicId = currentMusic.getSongId();
SongInfo metadata = QueueHelper.getMusicInfoById(mPlayingQueue, musicId);
if (metadata == null) {
throw new IllegalArgumentException("Invalid musicId " + musicId);
}
if (!TextUtils.isEmpty(metadata.getSongCover())) {
String coverUri = metadata.getSongCover();
// 获取图片bitmap
AlbumArtCache.getInstance().fetch(coverUri, new AlbumArtCache.FetchListener() {
@Override
public void onFetched(String artUrl, Bitmap bitmap, Bitmap icon) {
updateSongCoverBitmap(musicId, bitmap, icon);
SongInfo currentMusic = getCurrentMusic();
if (currentMusic == null) {
return;
}
String currentPlayingId = currentMusic.getSongId();
if (musicId.equals(currentPlayingId)) {
if (mListener != null) {
mListener.onMetadataChanged(QueueHelper.getMusicInfoById(mPlayingQueue, currentPlayingId));
}
}
}
});
}
}
use of com.lzx.musiclibrary.aidl.model.SongInfo in project NiceMusic by lizixian18.
the class SearchResultSection method onBindItemViewHolder.
@Override
public void onBindItemViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
ResultHolder holder = (ResultHolder) viewHolder;
SongInfo musicInfo = mMusicInfos.get(position);
GlideUtil.loadImageByUrl(mContext, musicInfo.getAlbumInfo().getAlbumCover(), holder.mMusicCover);
holder.mMusicName.setText(musicInfo.getSongName());
holder.mAlbumName.setText(musicInfo.getArtist());
}
use of com.lzx.musiclibrary.aidl.model.SongInfo in project NiceMusic by lizixian18.
the class PlayController method playMusicByIndex.
void playMusicByIndex(int index, boolean isJustPlay) {
if (mQueueManager.getPlayingQueue().size() == 0) {
return;
}
if (!QueueHelper.isIndexPlayable(index, mQueueManager.getPlayingQueue())) {
return;
}
SongInfo playInfo = mQueueManager.getPlayingQueue().get(index);
setCurrentQueueItem(playInfo, isJustPlay);
}
use of com.lzx.musiclibrary.aidl.model.SongInfo in project NiceMusic 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();
}
}
}
use of com.lzx.musiclibrary.aidl.model.SongInfo in project MusicLibrary 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;
}
}
Aggregations