Search in sources :

Example 21 with SongInfo

use of com.lzx.musiclibrary.aidl.model.SongInfo in project NiceMusic by lizixian18.

the class DbManager method querySongInfoById.

/**
 * 获取一条音乐信息
 */
private SongInfo querySongInfoById(String songId) {
    Uri uri = MusicContentProvider.SONG_LIST_URI;
    Cursor cursor = mResolver.query(uri, null, DbConstants.MUSIC_ID + " = ?", new String[] { songId }, null);
    if (cursor == null) {
        return null;
    }
    SongInfo info = new SongInfo();
    while (cursor.moveToNext()) {
        String musicId = cursor.getString(cursor.getColumnIndex(DbConstants.MUSIC_ID));
        String artist = cursor.getString(cursor.getColumnIndex(DbConstants.ARTIST));
        String musicTitle = cursor.getString(cursor.getColumnIndex(DbConstants.MUSIC_TITLE));
        String albumTitle = cursor.getString(cursor.getColumnIndex(DbConstants.ALBUM_TITLE));
        long duration = cursor.getLong(cursor.getColumnIndex(DbConstants.DURATION));
        String cover = cursor.getString(cursor.getColumnIndex(DbConstants.COVER));
        String url = cursor.getString(cursor.getColumnIndex(DbConstants.URL));
        info.setSongId(musicId);
        info.setArtist(artist);
        info.setSongName(musicTitle);
        info.setDuration(duration);
        info.setSongCover(cover);
        info.setSongUrl(url);
        AlbumInfo albumInfo = new AlbumInfo();
        albumInfo.setAlbumName(albumTitle);
        info.setAlbumInfo(albumInfo);
    }
    cursor.close();
    return info;
}
Also used : AlbumInfo(com.lzx.musiclibrary.aidl.model.AlbumInfo) SongInfo(com.lzx.musiclibrary.aidl.model.SongInfo) Cursor(android.database.Cursor) Uri(android.net.Uri)

Example 22 with SongInfo

use of com.lzx.musiclibrary.aidl.model.SongInfo in project NiceMusic by lizixian18.

the class DataHelper method fetchArtistJSONFromUrl.

public static List<SongInfo> fetchArtistJSONFromUrl(ResponseBody responseBody) throws IOException, JSONException {
    List<SongInfo> musicInfos = new ArrayList<>();
    JSONObject jsonObject = new JSONObject(responseBody.string());
    JSONArray array = jsonObject.getJSONArray("songlist");
    for (int i = 0; i < array.length(); i++) {
        JSONObject object = array.getJSONObject(i);
        SongInfo info = getSongInfo(null, object, i);
        musicInfos.add(info);
    }
    return musicInfos;
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) SongInfo(com.lzx.musiclibrary.aidl.model.SongInfo)

Example 23 with SongInfo

use of com.lzx.musiclibrary.aidl.model.SongInfo in project NiceMusic by lizixian18.

the class MainModel method loadMainData.

/**
 * 1、新歌榜,2、热歌榜,11、摇滚榜,12、爵士,16、流行,
 * 21、欧美金曲榜,22、经典老歌榜,23、情歌对唱榜,
 * 24、影视金曲榜,25、网络歌曲榜
 *
 * @return
 */
public Observable<List<SongInfo>> loadMainData() {
    List<SongInfo> infoList = new ArrayList<>();
    return RetrofitHelper.getMusicApi().requestMusicList(1, 4, 0).flatMap(responseBody -> {
        infoList.addAll(DataHelper.fetchJSONFromUrl(responseBody));
        return RetrofitHelper.getMusicApi().requestMusicList(2, 4, 0);
    }).flatMap(responseBody -> {
        infoList.addAll(DataHelper.fetchJSONFromUrl(responseBody));
        return RetrofitHelper.getMusicApi().requestMusicList(11, 4, 0);
    }).flatMap(responseBody -> {
        infoList.addAll(DataHelper.fetchJSONFromUrl(responseBody));
        return RetrofitHelper.getMusicApi().requestMusicList(12, 4, 0);
    }).flatMap(responseBody -> {
        infoList.addAll(DataHelper.fetchJSONFromUrl(responseBody));
        return RetrofitHelper.getMusicApi().requestMusicList(16, 4, 0);
    }).flatMap(responseBody -> {
        infoList.addAll(DataHelper.fetchJSONFromUrl(responseBody));
        return RetrofitHelper.getMusicApi().requestMusicList(21, 4, 0);
    }).flatMap(responseBody -> {
        infoList.addAll(DataHelper.fetchJSONFromUrl(responseBody));
        return RetrofitHelper.getMusicApi().requestMusicList(22, 4, 0);
    }).flatMap(responseBody -> {
        infoList.addAll(DataHelper.fetchJSONFromUrl(responseBody));
        return RetrofitHelper.getMusicApi().requestMusicList(23, 4, 0);
    }).flatMap(responseBody -> {
        infoList.addAll(DataHelper.fetchJSONFromUrl(responseBody));
        return RetrofitHelper.getMusicApi().requestMusicList(24, 4, 0);
    }).flatMap(responseBody -> {
        infoList.addAll(DataHelper.fetchJSONFromUrl(responseBody));
        return RetrofitHelper.getMusicApi().requestMusicList(25, 4, 0);
    }).map(responseBody -> {
        infoList.addAll(DataHelper.fetchJSONFromUrl(responseBody));
        String json = new Gson().toJson(infoList);
        // CacheManager.getImpl().saveCache(CacheManager.KEY_HOME_LIST_DATA, json);
        return infoList;
    });
}
Also used : SongInfo(com.lzx.musiclibrary.aidl.model.SongInfo) List(java.util.List) DataHelper(com.lzx.nicemusic.helper.DataHelper) Gson(com.google.gson.Gson) Observable(io.reactivex.Observable) RetrofitHelper(com.lzx.nicemusic.network.RetrofitHelper) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) SongInfo(com.lzx.musiclibrary.aidl.model.SongInfo)

Example 24 with SongInfo

use of com.lzx.musiclibrary.aidl.model.SongInfo in project NiceMusic by lizixian18.

the class SongListPresenter method requestLiveList.

@Override
public void requestLiveList(String title) {
    int mRadioType = 2;
    int mProvinceCode = 360000;
    Map<String, String> map = new HashMap<String, String>();
    map.put(DTransferConstants.RADIOTYPE, "" + mRadioType);
    map.put(DTransferConstants.PROVINCECODE, "" + mProvinceCode);
    CommonRequest.getRadios(map, new IDataCallBack<RadioList>() {

        @Override
        public void onSuccess(RadioList object) {
            if (object != null && object.getRadios() != null) {
                List<SongInfo> musicInfos = new ArrayList<>();
                for (int i = 0; i < object.getRadios().size(); i++) {
                    Radio radio = object.getRadios().get(i);
                    SongInfo info = new SongInfo();
                    // 音乐id
                    info.setSongId(String.valueOf(radio.getDataId()));
                    // 音乐标题
                    info.setSongName(radio.getRadioName());
                    // 音乐封面
                    info.setSongCover(radio.getCoverUrlLarge());
                    // 音乐播放地址
                    info.setSongUrl(radio.getRate64AacUrl());
                    // 类型(流派)
                    info.setGenre(radio.getKind());
                    // 类型
                    info.setType(radio.getKind());
                    // 音乐大小
                    info.setSize("");
                    // 音乐长度
                    info.setDuration(0);
                    // 音乐艺术家
                    info.setArtist(radio.getRadioName());
                    // 媒体的曲目号码(序号:1234567……)
                    info.setTrackNumber(i);
                    AlbumInfo albumInfo = new AlbumInfo();
                    // 专辑id
                    albumInfo.setAlbumId(String.valueOf(radio.getDataId()));
                    // 专辑名称
                    albumInfo.setAlbumName(radio.getProgramName());
                    // 专辑封面
                    albumInfo.setAlbumCover(radio.getCoverUrlLarge());
                    // 专辑音乐数
                    albumInfo.setSongCount(0);
                    // 专辑播放数
                    albumInfo.setPlayCount(0);
                    info.setAlbumInfo(albumInfo);
                    musicInfos.add(info);
                }
                mView.onGetSongListSuccess(musicInfos, title);
                mView.onGetLiveSongSuccess(musicInfos);
            }
        }

        @Override
        public void onError(int code, String message) {
            LogUtil.i("直播 = " + message);
            Toast.makeText(mContext, "获取直播数据失败", Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : RadioList(com.ximalaya.ting.android.opensdk.model.live.radio.RadioList) HashMap(java.util.HashMap) AlbumInfo(com.lzx.musiclibrary.aidl.model.AlbumInfo) ArrayList(java.util.ArrayList) RadioList(com.ximalaya.ting.android.opensdk.model.live.radio.RadioList) List(java.util.List) Radio(com.ximalaya.ting.android.opensdk.model.live.radio.Radio) SongInfo(com.lzx.musiclibrary.aidl.model.SongInfo)

Example 25 with SongInfo

use of com.lzx.musiclibrary.aidl.model.SongInfo in project NiceMusic by lizixian18.

the class QueueManager method updateSongCoverBitmap.

/**
 * 更新音乐艺术家信息
 *
 * @param musicId
 * @param bitmap
 * @param icon
 */
public void updateSongCoverBitmap(String musicId, Bitmap bitmap, Bitmap icon) {
    SongInfo musicInfo = QueueHelper.getMusicInfoById(mPlayingQueue, musicId);
    if (musicInfo == null) {
        return;
    }
    musicInfo.setSongCoverBitmap(bitmap);
    int index = mPlayingQueue.indexOf(musicInfo);
    mPlayingQueue.set(index, musicInfo);
}
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