System.UnauthorizedAccessException:从MusicLibrary Windows Phone 8.1打开mp3文件时拒绝访问

时间:2015-09-23 11:54:32

标签: c# windows-phone-8.1

我尝试使用SetUriSource从前台打开mp3文件,但我一直得到:

Failed with error code System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

我已经定义了音乐库的可用性并在声明时设置了.mp3文件类型。我有一个内置类的Windows运行时组件,我从该类调用此方法。

 var mediaPlayer = BackgroundMediaPlayer.Current;
 var folder = await KnownFolders.MusicLibrary.GetFolderAsync("myFolder");
 StorageFile file = await folder.GetFileAsync("myFile.mp3");
 mediaPlayer.AutoPlay = true;
 mediaPlayer.SetUriSource(new Uri(file.Path, UriKind.RelativeOrAbsolute));

这是我得到的file.Path结果:

C:\Data\Users\Public\Music\myFolder\myFile.mp3

如何解决这个问题?谢谢

1 个答案:

答案 0 :(得分:0)

我发现现在不可能执行

var mediaPlayer = BackgroundMediaPlayer.Current;
var folder = await KnownFolders.MusicLibrary.GetFolderAsync("myFolder");
StorageFile file = await folder.GetFileAsync("myFile.mp3");
mediaPlayer.AutoPlay = true;
mediaPlayer.SetUriSource(new Uri(file.Path, UriKind.RelativeOrAbsolute));

来自前台,所以我从BackgroundTask类执行这行代码并且它可以工作。 THX