开发者

Playing audio files in WPF

开发者 https://www.devze.com 2022-12-23 22:08 出处:网络
I am trying to play audio files in WPF and I am currently using the following code: 开发者_如何学PythonFileTextBox.Text = selectedFileName;

I am trying to play audio files in WPF and I am currently using the following code:

 开发者_如何学Python   FileTextBox.Text = selectedFileName;
    MediaPlayer mp = new MediaPlayer();
    mp.Open(new Uri(selectedFileName, UriKind.Relative ));
    mp.Play();

It's working well, except that it doesn't plays the sound. What am I doing wrong?


Your MediaPlayer object is probably being garbage collected before it has a chance to play the file because it has local scope. Try making the media player object a member variable of a class that has application lifetime and see if this fixes it.

0

精彩评论

暂无评论...
验证码 换一张
取 消