public async Task <MusicMetadata> CreateMusicMetadata(MusicProperties properties, CancellationToken cancellationToken)
        {
            var propertiesToRetrieve = new List <string>();

            AddPropertiesToRetrieve(propertiesToRetrieve);
            var customProperties = await properties.RetrievePropertiesAsync(propertiesToRetrieve).AsTask(cancellationToken).ConfigureAwait(false);

            TimeSpan duration = ReadDuration(properties, customProperties);
            uint     bitrate  = ReadBitrate(properties, customProperties);

            if (!IsSupported || (duration == TimeSpan.Zero && bitrate == 0))
            {
                return(MusicMetadata.CreateUnsupported(duration, bitrate));
            }

            return(new MusicMetadata(duration, bitrate)
            {
                Title = ReadTitle(properties, customProperties),
                Artists = ToSaveArray(ReadArtists(properties, customProperties)),
                Rating = ReadRating(properties, customProperties),
                Album = ReadAlbum(properties, customProperties),
                TrackNumber = ReadTrackNumber(properties, customProperties),
                Year = ReadYear(properties, customProperties),
                Genre = ToSaveArray(ReadGenre(properties, customProperties)),
                AlbumArtist = ReadAlbumArtist(properties, customProperties),
                Publisher = ReadPublisher(properties, customProperties),
                Subtitle = ReadSubtitle(properties, customProperties),
                Composers = ToSaveArray(ReadComposers(properties, customProperties)),
                Conductors = ToSaveArray(ReadConductors(properties, customProperties))
            });
        }
Exemplo n.º 2
0
        private async void Rename(Tag mytag)
        {
            CurrentSong = SongList.SelectedItem as Song;

            using (SQLiteConnection db = new SQLiteConnection(App.DB_PATH))
            {
                string import_name;
                var    temp_format_id = db.Find <MusicFormat>(c => c.Id == CurrentSong.FormatId);
                import_name = CurrentSong.Path + CurrentSong.NameSong + "." + temp_format_id.NameFormat;

                Main_folder = await Windows.Storage.AccessCache.StorageApplicationPermissions
                              .FutureAccessList.GetFolderAsync("Audio");

                StorageFile music_files = await Main_folder.GetFileAsync(import_name);

                var fileProperties = await music_files.Properties.GetMusicPropertiesAsync();

                //*Нормально не изменяет артиста
                StorageItemContentProperties rfileProperties = music_files.Properties;
                MusicProperties musicFileProperties          = await rfileProperties.GetMusicPropertiesAsync();

                string[] contributingArtistsKey = { "System.Music.Artist" };
                IDictionary <string, object> contributingArtistsProperty =
                    await musicFileProperties.RetrievePropertiesAsync(contributingArtistsKey);

                string[] contributingArtists = contributingArtistsProperty["System.Music.Artist"] as string[];

                //fileProperties.Genre = mytag.Genge; \\только для чтения
                fileProperties.TrackNumber = Convert.ToUInt32(mytag.TrackNumber);
                fileProperties.Album       = mytag.Albom;
                fileProperties.Artist      = mytag.Artist;
                //fileProperties.Composers = mytag.Composer; \\только для чтения
                fileProperties.Title       = mytag.NameSong;
                fileProperties.Year        = Convert.ToUInt32(mytag.Year);
                fileProperties.AlbumArtist = mytag.ArtistAlbom;
                //*Ошибка доступа для Флер
                await fileProperties.SavePropertiesAsync();

                var temp_song = db.Find <Song>(c => c.TagId == mytag.Id);
                await Task.Run(() =>
                {
                    temp_song.DateChange = DateTime.Now.AddHours(5);
                    Db_Helper.Update_Song(temp_song);
                });
            }
            var dialog = new MessageDialog("Тег изменен");
            await dialog.ShowAsync();
        }
Exemplo n.º 3
0
        //Recursive function for scanning all sub folders, also prepares search index for songs.
        public async Task LoadFromFolder(StorageFolder storageFolder)
        {
            IReadOnlyList <StorageFile> fileList = await storageFolder.GetFilesAsync();

            const ThumbnailMode thumbnailMode = ThumbnailMode.MusicView;

            foreach (StorageFile f in fileList)
            {
                if (musicFormat.FindIndex(x => x.Equals(f.FileType, StringComparison.OrdinalIgnoreCase)) != -1)
                {
                    const uint size = 100;
                    using (StorageItemThumbnail thumbnail = await f.GetThumbnailAsync(thumbnailMode, size))
                    {
                        if (thumbnail != null && (thumbnail.Type == ThumbnailType.Image || thumbnail.Type == ThumbnailType.Icon))
                        {
                            BitmapImage bitmapImage = new BitmapImage();
                            bitmapImage.SetSource(thumbnail);
                            AudioFile       o1 = new AudioFile();
                            Image           i  = new Image();
                            MusicProperties musicProperties = await f.Properties.GetMusicPropertiesAsync();

                            i.Source = bitmapImage;
                            o1.Thumb = i;
                            o1.Title = f.Name;
                            o1.Album = "Unknown";
                            if (musicProperties.Title != "")
                            {
                                o1.Title = musicProperties.Title;
                            }
                            if (musicProperties.Album != "")
                            {
                                o1.Album = musicProperties.Album;
                            }
                            string[] contributingArtistsKey = { "System.Music.Artist" };
                            IDictionary <string, object> contributingArtistsProperty = await musicProperties.RetrievePropertiesAsync(contributingArtistsKey);

                            string[] contributingArtists = contributingArtistsProperty["System.Music.Artist"] as string[];
                            o1.Artist = "";
                            if (contributingArtists != null)
                            {
                                foreach (string contributingArtist in contributingArtists)
                                {
                                    o1.Artist += contributingArtist;
                                }
                            }
                            if (o1.Artist == "")
                            {
                                o1.Artist = "Unknown";
                            }
                            o1.Genre = musicProperties.Genre.ToList();
                            o1.Name  = f.Name;
                            o1.Path  = f.Path;
                            SongList.Items.Add(o1);
                            songFileList.Add(o1);
                            autoItems.Add("(Song) " + o1.Name);
                        }
                    }
                }
            }

            IReadOnlyList <StorageFolder> folderList = await storageFolder.GetFoldersAsync();

            foreach (var i in folderList)
            {
                await LoadFromFolder(i);
            }
        }