Search in sources :

Example 26 with SongInfo

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));
                    }
                }
            }
        });
    }
}
Also used : Bitmap(android.graphics.Bitmap) AlbumArtCache(com.lzx.musiclibrary.utils.AlbumArtCache) SongInfo(com.lzx.musiclibrary.aidl.model.SongInfo)

Example 27 with SongInfo

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());
}
Also used : SongInfo(com.lzx.musiclibrary.aidl.model.SongInfo)

Example 28 with SongInfo

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);
}
Also used : SongInfo(com.lzx.musiclibrary.aidl.model.SongInfo)

Example 29 with SongInfo

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();
        }
    }
}
Also used : PlaybackStateCompat(android.support.v4.media.session.PlaybackStateCompat) SongInfo(com.lzx.musiclibrary.aidl.model.SongInfo)

Example 30 with SongInfo

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;
    }
}
Also used : SongInfo(com.lzx.musiclibrary.aidl.model.SongInfo)

Aggregations

SongInfo (com.lzx.musiclibrary.aidl.model.SongInfo)31 ArrayList (java.util.ArrayList)9 AlbumInfo (com.lzx.musiclibrary.aidl.model.AlbumInfo)6 List (java.util.List)5 JSONObject (org.json.JSONObject)5 Uri (android.net.Uri)4 RetrofitHelper (com.lzx.nicemusic.network.RetrofitHelper)4 JSONArray (org.json.JSONArray)4 Cursor (android.database.Cursor)3 Gson (com.google.gson.Gson)3 LogUtil (com.lzx.musiclibrary.utils.LogUtil)3 BasePresenter (com.lzx.nicemusic.base.mvp.factory.BasePresenter)3 DataHelper (com.lzx.nicemusic.helper.DataHelper)3 Observable (io.reactivex.Observable)3 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)3 Disposable (io.reactivex.disposables.Disposable)3 Schedulers (io.reactivex.schedulers.Schedulers)3 Bitmap (android.graphics.Bitmap)2 AnimationDrawable (android.graphics.drawable.AnimationDrawable)2 Bundle (android.os.Bundle)2