我正在尝试使用 TagLib-Sharp 从 mp4 视频中读取元数据,但得到 UnauthorizedAccessException。我正在使用 FileOpenPicker 并做出了正确的声明。
有任何想法吗?提前致谢。
错误: “在 taglib-sharp.DLL 中发生‘System.UnauthorizedAccessException’类型的异常,但未在用户代码中处理
附加信息:对路径“C:\Users\user\Videos\VideoName.mp4”的访问被拒绝。”
代码:
private async void Button_Click(object sender, RoutedEventArgs e)
{
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.VideosLibrary;
openPicker.FileTypeFilter.Add(".mp4");
StorageFile selection = await openPicker.PickSingleFileAsync();
var selectionstring = selection.Path.ToString();
if (selection != null)
{
//TagLib.File file = TagLib.File.Create(selectionstring); //<-Exception thrown here
//TagLib.Tag Tag = file.GetTag(TagLib.TagTypes.Id3v2);
//var frame = file.Tag.Comment.ToString();
OutputTextBlock.Text = selectionstring;
var stream = await selection.OpenAsync(Windows.Storage.FileAccessMode.Read);
videoWindow.SetSource(stream, selection.ContentType);
videoWindow.Play(); //The video will play just fine so I know I have read access.
}
else
{
OutputTextBlock.Text = "Operation cancelled.";
}
}