I have one button on my wpf called 'Open Media
' with click event and a MediaElement
to play media.
I want to open a media file by pressing that button.
It's giving me run time exception 'System.NotSupportedException
' on line 'mePlayer.Play()
'. How to achieve this using following code:
private void OpenMediaButton_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openMedia = new OpenFileDialog();
openMedia.Title = "Open Media";
openMedia.Filter = "mp4 files(*.mp4)|*.mp4";
openMedia.InitialDirectory = @"C:\";
openMedia.RestoreDirectory = true;
if (openMedia.ShowDialog() == true)
{
mePlayer.Source = new Uri(openMedia.FileName);
mePlayer.Position = TimeSpan.FromSeconds(1);
mePlayer.Play();
}
}