Search in sources :

Example 6 with SongInfo

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

the class DbManager method queryFavoriteList.

/**
 * 获取我的歌单
 *
 * @return
 */
private List<SongInfo> queryFavoriteList() {
    Uri uri = MusicContentProvider.FAVORITES_URI;
    Cursor cursor = mResolver.query(uri, null, null, null, null);
    if (cursor == null) {
        return new ArrayList<>();
    }
    List<SongInfo> musicInfos = new ArrayList<>();
    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));
        SongInfo info = new SongInfo();
        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);
        musicInfos.add(info);
    }
    cursor.close();
    return musicInfos;
}
Also used : AlbumInfo(com.lzx.musiclibrary.aidl.model.AlbumInfo) ArrayList(java.util.ArrayList) SongInfo(com.lzx.musiclibrary.aidl.model.SongInfo) Cursor(android.database.Cursor) Uri(android.net.Uri)

Example 7 with SongInfo

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

the class DataHelper method getSongInfo.

private static SongInfo getSongInfo(JSONObject billboard, JSONObject object, int i) throws IOException, JSONException {
    SongInfo info = new SongInfo();
    // 音乐id
    info.setSongId(object.getString("song_id"));
    // 音乐标题
    info.setSongName(object.getString("title"));
    // 音乐封面
    info.setSongCover(object.getString("pic_s500"));
    // 音乐播放地址
    info.setSongUrl("");
    if (billboard != null) {
        // 类型(流派)
        info.setGenre(billboard.getString("name"));
        // 类型
        info.setType(billboard.getString("billboard_type"));
    }
    // 音乐大小
    info.setSize("");
    // 音乐长度
    info.setDuration(object.getInt("file_duration") * 1000);
    // 音乐艺术家
    info.setArtist(object.getString("author"));
    // 音乐艺术家id
    info.setArtistId(object.getString("ting_uid"));
    // 音乐下载地址
    info.setDownloadUrl("");
    // 地点
    info.setSite(object.getString("country"));
    // 喜欢数
    info.setFavorites(Integer.parseInt(object.optString("hot", "0")));
    // 播放数
    info.setPlayCount(info.getFavorites() * 2);
    // 媒体的曲目号码(序号:1234567……)
    info.setTrackNumber(i);
    // 语言
    info.setLanguage(object.getString("language"));
    // 地区
    info.setCountry(object.getString("country"));
    // 代理公司
    info.setProxyCompany(object.getString("si_proxycompany"));
    // 发布时间
    info.setPublishTime(object.getString("publishtime"));
    // 音乐描述
    info.setDescription(object.getString("info"));
    // 版本
    info.setVersions(object.getString("versions"));
    AlbumInfo albumInfo = new AlbumInfo();
    // 专辑id
    albumInfo.setAlbumId(object.getString("album_id"));
    // 专辑名称
    albumInfo.setAlbumName(object.getString("album_title"));
    // 专辑封面
    albumInfo.setAlbumCover(object.getString("album_500_500"));
    // 长方形的封面
    albumInfo.setAlbumRectCover(object.getString("pic_huge"));
    // 高清的封面
    albumInfo.setAlbumHDCover(object.getString("pic_premium"));
    // 专辑艺术家
    albumInfo.setArtist(object.optString("artist_name"));
    // 专辑音乐数
    albumInfo.setSongCount(0);
    // 专辑播放数
    albumInfo.setPlayCount(0);
    info.setAlbumInfo(albumInfo);
    return info;
}
Also used : AlbumInfo(com.lzx.musiclibrary.aidl.model.AlbumInfo) SongInfo(com.lzx.musiclibrary.aidl.model.SongInfo)

Example 8 with SongInfo

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

the class DataHelper method fetchJSONFromUrl.

/**
 * 解析json
 *
 * @param responseBody
 * @return
 * @throws IOException
 * @throws JSONException
 */
public static List<SongInfo> fetchJSONFromUrl(ResponseBody responseBody) throws IOException, JSONException {
    List<SongInfo> musicInfos = new ArrayList<>();
    JSONObject jsonObject = new JSONObject(responseBody.string());
    JSONArray array = jsonObject.getJSONArray("song_list");
    JSONObject billboard = jsonObject.optJSONObject("billboard");
    for (int i = 0; i < array.length(); i++) {
        JSONObject object = array.getJSONObject(i);
        SongInfo info = getSongInfo(billboard, 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 9 with SongInfo

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

the class ArtistDetailActivity method init.

@Override
protected void init(Bundle savedInstanceState) {
    mSongInfo = getIntent().getParcelableExtra("songInfo");
    mSongName = findViewById(R.id.song_name);
    mArtistName = findViewById(R.id.artist_name);
    mSongCover = findViewById(R.id.song_cover);
    mArtistCover = findViewById(R.id.artist_cover);
    mArtistDesc = findViewById(R.id.artist_desc);
    mFloatingActionButton = findViewById(R.id.fab);
    mRecyclerView = findViewById(R.id.recycle_view);
    mNestedScrollView = findViewById(R.id.scrollView);
    mCoverLayout = findViewById(R.id.cover_layout);
    mArtistLayout = findViewById(R.id.artist_layout);
    mAppBarLayout = findViewById(R.id.app_bar_layout);
    mTextPeopleNum = findViewById(R.id.text_people_num);
    mTextPlayNum = findViewById(R.id.text_play_num);
    initUI(mSongInfo);
    mAdapter = new ArtistSongAdapter(this);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mRecyclerView.setNestedScrollingEnabled(false);
    mRecyclerView.setAdapter(mAdapter);
    getPresenter().getArtistSongs(mSongInfo.getArtistId());
    getPresenter().getArtistInfo(mSongInfo.getArtistId());
    MusicManager.get().addPlayerEventListener(this);
    mAppBarLayout.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> setViewsTranslation(verticalOffset));
    mFloatingActionButton.setOnClickListener(view -> {
        List<SongInfo> songInfos = mAdapter.getSongInfoList();
        int position = 0;
        if (songInfos.size() > 0 && songInfos.contains(mSongInfo)) {
            position = QueueHelper.getMusicIndexOnQueue(songInfos, mSongInfo.getSongId());
        } else {
            songInfos.add(mSongInfo);
        }
        MusicManager.get().playMusic(songInfos, position);
        PlayingDetailActivity.launch(mContext, songInfos, position);
    });
    mAdapter.setOnItemClickListener((info, position) -> {
        List<SongInfo> songInfos = mAdapter.getSongInfoList();
        if (songInfos.size() > 0) {
            MusicManager.get().playMusic(songInfos, position);
        } else {
            MusicManager.get().playMusicByInfo(info);
        }
    });
    Bundle bundle = new Bundle();
    bundle.putString("name", "大妈的");
    MusicManager.get().updateNotificationContentIntent(bundle, null);
}
Also used : Bundle(android.os.Bundle) ArtistSongAdapter(com.lzx.nicemusic.module.artist.adapter.ArtistSongAdapter) SongInfo(com.lzx.musiclibrary.aidl.model.SongInfo) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SuppressLint(android.annotation.SuppressLint)

Example 10 with SongInfo

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

the class ArtistSongAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ArtistHolder holder, int position) {
    SongInfo info = mSongInfoList.get(position);
    holder.mMusicNum.setText(String.valueOf(position + 1));
    holder.mMusicName.setText(info.getSongName());
    AnimationDrawable animationDrawable = (AnimationDrawable) holder.mImageAnim.getDrawable();
    if (MusicManager.isCurrMusicIsPlayingMusic(info)) {
        holder.mMusicNum.setVisibility(View.GONE);
        holder.mImageAnim.setVisibility(View.VISIBLE);
        if (MusicManager.isPlaying()) {
            animationDrawable.start();
        } else {
            animationDrawable.stop();
        }
    } else {
        animationDrawable.stop();
        holder.mMusicNum.setVisibility(View.VISIBLE);
        holder.mImageAnim.setVisibility(View.GONE);
    }
    holder.itemView.setOnClickListener(view -> {
        if (mOnItemClickListener != null) {
            mOnItemClickListener.onItemClick(info, position);
        }
    });
}
Also used : AnimationDrawable(android.graphics.drawable.AnimationDrawable) 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