用法
private string _videoPath;
//打开按钮
private void ButtonOpen_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "Video File(*.avi;*.mp4;*.mkv;*.wav;*.rmvb)|*.avi;*.mp4;*.mkv;*.wav;*.rmvb|All File(*.*)|*.*";
if(dialog.ShowDialog().GetValueOrDefault())
{
_videoPath = dialog.FileName;
}
}
//播放按钮
private void ButtonPlay_Click(object sender, RoutedEventArgs e)
{
MediaPlayer.Source = new Uri(_videoPath);
MediaPlayer.Play();
}
private void ButtonStop_Click(object sender, RoutedEventArgs e)
{
MediaPlayer.Stop();
}
private void ButtonForward_Click(object sender, RoutedEventArgs e)
{
MediaPlayer.Position = MediaPlayer.Position + TimeSpan.FromSeconds(20);
}
private void ButtonBack_Click(object sender, RoutedEventArgs e)
{
MediaPlayer.Position = MediaPlayer.Position - TimeSpan.FromSeconds(20);
}
private void MediaPlayer_MediaOpened(object sender, RoutedEventArgs e)
{
// Get the lenght of the video
int duration = MediaPlayer.NaturalDuration.TimeSpan.Seconds;
}