[英]How do I play a Media File Stored in D drive using Windows Store App C#
我有一個包含媒體文件路徑的列表框。 當我從列表框中選擇項目(路徑)時,它應該在媒體元素中播放...我該怎么辦? 謝謝,桑卡爾。
private async void btnLoadPlayList_Click(object sender, RoutedEventArgs e)
{
Windows.Storage.Pickers.FileOpenPicker filePicker = new Windows.Storage.Pickers.FileOpenPicker();
filePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.VideosLibrary;
filePicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
filePicker.FileTypeFilter.Clear();
filePicker.FileTypeFilter.Add(".mpeg");
filePicker.FileTypeFilter.Add(".wmv");
filePicker.FileTypeFilter.Add(".mp4");
filePicker.FileTypeFilter.Add(".mkv");
filePicker.FileTypeFilter.Add(".3gp");
IReadOnlyList<Windows.Storage.StorageFile> fileList = await filePicker.PickMultipleFilesAsync();
if (fileList.Count > 0)
{
foreach (StorageFile file in fileList)
{
lstPlayList.Items.Add(file.Path);
}
}
}
private async void lstPlayList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
PlayerME2.Source = new Uri(lstPlayList.SelectedItem.ToString());
}
如果我像這樣設置源,然后嘗試播放,它將顯示錯誤E訪問被拒絕異常。 告訴我一些設置源並播放所選文件的信息。
這是您必須休憩的鏈接。 您必須在appManifest中提供訪問功能。
除此之外,您還可以使用流
IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);
請看我在最新評論中發布的示例中的場景5。
StorageFile file = Playlist.SelectedItem as StorageFile;
if (file != null)
{
// Open the selected file and set it as the MediaElement's source
IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);
Scenario5MediaElement.SetSource(stream, file.ContentType);
}
希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.