【问题标题】:UnauthorizedAccessException using TabLib - Windows 8 App使用 TabLib 的 UnauthorizedAccessException - Windows 8 应用程序
【发布时间】:2013-11-14 04:34:31
【问题描述】:

我正在尝试使用 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."; 
            }       
   }

【问题讨论】:

    标签: c# windows-8 unauthorizedaccessexcepti taglib-sharp


    【解决方案1】:

    确保您对视频库具有写入权限(打开资源管理器,右键单击存储视频的文件夹(不是视频库图标!)并取消选择只读。

    希望有所帮助。

    【讨论】:

      【解决方案2】:

      应用程序只能直接访问其安装和应用程序数据目录中的文件系统。它没有从音乐库中读取的权限。

      要访问其他地方的文件,您需要使用从文件选择器(或通过合约)返回的 StorageFile 对象。

      此对象提供对文件的代理访问:代理拥有用户的完全访问权限,并且可以读取任何文件用户有权读取。代理代表您的应用使用此访问权限,通过 StorageFile 对象提供包含文件内容的流。

      希望这会有所帮助。

      File access and permissions in Windows Store apps

      【讨论】:

        【解决方案3】:

        所以使用它:VideoProperties class

        比 taglib 容易得多。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-01-29
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多