Search in sources :

Example 21 with MusicInfo

use of com.wm.remusic.info.MusicInfo in project remusic by aa112901.

the class MusicUtils method getMusicLists.

public static ArrayList<MusicInfo> getMusicLists(Context context, long[] id) {
    final StringBuilder selection = new StringBuilder();
    selection.append(MediaStore.Audio.Media._ID + " IN (");
    for (int i = 0; i < id.length; i++) {
        selection.append(id[i]);
        if (i < id.length - 1) {
            selection.append(",");
        }
    }
    selection.append(")");
    //sqlite 不支持decode
    //        final StringBuilder order = new StringBuilder();
    //        order.append("DECODE(" +MediaStore.Audio.Media._ID +",");
    //        for (int i = 0; i < id.length; i++) {
    //            order.append(id[i]);
    //            order.append(",");
    //            order.append(i);
    //            if (i < id.length - 1) {
    //                order.append(",");
    //            }
    //        }
    //        order.append(")");
    Cursor cursor = (context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, proj_music, selection.toString(), null, null));
    if (cursor == null) {
        return null;
    }
    ArrayList<MusicInfo> musicList = new ArrayList<>();
    musicList.ensureCapacity(id.length);
    for (int i = 0; i < id.length; i++) {
        musicList.add(null);
    }
    while (cursor.moveToNext()) {
        MusicInfo music = new MusicInfo();
        music.songId = cursor.getInt(cursor.getColumnIndex(Media._ID));
        music.albumId = cursor.getInt(cursor.getColumnIndex(Media.ALBUM_ID));
        music.albumName = cursor.getString(cursor.getColumnIndex(Albums.ALBUM));
        music.albumData = getAlbumArtUri(music.albumId) + "";
        music.musicName = cursor.getString(cursor.getColumnIndex(Media.TITLE));
        music.artist = cursor.getString(cursor.getColumnIndex(Media.ARTIST));
        music.artistId = cursor.getLong(cursor.getColumnIndex(Media.ARTIST_ID));
        music.islocal = true;
        for (int i = 0; i < id.length; i++) {
            if (id[i] == music.songId) {
                musicList.set(i, music);
            }
        }
    }
    cursor.close();
    return musicList;
}
Also used : ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) MusicInfo(com.wm.remusic.info.MusicInfo)

Example 22 with MusicInfo

use of com.wm.remusic.info.MusicInfo in project remusic by aa112901.

the class MusicUtils method getMusicListCursor.

public static ArrayList<MusicInfo> getMusicListCursor(Cursor cursor) {
    if (cursor == null) {
        return null;
    }
    ArrayList<MusicInfo> musicList = new ArrayList<>();
    while (cursor.moveToNext()) {
        MusicInfo music = new MusicInfo();
        music.songId = cursor.getInt(cursor.getColumnIndex(Media._ID));
        music.albumId = cursor.getInt(cursor.getColumnIndex(Media.ALBUM_ID));
        music.albumName = cursor.getString(cursor.getColumnIndex(Albums.ALBUM));
        music.albumData = getAlbumArtUri(music.albumId) + "";
        music.duration = cursor.getInt(cursor.getColumnIndex(Media.DURATION));
        music.musicName = cursor.getString(cursor.getColumnIndex(Media.TITLE));
        music.artist = cursor.getString(cursor.getColumnIndex(Media.ARTIST));
        music.artistId = cursor.getLong(cursor.getColumnIndex(Media.ARTIST_ID));
        String filePath = cursor.getString(cursor.getColumnIndex(Media.DATA));
        music.data = filePath;
        music.folder = filePath.substring(0, filePath.lastIndexOf(File.separator));
        music.size = cursor.getInt(cursor.getColumnIndex(Media.SIZE));
        music.islocal = true;
        music.sort = Pinyin.toPinyin(music.musicName.charAt(0)).substring(0, 1).toUpperCase();
        musicList.add(music);
    }
    cursor.close();
    return musicList;
}
Also used : ArrayList(java.util.ArrayList) MusicInfo(com.wm.remusic.info.MusicInfo)

Example 23 with MusicInfo

use of com.wm.remusic.info.MusicInfo in project remusic by aa112901.

the class MusicUtils method getMusicInfo.

public static MusicInfo getMusicInfo(Context context, long id) {
    ContentResolver cr = context.getContentResolver();
    Cursor cursor = cr.query(Media.EXTERNAL_CONTENT_URI, proj_music, "_id = " + String.valueOf(id), null, null);
    if (cursor == null) {
        return null;
    }
    MusicInfo music = new MusicInfo();
    while (cursor.moveToNext()) {
        music.songId = cursor.getInt(cursor.getColumnIndex(Media._ID));
        music.albumId = cursor.getInt(cursor.getColumnIndex(Media.ALBUM_ID));
        music.albumName = cursor.getString(cursor.getColumnIndex(Albums.ALBUM));
        music.albumData = getAlbumArtUri(music.albumId) + "";
        music.duration = cursor.getInt(cursor.getColumnIndex(Media.DURATION));
        music.musicName = cursor.getString(cursor.getColumnIndex(Media.TITLE));
        music.size = cursor.getInt(cursor.getColumnIndex(Media.SIZE));
        music.artist = cursor.getString(cursor.getColumnIndex(Media.ARTIST));
        music.artistId = cursor.getLong(cursor.getColumnIndex(Media.ARTIST_ID));
        String filePath = cursor.getString(cursor.getColumnIndex(Media.DATA));
        music.data = filePath;
        String folderPath = filePath.substring(0, filePath.lastIndexOf(File.separator));
        music.folder = folderPath;
        music.sort = Pinyin.toPinyin(music.musicName.charAt(0)).substring(0, 1).toUpperCase();
    }
    cursor.close();
    return music;
}
Also used : Cursor(android.database.Cursor) MusicInfo(com.wm.remusic.info.MusicInfo) ContentResolver(android.content.ContentResolver)

Example 24 with MusicInfo

use of com.wm.remusic.info.MusicInfo in project remusic by aa112901.

the class MediaService method getLrc.

private void getLrc(long id) {
    MusicInfo info = mPlaylistInfo.get(id);
    if (info == null) {
        L.D(D, TAG, "get lrc err ,musicinfo is null");
    }
    String lrc = Environment.getExternalStorageDirectory().getAbsolutePath() + LRC_PATH;
    File file = new File(lrc);
    L.D(D, TAG, "file exists = " + file.exists());
    if (!file.exists()) {
        //不存在就建立此目录
        boolean r = file.mkdirs();
        L.D(D, TAG, "file created = " + r);
    }
    file = new File(lrc + id);
    if (!file.exists()) {
        if (mRequestLrc != null) {
            mRequestLrc.stop();
            mLrcHandler.removeCallbacks(mRequestLrc);
        }
        mRequestLrc = new RequestLrc(mPlaylistInfo.get(id));
        mLrcHandler.postDelayed(mRequestLrc, 70);
    }
}
Also used : MusicInfo(com.wm.remusic.info.MusicInfo) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 25 with MusicInfo

use of com.wm.remusic.info.MusicInfo in project remusic by aa112901.

the class QueueLoader method getQueueSongs.

public static ArrayList<MusicInfo> getQueueSongs(Context context) {
    final ArrayList<MusicInfo> mMusicQueues = new ArrayList<>();
    Log.e("queueloader", "created");
    mCursor = new PlayQueueCursor(context);
    while (mCursor.moveToNext()) {
        MusicInfo music = new MusicInfo();
        music.songId = mCursor.getInt(0);
        music.albumName = mCursor.getString(4);
        music.musicName = mCursor.getString(1);
        music.artist = mCursor.getString(2);
        mMusicQueues.add(music);
    }
    if (mCursor != null) {
        mCursor.close();
        mCursor = null;
    }
    return mMusicQueues;
}
Also used : ArrayList(java.util.ArrayList) MusicInfo(com.wm.remusic.info.MusicInfo)

Aggregations

MusicInfo (com.wm.remusic.info.MusicInfo)25 Intent (android.content.Intent)10 ArrayList (java.util.ArrayList)9 View (android.view.View)7 TextView (android.widget.TextView)7 Uri (android.net.Uri)6 RecyclerView (android.support.v7.widget.RecyclerView)6 DialogInterface (android.content.DialogInterface)5 AsyncTask (android.os.AsyncTask)5 HashMap (java.util.HashMap)5 AlertDialog (android.support.v7.app.AlertDialog)4 MusicFlowAdapter (com.wm.remusic.adapter.MusicFlowAdapter)4 Cursor (android.database.Cursor)3 ImageView (android.widget.ImageView)3 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 ContentResolver (android.content.ContentResolver)2 Handler (android.os.Handler)2 LinearLayout (android.widget.LinearLayout)2 SimpleDraweeView (com.facebook.drawee.view.SimpleDraweeView)2