WPF MediaPlayer and threading
-
I`m trying to play a short sound using MediaPlayer class. I`m using the following code snippet: MediaPlayer mp = new MediaPlayer(); mp.Open(new Uri(@"C:\...\Dom.wav")); mp.Volume = 1D; mp.Play(); It goes well, but when I try to play this sound in my form (where I have several endless transformations), it never gets played. I suppose that the reason is that it is to be played on the same thread that UI works. And as the UI works all the time (because of endless transformations), my .wav never gets enough CPU to be played. So I tried to launch it on separate thread. It didn`t help either. The only solution I found is to add a sleep after this: MediaPlayer mp = new MediaPlayer(); mp.Open(new Uri(@"C:\...\Dom.wav")); mp.Volume = 1D; mp.Play(); Thread.Sleep(1500); But this looks terrible. Could anyone give me another solution?
-
I`m trying to play a short sound using MediaPlayer class. I`m using the following code snippet: MediaPlayer mp = new MediaPlayer(); mp.Open(new Uri(@"C:\...\Dom.wav")); mp.Volume = 1D; mp.Play(); It goes well, but when I try to play this sound in my form (where I have several endless transformations), it never gets played. I suppose that the reason is that it is to be played on the same thread that UI works. And as the UI works all the time (because of endless transformations), my .wav never gets enough CPU to be played. So I tried to launch it on separate thread. It didn`t help either. The only solution I found is to add a sleep after this: MediaPlayer mp = new MediaPlayer(); mp.Open(new Uri(@"C:\...\Dom.wav")); mp.Volume = 1D; mp.Play(); Thread.Sleep(1500); But this looks terrible. Could anyone give me another solution?
If you just want to play sound, look into the managed DirectX classes instead.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
If you just want to play sound, look into the managed DirectX classes instead.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
I don't know, but I know that class is slow, and it seems to me like overkill
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
I don't know, but I know that class is slow, and it seems to me like overkill
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Using so enormous technology as DirectX to play 5-second simple sound is even bigger overkill. Thanks for advice however.
Not really - it's just using built in stuff that is there already.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )