0

我正在嘗試爲Windows RT設備開發應用程序。我目前面臨的問題是基於未來用例場景:從可移動存儲Windows存儲訪問文件/ RT

  • 用戶定義了一個名爲「宋」擁有各個領域(標題,藝術家等),包括使用選擇的音頻文件結構類別爲FileOpenPicker

我想保存此結構中包含提供的信息JSON文件(標題,藝術家,FullPathToAudio,等等),後來加載結構。打開現有歌曲後,我想訪問音頻文件並提供播放按鈕。

問題是,當我嘗試通過StorageFile.GetFileFromPathAsync(currentSong.FullPathToAudio)訪問文件時,應用程序關閉。我已檢查可移動存儲框中的功能選項卡的Package.appxmanifest文件並添加了用於音頻文件(MP3)的FileTypeAssociation。

的Package.AppxManifest文件被更改如下:

<Applications> 
    <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="JamAid.App"> 
     <m2:VisualElements DisplayName="JamAid" Square150x150Logo="Assets\Logo.png" Square30x30Logo="Assets\SmallLogo.png" Description="JamAid" ForegroundText="light" BackgroundColor="#464646"> 
     <m2:SplashScreen Image="Assets\SplashScreen.png" /> 
     </m2:VisualElements> 
     <Extensions> 
     <Extension Category="windows.fileTypeAssociation"> 
      <FileTypeAssociation Name="mpfiles"> 
      <DisplayName>Mp3 Files</DisplayName> 
      <EditFlags OpenIsSafe="true" /> 
      <SupportedFileTypes> 
       <FileType ContentType="audio/mp3">.mp3</FileType> 
      </SupportedFileTypes> 
      </FileTypeAssociation> 
     </Extension> 
     </Extensions> 
    </Application> 
    </Applications> 
    <Capabilities> 
    <Capability Name="internetClient" /> 
    <Capability Name="removableStorage" /> 
    </Capabilities> 

因爲用戶可以創建大量的歌曲的播放列表,複製應用程序目錄或其他可訪問的位置的文件是不是一種選擇?

編輯:我試圖在本地機器上調試應用程序。現在,而不是剛剛閉幕,它提供了以下錯誤:

An exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll but was not handled in user code

WinRT information: Cannot access the specified file or folder (訁㣯ü). The item is not in a location that the application has access to (including application data folders, folders that are accessible via capabilities, and persisted items in the StorageApplicationPermissions lists). Verify that the file is not marked with system or hidden file attributes.

Additional information: Access is denied.

If there is a handler for this exception, the program may be safely continued.

回答

1

我發現我可以使用此解決方案:http://www.jonathanantoine.com/2012/08/06/keep-access-to-filesfolders-the-user-granted-you/

基本上一個人必須要存儲在FutureAccessList位置:

var picker = new FolderPicker(); 
picker.FileTypeFilter.Add("*.mp3"); 
var folder = await picker.PickSingleFolderAsync(); 

StorageApplicationPermissions.FutureAccessList.AddOrReplace(Token, folder); 

而且使用它找回來:

var folder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(Token); 
+0

令牌是一個字符串,CA n具有文件/文件夾,即字符串標記=「文件」; –