【问题标题】:Storage file to System uri?将文件存储到系统 uri?
【发布时间】:2013-05-13 20:00:17
【问题描述】:

我有一个用 c# 编写的 Windows Metro 应用程序。

这是我用来从本地音乐库中选择文件的代码:

FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.MusicLibrary;
openPicker.FileTypeFilter.Add(".mp3");
openPicker.FileTypeFilter.Add(".wav");

StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null)
{
   myMediaElement.Source = file; //error here
}
else
{
    //error here
}

上面说StorageFile不能转换成System.Uri用来改变MediaElement的来源。如何使我的文件成为 uri 链接?似乎Uri("...") 只接受文件位置的String

【问题讨论】:

    标签: c# windows-8 windows-runtime storagefile


    【解决方案1】:

    您必须与SetSource 一起使用文件流。来自How to play a local media file using a MediaElement

    var file = await openPicker.PickSingleFileAsync();
    var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
    myMediaElement.SetSource(stream, file.ContentType);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-28
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 2013-09-13
      • 1970-01-01
      • 2015-06-29
      相关资源
      最近更新 更多