Cannot retrieve file from FutureAccessList if I us

2019-08-14 16:56发布

I have an app that retrieves files in two ways: one using a file picker and the other, using the path directly. In both cases, I get the file, add it to the future access list, and save the token in an array. Later in the app, I use the token to retrieve the file using futureAccessList.getFileAsync. Now, the 2nd half, i.e. getting back of the file using the token code is identical in both cases, so it must be something in the way I add it to the future access list, because it works when I use the filepicker, but not when I use the path directly.

Filepicker add code

    // Create the picker object and set options
    var openPicker = new Windows.Storage.Pickers.FileOpenPicker();
    openPicker.viewMode = Windows.Storage.Pickers.PickerViewMode.thumbnail;
    openPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.musicLibrary;

    // Select MIDI files only
    openPicker.fileTypeFilter.replaceAll([".mp3"]);

    // Open the picker for the user to pick a file
    openPicker.pickSingleFileAsync().then(function (file) {
        if (file) {
            // Application now has read/write access to the picked file
            WinJS.log && WinJS.log("Picked file: " + file.name, "sample", "status");

            // Store the file to access again later
            var listToken = Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList.add(file);

            // Save the file mapping. If it exists, overwrite.
            fileMappings[padId] = { padNumber: padId, audioFile: listToken };
        }
        else {
            // The picker was dismissed with no selected file
            WinJS.log && WinJS.log("Operation cancelled.", "sample", "status");
        }
    });

Direct path add code

    Windows.Storage.KnownFolders.musicLibrary.getFileAsync("filename.mp3").then(function (file) {
        if (file) {
            // Application now has read/write access to the picked file
            WinJS.log && WinJS.log("Picked file: " + file.name + ", full path: " + file.path, "sample", "status");

            // Store the file to access again later
            var listToken = Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList.add(file);

            // Save the file mapping. If it exists, overwrite.
            fileMappings['pad0'] = { padNumber: 'pad0', audioFile: listToken };
        }
        else {
            // Could not get access to the file
            WinJS.log && WinJS.log("File unavailable!", "sample", "status");
        }
    });

Personally, I feel like this line (Windows.Storage.KnownFolders.musicLibrary.getFileAsync) doesn't give me read-write access, just read, and that might be what's messing it up. Here is a related thread on msdn. It's a C#-MediaElement question, but closely related. Any idea what could be wrong here? If it's permissions-related, how can I specify that I need r-w access? I thought specifying capabilities in the appxmanifest was good enough. I can add the file retrieval code here if anyone needs it. Thanks for your time.

[Windows RT app using Javascript. Confirmed 'Music Library' capability is checked.]

1条回答
我想做一个坏孩纸
2楼-- · 2019-08-14 17:47

Your code is correct. This is a bug in the WinRT API. I work on that part of the system and have filed a bug on this topic.

查看更多
登录 后发表回答