C# WPF 音频文件播放方法

前端代码.xaml

 

后台代码.cs

/// 
/// [SoundFile] Play/Stop
/// 
/// 
/// 
public void Dispatcher_mediaElement(bool pIsPlay, string pRelativePath = "")
{
        this.mediaElement.Dispatcher.BeginInvoke(new Action(() =>
        {
            if (pIsPlay == true)
            {
                this.mediaElement.Source = new Uri(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + pRelativePath);
                this.mediaElement.Play();
            }
            else
            {
                this.mediaElement.Close();
                this.mediaElement.Source = null;
            }
        }));
}

 

你可能感兴趣的:(WPF,C#,WPF)