• (2 Pages)
  • +
  • 1
  • 2

How to add sounds to your software. Learn to add sounds to your buttons, labels, etc.

#16 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,991
  • Joined: 08-June 10

Posted 15 January 2012 - 12:34 PM

Judging by the SoundPlayer Class documentation, there is only one form of the Play method: without any arguments. That would be why your code is failing, because it isn't expecting you to pass an argument.

There is however a SoundLocation property, so you could try using that:
DialToneJukeBox.SoundLocation = Resource1._1;
DialToneJukeBox.Play();


Not sure if it has to be loaded first, or if Play takes note of the updated location first and loads it for you.
Was This Post Helpful? 1
  • +
  • -

#17 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4361
  • View blog
  • Posts: 12,180
  • Joined: 18-April 07

Posted 15 January 2012 - 12:39 PM

Play() doesn't take an argument. You setup the SoundPlayer class with the sound you want to play and then call Play() to play it. In other words...

SoundPlayer DialToneJukeBox = new SoundPlayer();

private void button1_Click(object sender, EventArgs e)
{
     // Tell it the location of the sound file
     DialToneJukeBox.SoundLocation("path to sound file");

     // Load it into the player
     DialToneJukeBox.Load();

     // Play it
     DialToneJukeBox.Play();
}



This of course can probably be refactored so that it cuts down on all the lines of code here, but I wanted you to see that Play() itself doesn't take a parameter. It simply starts the sound file.

:)
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2