GItHub链接
技术问题
1.建立播放器
点击打开链接
要制作一个播放器,首先要做的就是选择播放器。
我们选择了自带控件MediaElement。并设置了它的一些属性。
<MediaElement Name="Player"
HorizontalAlignment="Left" Height="Auto"
VerticalAlignment="Top" Width="Auto"
AutoPlay="True"
AreTransportControlsEnabled="True" >
</MediaElement>
2.读取文件
接下来要做的事情就是使其支持打开文件这样的方式。
private async System.Threading.Tasks.Task OpenFileDialogAsync()
{
var OpenPicker = new Windows.Storage.Pickers.FileOpenPicker();
OpenPicker.ViewMode = PickerViewMode.Thumbnail;
OpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
OpenPicker.FileTypeFilter.Add(".mp3");
OpenPicker.FileTypeFilter.Add(".mp4");
var file = await OpenPicker.PickSingleFileAsync();
if (file != null)
{
var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
Player.SetSource(stream, file.ContentType);
Player.Play();
}
else
{
FileText.Text = "Not a true file";
}
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
await OpenFileDialogAsync();
}
效果图
看起来很丑,因为没有添加背景,通过上网搜索(还是那个网站),我们找到了这么一句话:
You can use the PosterSource property to provide your MediaElement with a visual representation before the media is loaded.
于是我们在MediaElement空间下添加上了PosterSource属性。
PosterSource="/Assets/Image.jpg"
然后运行:
接下来,MP3:
MP4:
似乎很是完美,但是!在播放音乐时,打开全屏,效果如下:
左上角和右上角的东西,看起来让人很难受啊。
为了解决这个问题… 通过上网… 点击打开链接
我决定,把它隐藏起来。
if (GridSettings.Visibility== Visibility.Visible)
{
GridSettings.Visibility = Visibility.Collapsed;
Btn.Content = "︾";
}
else
{
GridSettings.Visibility = Visibility.Visible;
Btn.Content = "︽";
}
嗯,就这样… = = = =