public static void ShuffleAll(Context context) { var cursor = SongLoader.CreateSongCursor(context, null, null); var trackList = SongLoader.GetSongListByCursor(cursor); var position = 0; if (trackList.Length == 0 || Service == null) { return; } try { Service.SetShuffleMode(MusicService.SHUFFLE_NORMAL); var mCurrentId = Service.GetAudioId(); var mCurrentQueuePosition = GetQueuePosition(); if (position != -1 && mCurrentQueuePosition == position && mCurrentId == trackList[position]) { var playlist = GetQueue(); if (Equals(trackList, playlist)) { Service.Play(); return; } } Service.Open(trackList, -1, -1, (int)MusicUtils.SourceTypeId.NA); Service.Play(); cursor.Close(); cursor = null; } catch { } }
public static long[] GetSongListByAlbum(Context context, long id) { var projection = new [] { BaseColumns.Id }; string selection = $"{AudioColumns.AlbumId} = {id} AND {AudioColumns.IsMusic} = 1"; var cursor = context.ContentResolver.Query( Media.ExternalContentUri, projection, selection, null, AudioColumns.Track + ", " + Media.DefaultSortOrder); if (cursor != null) { long[] mList = SongLoader.GetSongListByCursor(cursor); cursor.Close(); cursor = null; return(mList); } return(new long[0]); }
public static long[] GetSongListByArtist(Context context, long id) { var projection = new[] { BaseColumns.Id }; var selection = $"{AudioColumns.ArtistId} = {id} AND {AudioColumns.IsMusic} = 1"; var cursor = context.ContentResolver.Query( Media.ExternalContentUri, projection, selection, null, AudioColumns.AlbumKey + "," + AudioColumns.Track); if (cursor != null) { var list = SongLoader.GetSongListByCursor(cursor); cursor.Close(); cursor = null; return(list); } return(new long[0]); }