I have this function:
public static void Play(string FileName, bool Async = false)
{
System.Windows.Media.MediaPlayer mp = new System.Windows.Med
I will share my Solution with you:
I created a Window: WindowPlay.xaml
WindowPlay.xaml.cs:
using System;
using System.Windows;
namespace Sistema.Util
{
///
/// Interaction logic for WindowPlay.xaml
///
public partial class WindowPlay : Window
{
public WindowPlay()
{
try
{
InitializeComponent();
}
catch
{
this.Close();
}
}
///
/// Plays the specified file name
///
/// The filename to play
/// If True play in background and return immediatelly the control to the calling code. If False, Play and wait until finish to return control to calling code.
public static void Play(Uri FileName, bool Async = false)
{
WindowPlay w = new WindowPlay();
var mp = w.MediaElement1;
if (mp == null)
{
// pode estar sendo fechada a janela
return;
}
mp.Source = (FileName);
if (Async)
w.Show();
else
w.ShowDialog();
}
private void MediaElement1_MediaEnded(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}