我正在为 Windows Phone 8 构建一个 FTP 应用程序,并希望将下载的歌曲从隔离存储保存到媒体库。我检查文件是否存在于 isostore 中,它返回 true,但是当我使用 SaveSong 方法时,它总是抛出异常。这是代码示例:
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");
}
}
如果有人可以帮助我,我将不胜感激,谢谢。