Windows Develop Bookmark and Share   
 index > Windows Forms General > System.Media - SoundPlayer PlayLooping() - Error When Another Timer Is Running
 

System.Media - SoundPlayer PlayLooping() - Error When Another Timer Is Running

Recently I had a problem using SoundPlayer PlayLooping method.

Below is my problem and the solution I have found.

Hope this will help anybody with similar issues.

The issue is that as this is essentially a timer, if anther timer is operating at the same time the other timer will somehow interfere and the sound player will loose its file and playback computer noise. A way around this seems to be to construct a manual timer for looping back the sound.

timer_LoopRinging.Enabled = true;

private void timer_LoopRinging_Tick(object sender, EventArgs e)

{

SoundPlayer player = new SoundPlayer(soundFile);

player.Play();

}

Black Dhalia  Monday, February 26, 2007 4:26 PM
Maybe a bit late, but I am having exactly the same problem. I my app several timers (System.Windows.Forms.Timer, 200ms interval) are running when I playback a sound with SoundPlayer.PlayLooping(); It happens within 30 seconds for me (consistently every time).
I am still experimenting whether it is really caused by these other timers. In a standalone app I don't get the problem, or at least, not as fast. If I call SoundPlayer.Stop(); and then SoundPlayer.PlayLooping(); again, everything is fine once more.
        private SoundPlayer     SOUND_Player;
        private Boolean         SOUND_Playing = false;
        private Boolean         SOUND_Silenced = false;

        private void SOUND_Alarm() {
            if(SOUND_Silenced || SOUND_Playing) {
                return;
            }
            try {
                SOUND_Player.Stream = Properties.Resources.Alarm1;
                SOUND_Player.PlayLooping();
                SOUND_Playing = true;
            }catch{
            }
        }
        private void SOUND_Stop() {
            SOUND_Player.Stop();
            SOUND_Playing = false;
        }

Anybody a clue as whether this is a bug or something I could be doing wrong in my app?

Thanks!
DC


DC_2000  Thursday, October 01, 2009 8:56 PM
It seems to be related to the SoundPlayer.Stream property only: When I use this with a sound file embedded in my .resx file it starts emitting bizar sounds after about 20-30 seconds. When I use the SoundPlayer.SoundLocation Property, the problem does not occur (did a 18 Hour test). I looks to me like a Garbage Collector issue, but I'm not sure how that's possible, as I have a global variable which points to the resource stream.
Anywho, I'll guess I won't be using embedded wav files for now and post this as a potential bug to MS.

DC
DC_2000  Friday, October 02, 2009 3:37 PM

You can use google to search for other answers

Custom Search

More Threads

• How to determine which windowsform control is about to receive focus
• Split Container Control ?
• Executing DOS Commands
• regarding password protection
• MVC pattern in WinForms applications
• MDI application problem
• Bug: Please Confirm
• SendMessage (WM_CLOSE) will no close a MessageBox with MessageBoxButtons.YesNo
• Is there any Window Control to hold avi files other than window media player
• Tear-Off Menus and Tabs in Windows Forms Applications