访问MediaLibrary的GetPath()方法时出现UnAuthorizedAccessException

时间:2014-12-10 20:04:17

标签: c# .net windows-phone-8 unauthorizedaccessexcepti media-library

我真的陷入一个奇怪的问题,我无法在我的最后重现,但它经常在用户结束时发生。根据堆栈跟踪,当用户导航到特定页面时,应用程序崩溃。跟踪从Microsoft收到的该问题的堆栈跟踪。



Frame    Image                                                    Function                                                                                                               Offset        
0        Microsoft.Xna.Framework.MediaLibraryExtensions.ni.dll    Microsoft.Xna.Framework.Media.PhoneExtensions.MediaLibraryExtensions.ThrowExceptionFromResult                          0x00000f5e    
1        Microsoft.Xna.Framework.MediaLibraryExtensions.ni.dll    Microsoft.Xna.Framework.Media.PhoneExtensions.MediaLibraryExtensions.GetPathFromItemInternal                           0x00000050    
2        Microsoft.Xna.Framework.MediaLibraryExtensions.ni.dll    Microsoft.Xna.Framework.Media.PhoneExtensions.MediaLibraryExtensions.GetPath                                           0x00000022    
3        InstaRepost.ni.DLL                                       InstaRepost.Gallery.OnNavigatedTo                                                                                      0x000000ae    
4        Microsoft.Phone.ni.dll                                   Microsoft.Phone.Controls.PhoneApplicationPage.InternalOnNavigatedTo                                                    0x000002d4    
5        Microsoft.Phone.ni.dll                                   Microsoft.Phone.Controls.PhoneApplicationPage.Microsoft.Phone.Controls.IPhoneApplicationPage.InternalOnNavigatedToX    0x0000000c    
6        Microsoft.Phone.ni.dll                                   System.Windows.Navigation.NavigationService.RaiseNavigated                                                             0x0000038e    
7        Microsoft.Phone.ni.dll                                   System.Windows.Navigation.NavigationService.CompleteNavigation                                                         0x00000158    
8        Microsoft.Phone.ni.dll                                   System.Windows.Navigation.NavigationService.ContentLoader_BeginLoad_Callback                                           0x000002aa    
9        Microsoft.Phone.ni.dll                                   System.Windows.Navigation.PageResourceContentLoader.BeginLoad_OnUIThread                                               0x000002b4    
10       Microsoft.Phone.ni.dll                                   System.Windows.Navigation.PageResourceContentLoader+__c__DisplayClass4._BeginLoad_b__0                                 0x0000000a




我在代码中尝试做的是我在Medialibrary以及应用程序的IsolatedStorage中有图像。因此,为了显示它们,我正在从lonelystorage中读取它们的名字,然后从MediaLibrary打开它。

for (int i = 0; i < filesNames.Length; i++)
       {
         if (!filesNames[i].Contains(".tmp") && !filesNames[i].Contains("_ApplicationSettings"))
            {
               obj = new VideoInformation();
               obj.videoName = filesNames[i];
               obj.timeCreated = isolatedStorageFile.GetCreationTime(filesNames[i]);
               for (int j = 0; j < instaRepostPictures.Count; j++)
                {
                   string imagePath = Pictures[j].GetPath();
                   if (imagePath.Contains(obj.videoName))
                    {
                     obj.thumbnailpath = PictureDecoder.DecodeJpeg(Pictures[j].GetThumbnail());
                            //obj.thumbnailpath.
                        }
                    }
                    pictureList.Add(obj);
                }
            }

我认为问题出在GetPath功能中。我已经检查了功能和ID_CAP_MEDIALIB_PHOTO功能。如果有人能帮助我找出这个问题。我要感激不尽。

1 个答案:

答案 0 :(得分:0)

尝试添加这段代码,因为您必须自己调用FrameworkDispatcher.Update方法来调度XNA Framework消息队列中的消息。

Microsoft.Xna.Framework.FrameworkDispatcher.Update();

正如您所说,请确保Capabilities中的Manifest已被勾选。

参考:MSDN