I'm building a FTP application for Windows Phone 8, and want to save the downloaded songs from the isolated storage to the media library. I check if the file exists in isostore, and it returns true, but when I'm using the SaveSong method it always throws an exception. Here is the code sample:
private async void contextMenuItem1_Click(object sender, RoutedEventArgs e)
{
string fileName = (sender as MenuItem).DataContext.ToString();
MediaLibrary library = null;
......
else if (fileName.EndsWith(".mp3") || fileName.EndsWith(".wav") || fileName.EndsWith(".aac"))
{
IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
if (myIsolatedStorage.FileExists(fileName))
{
library = new MediaLibrary();
StorageFile localFile = await ApplicationData.Current.LocalFolder.GetFileAsync(fileName);
if (localFile != null)
{
//MessageBox.Show("StorageFile is: " + localFile.Name);
try
{
library.SaveSong(new Uri(localFile.Name, UriKind.RelativeOrAbsolute), null, SaveSongOperation.CopyToLibrary);
//MediaLibraryExtensions.SaveSong(media, new Uri(fileName, UriKind.RelativeOrAbsolute), null, SaveSongOperation.CopyToLibrary);
}
catch (InvalidOperationException ex)
{
MessageBox.Show("Exception caught: " + ex.Message);
}
}
}
else
MessageBox.Show("File does not exist in isostore");
}
}
I wolud be very grateful if anybody could help me, thx.