Hi I was wondering how I could use sounds in a C# program, like mp3's, and how would I run the program and the music at the same time? I use the 2005 version of C#.
How do I implement sounds like music in C#
Collapse
X
-
For cases like this, google is your friend. General searches of the form "<language> <task>" typically turn up excellent resources. Give it a try, a few great links came up near the top that should get you on the right track.
As for playing it at the same as the program runs, I believe it's threaded. The music playing is processed by a different thread than the one your program executes on.
Good luck!Last edited by GaryTexmo; May 31 '10, 09:13 PM. Reason: Re-added a portion of the removed text which provides the means for the OP to resolve their problem -
i found a way of doing it but i keep getting a error for this code
Code:private void label1_Click(object sender, EventArgs e) { System.Media.SoundPlayer player = new System.Media.SoundPlayer(); player.SoundLocation = @"C:/Users/Ussssssssssser/Desktop/sounds/elvis.wav"; player.Play(); }
InvalidOperatio nException was unhandled
Sound API only supports playing PCM wave files.
and i dont know how to fix it, im really new at C#Comment
-
Originally posted by MattBergeni found a way of doing it but i keep getting a error for this code
private void label1_Click(ob ject sender, EventArgs e)
{
System.Media.So undPlayer player = new System.Media.So undPlayer();
player.SoundLoc ation =
@"C:/Users/Ussssssssssser/Desktop/sounds/elvis.wav";
player.Play();
}
it highlights player.Play(); and says
InvalidOperatio nException was unhandled
Sound API only supports playing PCM wave files.
and i dont know how to fix it, im really new at C#
Hmm, I did some googling around (again, you should really do this...) and it sounds like there might be a problem with streaming sound content over the web. Are you trying to do this, or is this a local application? I'm at home right now and recently got a new computer so I don't have VS installed. I'll try making a test project tomorrow when I'm at work, but I'd still recommend you try the above suggestions (a wave file you created, and googling around for more information).
I'll try to get back to you tomorrow.Comment
-
Hey thanks for the help I got the sound to work but now I’m wondering how I could play the sounds and the main program at the same time. I’ve looked up threading but don’t understand it fully and was wondering if there is an easier way?Comment
-
Oh, right on, glad you got it working.
Well, if you start it in a different thread it will play with the main program at the same time. I don't really understand what you're wanting. Your main program can still control the thread the player is running on so you can start/stop the player based on responses from the main GUI.
To be honest, I thought the player was already threaded on it's own... is this not the case? Can you describe the behaviour? I'm at home looking after my cat who just had surgery so I can't do up a test program, but I can still try to help if you like.Comment
Comment