获取音乐库文件

时间:2016-05-05 16:41:31

标签: c# windows-phone-8.1 known-folders

尝试在Windows Phone app 8.1上使用多余的音乐文件夹,但获得以下异常:

  

System.Reflection.TargetInvocationException未处理消息:System.Windows.ni.dll中发生未处理的类型“System.Reflection.TargetInvocationException”异常附加信息:调用目标已抛出异常。

以下是代码:致电

try
{
    GetFiles();
}
catch (Exception ex)
{
    Debug.WriteLine(ex.Message);
}

private async void GetFiles()
{
    StorageFolder folder = KnownFolders.MusicLibrary;
    IReadOnlyList<StorageFile> listOfFiles;
    if (folder!=null)
    {
        listOfFiles =await folder.GetFilesAsync(); //this line casuing Debugger.break();
    }
}

2 个答案:

答案 0 :(得分:2)

在package.appmanifest文件中添加音乐库功能

然后尝试此代码。它对我有用

echo json_encode(array_flip($return_array));

PEP8

答案 1 :(得分:0)

试试这个。

Windows 8.1 Universal

上完美运行
            FileOpenPicker openPicker = new FileOpenPicker();
            openPicker.ViewMode = PickerViewMode.Thumbnail;
            openPicker.SuggestedStartLocation = PickerLocationId.MusicLibrary;
            openPicker.FileTypeFilter.Add(".mp3");
            openPicker.FileTypeFilter.Add(".wav");
            openPicker.FileTypeFilter.Add(".mp4");

            var file = await openPicker.PickSingleFileAsync();

            try
            {
                var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
                playbackElement3.SetSource(stream, file.ContentType);//Play Selected

                playbackElement3.Play();

            }
            catch (Exception ex)
            {

            }

然后尝试从源

获取列表