簡體   English   中英

Winjs 項目 - 使用文件選擇器選擇音頻文件並播放

[英]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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM