[英]Get music library files
Trying to excess Music folder on windows phone app 8.1 but getting following Exception: 尝试在Windows Phone App 8.1上超出音乐文件夹,但出现以下异常:
System.Reflection.TargetInvocationException was unhandled Message: An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in System.Windows.ni.dll Additional information: Exception has been thrown by the target of an invocation.
尚未处理System.Reflection.TargetInvocationException消息:System.Windows.ni.dll中发生了类型为'System.Reflection.TargetInvocationException'的未处理异常附加信息:调用的目标已引发异常。
Here is the code: Calling 这是代码:调用
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();
}
}
Add Music-library capability in package.appmanifest file 在package.appmanifest文件中添加音乐库功能
Then try this code. 然后尝试此代码。 It worked for me
对我有用
StorageFolder folder = KnownFolders.MusicLibrary;
if (folder!=null)
{
var songs = (await folder.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByName)).ToList();
}
Try this. 尝试这个。
Works perfect on Windows 8.1 Universal 在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)
{
}
Then try to get the list from source 然后尝试从来源获取列表
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.