Beispiel #1
0
 private Album(SongCollection songCollection, string name, Artist artist, Genre genre)
 {
     this.songCollection = songCollection;
     this.album          = name;
     this.artist         = artist;
     this.genre          = genre;
 }
Beispiel #2
0
 private Album(SongCollection songCollection, string name, Artist artist, Genre genre)
 {
     Songs      = songCollection;
     Name       = name;
     Artist     = artist;
     Genre      = genre;
     IsDisposed = false;
 }
        public SongCollection Clone()
        {
            SongCollection sc = new SongCollection();

            foreach (Song song in this.innerlist)
            {
                sc.Add(song);
            }
            return(sc);
        }
Beispiel #4
0
 public static void Play(SongCollection collection, int index = 0)
 {
     MediaPlayer._queue.Clear();
     MediaPlayer._numSongsInQueuePlayed = 0;
     foreach (Song song in collection)
     {
         MediaPlayer._queue.Add(song);
     }
     MediaPlayer._queue.ActiveSongIndex = index;
     MediaPlayer.PlaySong(MediaPlayer._queue.ActiveSong);
 }
Beispiel #5
0
        public static void Play(SongCollection collection, int index = 0)
        {
            _queue.Clear();
            _numSongsInQueuePlayed = 0;

            foreach (var song in collection)
            {
                _queue.Add(song);
            }

            _queue.ActiveSongIndex = index;

            PlaySong(_queue.ActiveSong, null);
        }
Beispiel #6
0
        public static void Play(SongCollection collection, int index = 0)
        {
            Queue.Clear();
            numSongsInQueuePlayed = 0;

            foreach (Song song in collection)
            {
                Queue.Add(song);
            }

            Queue.ActiveSongIndex = index;

            PlaySong(Queue.ActiveSong);
        }
Beispiel #7
0
        public static void Play(SongCollection songs, int index)
        {
            Queue.Clear();
            numSongsInQueuePlayed = 0;

            foreach (Song song in songs)
            {
                LoadSong(song);
            }

            Queue.ActiveSongIndex = index;

            PlaySong(Queue.ActiveSong);
        }
Beispiel #8
0
        public SongCollection Clone()
        {
#if WINDOWS_PHONE
            if (this.songCollection != null)
            {
                throw new NotSupportedException();
            }
#endif
            SongCollection sc = new SongCollection();
            foreach (Song song in this.innerlist)
            {
                sc.Add(song);
            }
            return(sc);
        }
Beispiel #9
0
        //
        // Play (SongCollection)
        //

        public static void Play(SongCollection songs, int index)
        {
            if (songs.Count == 0)
            {
                Queue.Clear();
                Stop();
            }
            else if (songs.Count == 1)
            {
                Play((Song)(object)songs[0]);
            }
            else
            {
                throw new PlatformNotSupportedException();
            }
        }
Beispiel #10
0
        /// <summary>
        /// Shuffles the songs of a local artist and starts playback
        /// </summary>
        /// <param name="localArtistName">Name of the artist</param>
        public void ShuffleAndPlayLocalArtist(string localArtistName)
        {
            Microsoft.Xna.Framework.Media.MediaLibrary lib =
                new Microsoft.Xna.Framework.Media.MediaLibrary();

            for (int i = 0; i < lib.Artists.Count; i++)
            {
                if (localArtistName == lib.Artists[i].Name)
                {
                    // generate a random track index
                    Random rand  = new Random();
                    int    track = rand.Next(0, lib.Artists[i].Songs.Count);

                    Microsoft.Xna.Framework.Media.SongCollection songCollection = lib.Artists[i].Songs;
                    Microsoft.Xna.Framework.Media.MediaPlayer.Play(songCollection, track);
                    Microsoft.Xna.Framework.Media.MediaPlayer.IsShuffled = true;
                    Microsoft.Xna.Framework.FrameworkDispatcher.Update();
                    break;
                }
            }
        }
Beispiel #11
0
        public SongCollection GetSongs()
        {
            IWMPMediaCollection media    = wmp.mediaCollection;
            IWMPPlaylist        playlist = media.getAll();
            List <Song>         songlist = new List <Song>();

            for (int i = 0; i < playlist.count; i++)
            {
                IWMPMedia temp = playlist[i];
                if (temp.getItemInfo("MediaType") == "audio")
                {
                    int  wmprating;
                    int  rating;
                    int  tracknumber;
                    int  playcount;
                    bool IsProtected;
                    if (!int.TryParse(temp.getItemInfo("UserRating"), out wmprating))
                    {
                        throw new Exception();
                    }
                    if (wmprating >= 87)
                    {
                        rating = 10;
                    }
                    else if (wmprating >= 63)
                    {
                        rating = 8;
                    }
                    else if (wmprating >= 38)
                    {
                        rating = 6;
                    }
                    else if (wmprating >= 13)
                    {
                        rating = 4;
                    }
                    else if (wmprating >= 1)
                    {
                        rating = 2;
                    }
                    else
                    {
                        rating = 0;
                    }
                    if (!int.TryParse(temp.getItemInfo("WM/TrackNumber"), out tracknumber))
                    {
                        tracknumber = 0;
                    }
                    if (!int.TryParse(temp.getItemInfo("PlayCount"), out playcount))
                    {
                        throw new Exception();
                    }
                    if (!bool.TryParse(temp.getItemInfo("Is_Protected"), out IsProtected))
                    {
                        throw new Exception();
                    }
                    TimeSpan duration = new TimeSpan(0, 0, 0, 0, (int)(temp.duration * 1000.0));
                    songlist.Add(new Song(temp.name, duration, rating, tracknumber, temp, mediasource));
                }
            }
            SongCollection songs = new SongCollection(songlist);

            return(songs);
        }
Beispiel #12
0
 public static void Play(SongCollection songs)
 {
     Play(songs, 0);
 }
Beispiel #13
0
        private void PlatformLoad(Action <int> progressCallback)
        {
            List <StorageFile> files = new List <StorageFile>();

            this.GetAllFiles(musicFolder, files);

            List <Song>  songList  = new List <Song>();
            List <Album> albumList = new List <Album>();

            Task.Run(async() =>
            {
                Dictionary <string, Artist> artists = new Dictionary <string, Artist>();
                Dictionary <string, Album> albums   = new Dictionary <string, Album>();
                Dictionary <string, Genre> genres   = new Dictionary <string, Genre>();

                var cacheFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("MediaLibrary.cache", CreationCollisionOption.OpenIfExists);
                var cache     = new Dictionary <string, MusicProperties>();

                // Read cache
                using (var stream = new BinaryReader(await cacheFile.OpenStreamForReadAsync()))
                    try
                    {
                        for (; stream.BaseStream.Position < stream.BaseStream.Length;)
                        {
                            var entry = MusicProperties.Deserialize(stream);
                            cache.Add(entry.Path, entry);
                        }
                    }
                    catch { }

                // Write cache
                using (var stream = new BinaryWriter(await cacheFile.OpenStreamForWriteAsync()))
                {
                    int prevProgress = 0;

                    for (int i = 0; i < files.Count; i++)
                    {
                        var file = files[i];
                        try
                        {
                            MusicProperties properties;
                            if (!(cache.TryGetValue(file.Path, out properties) && properties.TryMatch(file)))
                            {
                                properties = new MusicProperties(file);
                            }
                            properties.Serialize(stream);

                            if (string.IsNullOrWhiteSpace(properties.Title))
                            {
                                continue;
                            }

                            Artist artist;
                            if (!artists.TryGetValue(properties.Artist, out artist))
                            {
                                artist = new Artist(properties.Artist);
                                artists.Add(artist.Name, artist);
                            }

                            Artist albumArtist;
                            if (!artists.TryGetValue(properties.AlbumArtist, out albumArtist))
                            {
                                albumArtist = new Artist(properties.AlbumArtist);
                                artists.Add(albumArtist.Name, albumArtist);
                            }

                            Genre genre;
                            if (!genres.TryGetValue(properties.Genre, out genre))
                            {
                                genre = new Genre(properties.Genre);
                                genres.Add(genre.Name, genre);
                            }

                            Album album;
                            if (!albums.TryGetValue(properties.Album, out album))
                            {
                                var thumbnail = Task.Run(async() => await properties.File.GetThumbnailAsync(ThumbnailMode.MusicView, 300, ThumbnailOptions.ResizeThumbnail)).Result;
                                album         = new Album(new SongCollection(), properties.Album, albumArtist, genre, thumbnail.Type == ThumbnailType.Image ? thumbnail : null);
                                albums.Add(album.Name, album);
                                albumList.Add(album);
                            }

                            var song = new Song(album, artist, genre, properties);
                            song.Album.Songs.Add(song);
                            songList.Add(song);
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine("MediaLibrary exception: " + e.Message);
                        }

                        int progress = 100 * i / files.Count;
                        if (progress > prevProgress)
                        {
                            prevProgress = progress;
                            if (progressCallback != null)
                            {
                                progressCallback.Invoke(progress);
                            }
                        }
                    }
                }
            }).Wait();

            if (progressCallback != null)
            {
                progressCallback.Invoke(100);
            }

            albumCollection = new AlbumCollection(albumList);
            songCollection  = new SongCollection(songList);
        }
Beispiel #14
0
        private void PlatformLoad(Action <int> progressCallback)
        {
            List <Song>  songList  = new List <Song>();
            List <Album> albumList = new List <Album>();

            using (var musicCursor = Context.ContentResolver.Query(MediaStore.Audio.Media.ExternalContentUri, null, null, null, null))
            {
                if (musicCursor != null && musicCursor.MoveToFirst())
                {
                    Dictionary <string, Artist> artists = new Dictionary <string, Artist>();
                    Dictionary <string, Album>  albums  = new Dictionary <string, Album>();
                    Dictionary <string, Genre>  genres  = new Dictionary <string, Genre>();

                    // Note: Grabbing album art using MediaStore.Audio.AlbumColumns.AlbumArt and
                    // MediaStore.Audio.AudioColumns.AlbumArt is broken
                    // See: https://code.google.com/p/android/issues/detail?id=1630
                    // Workaround: http://stackoverflow.com/questions/1954434/cover-art-on-android

                    int albumNameColumn   = musicCursor.GetColumnIndex(MediaStore.Audio.AlbumColumns.Album);
                    int albumArtistColumn = musicCursor.GetColumnIndex(MediaStore.Audio.AlbumColumns.Artist);
                    int albumIdColumn     = musicCursor.GetColumnIndex(MediaStore.Audio.AlbumColumns.AlbumId);
                    int genreColumn       = musicCursor.GetColumnIndex(MediaStore.Audio.GenresColumns.Name); // Also broken :(

                    int artistColumn   = musicCursor.GetColumnIndex(MediaStore.Audio.AudioColumns.Artist);
                    int titleColumn    = musicCursor.GetColumnIndex(MediaStore.Audio.AudioColumns.Title);
                    int durationColumn = musicCursor.GetColumnIndex(MediaStore.Audio.AudioColumns.Duration);
                    int assetIdColumn  = musicCursor.GetColumnIndex(MediaStore.Audio.AudioColumns.Id);

                    if (titleColumn == -1 || durationColumn == -1 || assetIdColumn == -1)
                    {
                        Debug.WriteLine("Missing essential properties from music library. Returning empty library.");
                        albumCollection = new AlbumCollection(albumList);
                        songCollection  = new SongCollection(songList);
                        return;
                    }

                    do
                    {
                        long     durationProperty = musicCursor.GetLong(durationColumn);
                        TimeSpan duration         = TimeSpan.FromMilliseconds(durationProperty);

                        // Exclude sound effects
                        if (duration < MinimumSongDuration)
                        {
                            continue;
                        }

                        string albumNameProperty   = albumNameColumn > -1 ? musicCursor.GetString(albumNameColumn) : "Unknown Album";
                        string albumArtistProperty = albumArtistColumn > -1 ? musicCursor.GetString(albumArtistColumn) : "Unknown Artist";
                        string genreProperty       = genreColumn > -1 ? musicCursor.GetString(genreColumn) : "Unknown Genre";
                        string artistProperty      = artistColumn > -1 ? musicCursor.GetString(artistColumn) : "Unknown Artist";
                        string titleProperty       = musicCursor.GetString(titleColumn);

                        long assetId     = musicCursor.GetLong(assetIdColumn);
                        var  assetUri    = ContentUris.WithAppendedId(MediaStore.Audio.Media.ExternalContentUri, assetId);
                        long albumId     = albumIdColumn > -1 ? musicCursor.GetInt(albumIdColumn) : -1;
                        var  albumArtUri = albumId > -1 ? ContentUris.WithAppendedId(Uri.Parse("content://media/external/audio/albumart"), albumId) : null;

                        Artist artist;
                        if (!artists.TryGetValue(artistProperty, out artist))
                        {
                            artist = new Artist(artistProperty);
                            artists.Add(artist.Name, artist);
                        }

                        Artist albumArtist;
                        if (!artists.TryGetValue(albumArtistProperty, out albumArtist))
                        {
                            albumArtist = new Artist(albumArtistProperty);
                            artists.Add(albumArtist.Name, albumArtist);
                        }

                        Genre genre;
                        if (!genres.TryGetValue(genreProperty, out genre))
                        {
                            genre = new Genre(genreProperty);
                            genres.Add(genre.Name, genre);
                        }

                        Album album;
                        if (!albums.TryGetValue(albumNameProperty, out album))
                        {
                            album = new Album(new SongCollection(), albumNameProperty, albumArtist, genre, albumArtUri);
                            albums.Add(album.Name, album);
                            albumList.Add(album);
                        }

                        var song = new Song(album, artist, genre, titleProperty, duration, assetUri);
                        song.Album.Songs.Add(song);
                        songList.Add(song);
                    } while (musicCursor.MoveToNext());
                }
            }

            albumCollection = new AlbumCollection(albumList);
            songCollection  = new SongCollection(songList);
        }
Beispiel #15
0
 public static void Play(SongCollection songs, int index)
 {
     throw new NotImplementedException();
 }
Beispiel #16
0
        private void PlatformLoad(Action <int> progressCallback)
        {
            MPMediaQuery mediaQuery = new MPMediaQuery();
            var          value      = NSObject.FromObject(MPMediaType.Music);
            var          type       = MPMediaItem.MediaTypeProperty;
            var          predicate  = MPMediaPropertyPredicate.PredicateWithValue(value, type);

            mediaQuery.AddFilterPredicate(predicate);
            mediaQuery.GroupingType = MPMediaGrouping.Album;

            List <Song>  songList  = new List <Song>();
            List <Album> albumList = new List <Album>();

            for (int i = 0; i < mediaQuery.Collections.Length; i++)
            {
                MPMediaItemCollection itemCollection = mediaQuery.Collections[i];
                List <Song>           albumSongs     = new List <Song>(itemCollection.Count);

                var                nsAlbumArtist = itemCollection.RepresentativeItem.ValueForProperty(MPMediaItem.AlbumArtistProperty);
                var                nsAlbumName   = itemCollection.RepresentativeItem.ValueForProperty(MPMediaItem.AlbumTitleProperty);
                var                nsAlbumGenre  = itemCollection.RepresentativeItem.ValueForProperty(MPMediaItem.GenreProperty);
                string             albumArtist   = nsAlbumArtist == null ? "Unknown Artist" : nsAlbumArtist.ToString();
                string             albumName     = nsAlbumName == null ? "Unknown Album" : nsAlbumName.ToString();
                string             albumGenre    = nsAlbumGenre == null ? "Unknown Genre" : nsAlbumGenre.ToString();
                MPMediaItemArtwork thumbnail     = itemCollection.RepresentativeItem.ValueForProperty(MPMediaItem.ArtworkProperty) as MPMediaItemArtwork;

                var album = new Album(new SongCollection(albumSongs), albumName, new Artist(albumArtist), new Genre(albumGenre), thumbnail);
                albumList.Add(album);

                for (int j = 0; j < itemCollection.Count; j++)
                {
                    var nsArtist = itemCollection.Items[j].ValueForProperty(MPMediaItem.ArtistProperty);
                    var nsTitle  = itemCollection.Items[j].ValueForProperty(MPMediaItem.TitleProperty);
                    var nsGenre  = itemCollection.Items[j].ValueForProperty(MPMediaItem.GenreProperty);
                    var assetUrl = itemCollection.Items[j].ValueForProperty(MPMediaItem.AssetURLProperty) as NSUrl;

                    if (nsTitle == null || assetUrl == null) // The Asset URL check will exclude iTunes match items from the Media Library that are not downloaded, but show up in the music app
                    {
                        continue;
                    }

                    string   artist   = nsArtist == null ? "Unknown Artist" : nsArtist.ToString();
                    string   title    = nsTitle.ToString();
                    string   genre    = nsGenre == null ? "Unknown Genre" : nsGenre.ToString();
                    TimeSpan duration = TimeSpan.FromSeconds(((NSNumber)itemCollection.Items[j].ValueForProperty(MPMediaItem.PlaybackDurationProperty)).FloatValue);

                    var song = new Song(album, new Artist(artist), new Genre(genre), title, duration, itemCollection.Items[j], assetUrl);
                    albumSongs.Add(song);
                    songList.Add(song);
                }
            }

            albumCollection = new AlbumCollection(albumList);
            songCollection  = new SongCollection(songList);

            /*_playLists = new PlaylistCollection();
             *
             *          MPMediaQuery playlists = new MPMediaQuery();
             *          playlists.GroupingType = MPMediaGrouping.Playlist;
             * for (int i = 0; i < playlists.Collections.Length; i++)
             * {
             *  MPMediaItemCollection item = playlists.Collections[i];
             *  Playlist list = new Playlist();
             *  list.Name = playlists.Items[i].ValueForProperty(MPMediaPlaylistPropertyName).ToString();
             *  for (int k = 0; k < item.Items.Length; k++)
             *  {
             *      TimeSpan time = TimeSpan.Parse(item.Items[k].ValueForProperty(MPMediaItem.PlaybackDurationProperty).ToString());
             *      list.Duration += time;
             *  }
             *  _playLists.Add(list);
             * }*/
        }
Beispiel #17
0
 internal Album(SongCollection songCollection, string name, Artist artist, Genre genre, StorageItemThumbnail thumbnail)
     : this(songCollection, name, artist, genre)
 {
     this.thumbnail = thumbnail;
 }
Beispiel #18
0
 internal Album(SongCollection songCollection, string name, Artist artist, Genre genre, Android.Net.Uri thumbnail)
     : this(songCollection, name, artist, genre)
 {
     this.thumbnail = thumbnail;
 }
Beispiel #19
0
 internal Album(SongCollection songCollection, string name, Artist artist, Genre genre, MPMediaItemArtwork thumbnail)
     : this(songCollection, name, artist, genre)
 {
     this.thumbnail = thumbnail;
 }