UWP学习--NaiveMediaPlayer
2018-04-03 19:35
148 查看
这里,我制作了一个Naïve MediaPlayer,由于是Naïve ,所以只有简单的播放.mp3,.mp4资源文件的功能,在之后的两次博客中,会逐渐改善升级。
第一:project homepage of my Github project:https://github.com/chunfengchuicao/NaiveMediaPlayer 第二:the problems由于是简单的播放器,所以只有两个问题需要解决。一个是如何找到资源文件位置,另一个是如何播放资源文件。 问题一:找到资源文件位置 获取文件路径是必须,也是最重要的。在这里,通过网络搜索,在微软官方网站上我找到了fileopenpickerclass这个类,文件选取器可以显示,了解到了使用方法。找到的网页:https://docs.microsoft.com/en-us/uwp/api/windows.storage.pickers.fileopenpicker网页中例子的代码:FileOpenPicker openPicker= new FileOpenPicker();openPicker.ViewMode =PickerViewMode.Thumbnail;openPicker.SuggestedStartLocation= PickerLocationId.PicturesLibrary;openPicker.FileTypeFilter.Add(".jpg");openPicker.FileTypeFilter.Add(".jpeg");openPicker.FileTypeFilter.Add(".png"); StorageFile file = await openPicker.PickSingleFileAsync();if (file != null){ // Application now has read/write accessto the picked file OutputTextBlock.Text = "Pickedphoto: " + file.Name;}else{ OutputTextBlock.Text = "Operationcancelled.";} Note:You should always make sure that your app is not snapped (or thatit can be unsnapped) and set file picker properties regardless of whether theuser is picking a single file or multiple files. 我的代码:varopenPicker = newWindows.Storage.Pickers.FileOpenPicker(); openPicker.FileTypeFilter.Add(".mp4"); openPicker.FileTypeFilter.Add(".mp3"); var file = await openPicker.PickSingleFileAsync(); 在这里,我学会了如何获取文件位置,并限制文件选取格式的选取。 问题二:播放文件资源 在课堂上和第一次blog中就了解到了MeidaEvent这个控件,在这里就可以使用这个控件来播放资源文件。在微软的官方文档中有详细的使用方法。找到的微软官方网站:https://docs.microsoft.com/en-us/uwp/api/Windows.UI.Xaml.Controls.MediaElement网站中例子的代码:private async void Button_Click(object sender, RoutedEventArgse){ await SetLocalMedia();} async private System.Threading.Tasks.Task SetLocalMedia(){ var openPicker = new Windows.Storage.Pickers.FileOpenPicker(); openPicker.FileTypeFilter.Add(".wmv"); openPicker.FileTypeFilter.Add(".mp4"); openPicker.FileTypeFilter.Add(".wma"); openPicker.FileTypeFilter.Add(".mp3"); var file = await openPicker.PickSingleFileAsync(); // mediaPlayer is a MediaElement definedin XAML if (file != null) { var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); mediaPlayer.SetSource(stream,file.ContentType); mediaPlayer.Play(); }} Important:In Windows 10, build 1607 and on we recommend that you use MediaPlayerElement in place of MediaElement. MediaPlayerElementhas the same functionality as MediaElement,while also enabling more advanced media playback scenarios. Additionally, allfuture improvements in media playback will happen in MediaPlayerElement.
但是我还是用的MediaEvent
我的代码:if (file!= null) { var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); play.SetSource(stream,file.ContentType); play.Play(); }在这里,我学会了,现将文件路径转换成流,在设置媒体播放的文件路径,最后是播放媒体文件。
第一:project homepage of my Github project:https://github.com/chunfengchuicao/NaiveMediaPlayer 第二:the problems由于是简单的播放器,所以只有两个问题需要解决。一个是如何找到资源文件位置,另一个是如何播放资源文件。 问题一:找到资源文件位置 获取文件路径是必须,也是最重要的。在这里,通过网络搜索,在微软官方网站上我找到了fileopenpickerclass这个类,文件选取器可以显示,了解到了使用方法。找到的网页:https://docs.microsoft.com/en-us/uwp/api/windows.storage.pickers.fileopenpicker网页中例子的代码:FileOpenPicker openPicker= new FileOpenPicker();openPicker.ViewMode =PickerViewMode.Thumbnail;openPicker.SuggestedStartLocation= PickerLocationId.PicturesLibrary;openPicker.FileTypeFilter.Add(".jpg");openPicker.FileTypeFilter.Add(".jpeg");openPicker.FileTypeFilter.Add(".png"); StorageFile file = await openPicker.PickSingleFileAsync();if (file != null){ // Application now has read/write accessto the picked file OutputTextBlock.Text = "Pickedphoto: " + file.Name;}else{ OutputTextBlock.Text = "Operationcancelled.";} Note:You should always make sure that your app is not snapped (or thatit can be unsnapped) and set file picker properties regardless of whether theuser is picking a single file or multiple files. 我的代码:varopenPicker = newWindows.Storage.Pickers.FileOpenPicker(); openPicker.FileTypeFilter.Add(".mp4"); openPicker.FileTypeFilter.Add(".mp3"); var file = await openPicker.PickSingleFileAsync(); 在这里,我学会了如何获取文件位置,并限制文件选取格式的选取。 问题二:播放文件资源 在课堂上和第一次blog中就了解到了MeidaEvent这个控件,在这里就可以使用这个控件来播放资源文件。在微软的官方文档中有详细的使用方法。找到的微软官方网站:https://docs.microsoft.com/en-us/uwp/api/Windows.UI.Xaml.Controls.MediaElement网站中例子的代码:private async void Button_Click(object sender, RoutedEventArgse){ await SetLocalMedia();} async private System.Threading.Tasks.Task SetLocalMedia(){ var openPicker = new Windows.Storage.Pickers.FileOpenPicker(); openPicker.FileTypeFilter.Add(".wmv"); openPicker.FileTypeFilter.Add(".mp4"); openPicker.FileTypeFilter.Add(".wma"); openPicker.FileTypeFilter.Add(".mp3"); var file = await openPicker.PickSingleFileAsync(); // mediaPlayer is a MediaElement definedin XAML if (file != null) { var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); mediaPlayer.SetSource(stream,file.ContentType); mediaPlayer.Play(); }} Important:In Windows 10, build 1607 and on we recommend that you use MediaPlayerElement in place of MediaElement. MediaPlayerElementhas the same functionality as MediaElement,while also enabling more advanced media playback scenarios. Additionally, allfuture improvements in media playback will happen in MediaPlayerElement.
但是我还是用的MediaEvent
我的代码:if (file!= null) { var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); play.SetSource(stream,file.ContentType); play.Play(); }在这里,我学会了,现将文件路径转换成流,在设置媒体播放的文件路径,最后是播放媒体文件。
相关文章推荐
- UWP_Homework3------Naive Media Player
- NaiveMediaPlayer——UWP简单的播放器实现(for MP3/MP4)
- 一个Naive的Media Player By UWP
- 学习笔记--AxWIndowsMediaPlayer 属性
- Androidx学习笔记(78)--- 视频播放器(MediaPlayer+SurfaceView)
- C#学习之路之使用windows media player 实例
- Homework for UWP——Naïve Media Player, Part 1
- Naive Media Player 1
- UWP:使用MediaPlayerElement实现媒体播放器
- UWP-Naïve Media Player 1.0
- Naive Media Player
- 【VC学习】VC2010 Windows Media Player控件的使用技巧
- IOS学习——IOS上MediaPlayer framework实现视频播放
- Android学习(六)getService(String16(media.player))
- android 媒体框架学习--mediaplayerservice 关系类图
- 为vlc增加libvlc_MediaPlayerBuffering事件处理(原创)
- Windows Media Player 的文件格式支持情况
- android Mediaplayer各种属性和方法简单介绍
- VC2010 编译 Media Player Classic - BE (mpc-be)
- WindowsMediaPlayer的用法