0

I am attempting to us TagLib-Sharp to read metadata from mp4 videos but get an UnauthorizedAccessException. I'm using the FileOpenPicker and have made the proper declarations.

Any ideas? Thanks in advance.

Error: "An exception of type 'System.UnauthorizedAccessException' occurred in taglib-sharp.DLL but was not handled in user code

Additional information: Access to the path 'C:\Users\user\Videos\VideoName.mp4' is denied."

Code:

     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."; 
            }       
   }
Jignesh.Raj
  • 5,776
  • 4
  • 27
  • 56
kendric
  • 1
  • 2

3 Answers3

0

Make sure you have write access to the video library (open explorer, right click the folder where you store your videos (not the video library icon!) and deselect read-only.

Hope that helped.

0

Applications only have direct access to the file system within its install and application data directories. It doesn't have permission to read from the music library.

To access the files elsewhere you need to use the StorageFile object returned from the file picker (or via contracts).

This object provides brokered access to the file: the broker has the user's full access and can read any file the user has permissions to read. The broker uses this access on your app's behalf to provide a stream with the file's contents through the StorageFile object.

Hope this helps.

File access and permissions in Windows Store apps

SoftwareCarpenter
  • 3,835
  • 3
  • 25
  • 37
0

So use that: VideoProperties class

Much easier than taglib.

dodocs
  • 61
  • 6