public async void Export()
        {
            TryClose();
            using (var library = new MediaLibrary())
            {
                var existingTrackNames =
                    library.Songs.Where(
                        s => s.Album.Name == ApplicationSettings.AlbumName && s.Artist.Name == ApplicationSettings.ArtistName)
                           .Select(s => s.Name)
                           .ToList();
                var trackName = ApplicationSettings.AutoGenerateUniqueTrackNames
                                    ? GetUniqueTrackName(RecordingToExport.Name, existingTrackNames)
                                    : RecordingToExport.Name;

                var metaData = new SongMetadata
                                   {
                                       ArtistName = ApplicationSettings.ArtistName,
                                       AlbumName = ApplicationSettings.AlbumName,
                                       Name = trackName
                                   };

                await CopyFileIntoIsoStore(await _streamManager.GetStorageFileAsync(RecordingToExport));
                var recordingUri = new Uri(RecordingToExport.Id.ToString(), UriKind.RelativeOrAbsolute);
                try
                {
                    library.SaveSong(recordingUri, metaData, SaveSongOperation.CopyToLibrary);
                }
                catch (InvalidOperationException e)
                {
                    MessageBox.Show(e.Message);
                    return;
                }

                MessageBox.Show(
                    String.Format("Copied this recording to the media library{3}Track: {0}{3}Album: {1}{3}Artist {2}",
                                  trackName, ApplicationSettings.AlbumName, ApplicationSettings.ArtistName, Environment.NewLine));
            }
        }
 /// <summary>
 /// Save the audio file to media library.
 /// </summary>
 /// <param name="sender">Save menu item</param>
 /// <param name="e">Event arguments</param>
 private void Save_Click(object sender, EventArgs e)
 {
     AudioFileModel selected = (AudioFileModel)AudioFilesList.SelectedItem;
     if (selected != null)
     {
         var library = new MediaLibrary();
         Song s = library.SaveSong(
             new Uri(selected.FileName, UriKind.RelativeOrAbsolute),
             null,
             /*
             new SongMetadata()
             {
                 ArtistName = "ArtistName",
                 AlbumArtistName = "AlbumArtistName",
                 Name = "SongName",
                 AlbumName = "AlbumName",
                 Duration = TimeSpan.FromSeconds(10),
                 TrackNumber = 1,
                 AlbumReleaseDate = DateTime.Now,
                 GenreName = "Genre"
             },
             */
             SaveSongOperation.CopyToLibrary);
     }
 }
Beispiel #3
0
 public void SaveToMediaLibrary(string fileName, string artist, string name)
 {
     MediaLibrary ml = new MediaLibrary();
     ml.SaveSong(new Uri(fileName, UriKind.Relative), new SongMetadata() { ArtistName = artist, Name = name }, SaveSongOperation.CopyToLibrary);
 }