Beispiel #1
0
 internal Song(Album album, Artist artist, Genre genre, MusicProperties musicProperties)
 {
     this.album           = album;
     this.artist          = artist;
     this.genre           = genre;
     this.musicProperties = musicProperties;
 }
Beispiel #2
0
		internal Song(Album album, Artist artist, Genre genre, MusicProperties musicProperties)
		{
            this.album = album;
            this.artist = artist;
            this.genre = genre;
            this.musicProperties = musicProperties;
		}
Beispiel #3
0
        public static MusicProperties Deserialize(BinaryReader stream)
        {
            var instance = new MusicProperties();
            instance.Path = stream.ReadString();
            instance.DateCreated = new DateTimeOffset(stream.ReadInt64(), new TimeSpan(stream.ReadInt64()));

            instance.Album = stream.ReadString();
            instance.AlbumArtist = stream.ReadString();
            instance.Artist = stream.ReadString();
            instance.Duration = new TimeSpan(stream.ReadInt64());
            instance.Genre = stream.ReadString();
            instance.IsProtected = stream.ReadBoolean();
            instance.Rating = stream.ReadInt32();
            instance.Title = stream.ReadString();
            instance.TrackNumber = stream.ReadInt32();

            return instance;
        }
        public static MusicProperties Deserialize(BinaryReader stream)
        {
            var instance = new MusicProperties();

            instance.Path        = stream.ReadString();
            instance.DateCreated = new DateTimeOffset(stream.ReadInt64(), new TimeSpan(stream.ReadInt64()));

            instance.Album       = stream.ReadString();
            instance.AlbumArtist = stream.ReadString();
            instance.Artist      = stream.ReadString();
            instance.Duration    = new TimeSpan(stream.ReadInt64());
            instance.Genre       = stream.ReadString();
            instance.IsProtected = stream.ReadBoolean();
            instance.Rating      = stream.ReadInt32();
            instance.Title       = stream.ReadString();
            instance.TrackNumber = stream.ReadInt32();

            return(instance);
        }
Beispiel #5
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 #6
0
		internal Song(Album album, Artist artist, Genre genre, MusicProperties musicProperties)
			: this(album, artist, genre)
		{
			this.musicProperties = musicProperties;
		}
Beispiel #7
0
 internal Song(Album album, Artist artist, Genre genre, MusicProperties musicProperties)
     : this(album, artist, genre)
 {
     this.musicProperties = musicProperties;
 }