如何使用MediaElement.SetPlaybackSource

时间:2016-06-01 16:01:38

标签: c# winrt-xaml uwp-xaml

任何人都可以帮助我了解如何使用UWP MediaElement.SetPlaybackSource吗?

我浏览了this链接,但无法弄清楚/了解此方法的用法。也没有在MSDN或网络上提供的任何示例。谢谢!

1 个答案:

答案 0 :(得分:0)

以下是sample code from MSDN

//Create a new picker
var filePicker = new Windows.Storage.Pickers.FileOpenPicker();

//Add filetype filters.  In this case wmv and mp4.
filePicker.FileTypeFilter.Add(".wmv");
filePicker.FileTypeFilter.Add(".mp4");
filePicker.FileTypeFilter.Add(".mkv");

//Set picker start location to the video library
filePicker.SuggestedStartLocation = PickerLocationId.VideosLibrary;

//Retrieve file from picker
StorageFile file = await filePicker.PickSingleFileAsync();

if (file != null)
{
    mediaSource = MediaSource.CreateFromStorageFile(file);
    mediaElement.SetPlaybackSource(mediaSource);
}