从本地路径打开音乐文件?

时间:2014-08-30 17:09:28

标签: c#

我在互联网上搜索答案,但我找不到任何东西。让我解释一下我的错误: 当我尝试从本地路径打开文件时,我收到此消息:

  

备用流名称必须以“app - ”

开头

我的代码:

 var itemId = ((Item)e.ClickedItem).Subtitle; 
 var file = await KnownFolders.VideosLibrary.GetFileAsync("file:///" + itemId);
 var stream = await file.OpenAsync(FileAccessMode.Read);
 music.SetSource(stream, ".mp3");

我已经在清单中声明了视频库和音乐库。 itemid中的副标题是文件路径。

1 个答案:

答案 0 :(得分:0)

检查this link。我想它可以帮到你

两个问题:

GetFileFromPathAsync requires a path and since it's Async you need to Await it.

To use a URI like ms-appx use the GetFileFromApplicationUriAsync | getFileFromApplicationUriAsync method :

  file = Await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///programs/TextFile1.txt"))

您还必须在函数声明中添加“Async”修饰符。有关异步方法的详细信息,请参阅快速入门:在C#或Visual Basic中调用异步API。

Private Async Sub Button_Tapped(sender As Object, e As TappedRoutedEventArgs)