简体   繁体   English

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

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

I'm working with Visual Studio 2017, winjs project.我正在使用 Visual Studio 2017,winjs 项目。 How to use FilePicker to open file dialog and pick an audio file, then play that file?如何使用 FilePicker 打开文件对话框并选择音频文件,然后播放该文件? Thanks guys.多谢你们。

You could use the Fileopenpicker in your JS code like this:您可以在 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");
        }
    });

What you need is to change the file type to the target type you need.您需要将文件类型更改为您需要的目标类型。

There is a JS sample that you could directly refer to: FilePicker - JS .有一个 JS 示例可以直接参考: FilePicker - JS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM