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;
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations