开发者

Playing audio files in WPF

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜