Winjs 项目 - 使用文件选择器 select 音频文件并播放

Winjs project - use File picker to select audio file and play it

我正在使用 Visual Studio 2017 年的 winjs 项目。如何使用 FilePicker 打开文件对话框并选择一个音频文件,然后播放该文件?谢谢大家。

您可以像这样在 JS 代码中使用 Fileopenpicker:

var openPicker = new Windows.Storage.Pickers.FileOpenPicker();
    openPicker.viewMode = Windows.Storage.Pickers.PickerViewMode.thumbnail;
    openPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.picturesLibrary;
    // Users expect to have a filtered view of their folders depending on the scenario.
    // For example, when choosing a documents folder, restrict the filetypes to documents for your application.
    openPicker.fileTypeFilter.replaceAll([".png", ".jpg", ".jpeg"]);

    // 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 photo: " + file.name, "sample", "status");
        } else {
            // The picker was dismissed with no selected file
            WinJS.log && WinJS.log("Operation cancelled.", "sample", "status");
        }
    });

您需要的是将文件类型更改为您需要的目标类型。

有一个JS示例可以直接参考:FilePicker - JS.