I am developing a small project in wpf. I have 13 user controls. Each has one wav(sound) file. I wrote a function in a class to play the wav file. I have list view control to display the user control items in the main window. Whenever i click the list view item, the corresponding wav file should play.It plays, it works fine. If i go to the next item while playing the current item, the current item's file is playing. It should be stopped.I dont know how to do that...
The following is the Class code
The following is the user control code
Help me....
Thank you.....
The following is the Class code
Code:
class Class1
{
string fpath;
//public SoundPlayer player;
public MediaPlayer player;
public void playsound(string s)
{
if (s != null)
{
try
{
//player = new SoundPlayer(System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + "\\IntroToRatios\\" + s + "");
//player.Play();
fpath = System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + "\\IntroToRatios\\" + s + "";
player = new MediaPlayer();
player.Open(new Uri(fpath));
player.Play();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
Code:
Class1 cls = new Class1()
if(timertick = 200)
{
cls.playsound("2.wav");
}
Thank you.....
Comment