Ejemplo n.º 1
0
 public async Task <IEnumerable <Song> > GetSongsAsync(SongSortOrder sortOrder = SongSortOrder.Default)
 {
     return(await Task.Run(() =>
     {
         var mediaQuery = PrepareMediaQuery();
         return mediaQuery.ToSongs(sortOrder);
     }));
 }
 public async Task <IEnumerable <Song> > GetSongsAsync(SongSortOrder sortOrder = SongSortOrder.Default)
 {
     return(await LoadSongsAsync(
                selection : null,
                selectionArgs : null,
                sortOrder : sortOrder
                ));
 }
 internal static IEnumerable <Song> ToSongs(this MPMediaQuery mediaQuery, SongSortOrder sortOrder)
 {
     foreach (var mediaItem in mediaQuery.Items)
     {
         if (mediaItem != null && mediaItem.AssetURL != null)
         {
             yield return(mediaItem.ToSong());
         }
     }
 }
        public async Task <IEnumerable <Song> > SearchSongsAsync(string searchTerm, SongSortOrder sortOrder = SongSortOrder.Default)
        {
            if (string.IsNullOrWhiteSpace(searchTerm))
            {
                throw new ArgumentNullException(nameof(searchTerm));
            }

            return(await LoadSongsAsync(
                       selection : MediaStore.Audio.Media.InterfaceConsts.Title + " like ?",
                       selectionArgs : new[] { searchTerm + "%" },
                       sortOrder : sortOrder
                       ));
        }
 internal static string ToStringSortOrder(this SongSortOrder sortOrder)
 {
     return(sortOrder switch
     {
         SongSortOrder.AlphabeticAlbum => MediaStore.Audio.Media.InterfaceConsts.AlbumKey,
         SongSortOrder.AlphabeticComposer => MediaStore.Audio.Media.InterfaceConsts.Composer + ASC,
         SongSortOrder.DisplayName => MediaStore.Audio.Media.InterfaceConsts.DisplayName,
         SongSortOrder.GreaterDuration => MediaStore.Audio.Media.InterfaceConsts.Duration + DESC,
         SongSortOrder.SmallerDuration => MediaStore.Audio.Media.InterfaceConsts.Duration + ASC,
         SongSortOrder.GreaterTrackNumber => MediaStore.Audio.Media.InterfaceConsts.Track + DESC,
         SongSortOrder.SmallerTrackNumber => MediaStore.Audio.Media.InterfaceConsts.Track + ASC,
         SongSortOrder.OldestYear => MediaStore.Audio.Media.InterfaceConsts.Year + DESC,
         SongSortOrder.RecentYear => MediaStore.Audio.Media.InterfaceConsts.Year + ASC,
         _ => MediaStore.Audio.Media.DefaultSortOrder
     });
Ejemplo n.º 6
0
        public async Task <IEnumerable <Song> > SearchSongsAsync(string searchTerm, SongSortOrder sortOrder = SongSortOrder.Default)
        {
            if (string.IsNullOrWhiteSpace(searchTerm))
            {
                throw new ArgumentNullException(nameof(searchTerm));
            }

            return(await Task.Run(() =>
            {
                var mediaQuery = PrepareMediaQuery();
                var value = NSObject.FromObject(searchTerm);
                var searchTermPredicate = MPMediaPropertyPredicate.PredicateWithValue(value, MPMediaItem.TitleProperty, MPMediaPredicateComparison.Contains);
                mediaQuery.AddFilterPredicate(searchTermPredicate);
                return mediaQuery.ToSongs(sortOrder);
            }));
        }
Ejemplo n.º 7
0
        public async Task <IEnumerable <Song> > GetSongsFromPlaylistAsync(Playlist playlist, SongSortOrder sortOrder = SongSortOrder.Default)
        {
            if (playlist == null)
            {
                throw new ArgumentNullException(nameof(playlist));
            }

            return(await GetSongsByIdAsync(playlist.MemberIds, sortOrder));
        }
Ejemplo n.º 8
0
        public async Task <IEnumerable <Song> > GetSongsFromGenreAsync(string genreId, SongSortOrder sortOrder = SongSortOrder.Default)
        {
            if (string.IsNullOrWhiteSpace(genreId))
            {
                throw new ArgumentNullException(nameof(genreId));
            }

            return(await Task.Run(() =>
            {
                var mediaQuery = PrepareMediaQuery();
                var value = NSObject.FromObject(genreId);
                var genreIdPredicate = MPMediaPropertyPredicate.PredicateWithValue(value, MPMediaItem.GenrePersistentIDProperty);
                mediaQuery.AddFilterPredicate(genreIdPredicate);
                return mediaQuery.ToSongs(sortOrder);
            }));
        }
Ejemplo n.º 9
0
        public async Task <IEnumerable <Song> > GetSongsByIdAsync(IEnumerable <string> songIds, SongSortOrder sortOrder = SongSortOrder.Default)
        {
            if (!songIds.HasValue())
            {
                throw new ArgumentException(nameof(songIds));
            }

            return(await Task.Run(() =>
            {
                var mediaQuery = PrepareMediaQuery();
                var value = NSArray.FromNSObjects(songIds.Select(s => NSObject.FromObject(s)).ToArray());
                var arrayPredictor = MPMediaPropertyPredicate.PredicateWithValue(value, MPMediaItem.PersistentIDProperty, MPMediaPredicateComparison.Contains);
                mediaQuery.AddFilterPredicate(arrayPredictor);
                return mediaQuery.ToSongs(sortOrder);
            }));
        }
Ejemplo n.º 10
0
 private SongListVM GetUnselectedSongList(SongSortOrder sortOrder)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 11
0
 public SongListVM GetSongList(SongSortOrder sortOrder, bool isSelected)
 {
     throw new NotImplementedException();
 }
        public async Task <IEnumerable <Song> > GetSongsFromGenreAsync(string genreId, SongSortOrder sortOrder = SongSortOrder.Default)
        {
            if (string.IsNullOrWhiteSpace(genreId))
            {
                throw new ArgumentNullException(nameof(genreId));
            }

            return(await LoadSongsAsync(
                       selection : null,
                       selectionArgs : null,
                       sortOrder : sortOrder
                       ));
        }
        public async Task <IEnumerable <Song> > GetSongsFromArtistAsync(string artistId, SongSortOrder sortOrder = SongSortOrder.Default)
        {
            if (string.IsNullOrWhiteSpace(artistId))
            {
                throw new ArgumentNullException(nameof(artistId));
            }

            return(await LoadSongsAsync(
                       selection : MediaStore.Audio.Media.InterfaceConsts.ArtistId + " =?",
                       selectionArgs : new[] { artistId },
                       sortOrder : sortOrder
                       ));
        }
        public async Task <IEnumerable <Song> > GetSongsByIdAsync(IEnumerable <string> songIds, SongSortOrder sortOrder = SongSortOrder.Default)
        {
            if (!songIds.HasValue())
            {
                throw new ArgumentException(nameof(songIds));
            }

            var selectionBuilder = new StringBuilder();

            selectionBuilder.Append(MediaStore.Audio.Media.InterfaceConsts.Id + " IN (");
            selectionBuilder.Append(string.Join(",", songIds));
            selectionBuilder.Append(")");

            return(await LoadSongsAsync(
                       selection : selectionBuilder.ToString(),
                       selectionArgs : null,
                       sortOrder : sortOrder
                       ));
        }
 private async Task <IEnumerable <Song> > LoadSongsAsync(string selection, string[] selectionArgs, SongSortOrder sortOrder)
 {
     return(await Task.Run(() =>
     {
         var cursor = Android.App.Application.Context.ContentResolver.Query(
             uri: MediaStore.Audio.Media.ExternalContentUri,
             projection: _projections,
             selection: selection,
             selectionArgs: selectionArgs,
             sortOrder: sortOrder.ToStringSortOrder()
             );
         return cursor.ToSongs();
     }));
 }