0

I am trying to make a program that will show images like a slide show, and each time a picture is shown a sound will play for the current image, a different one for each image. How I can use an array with sounds and play the sound from the array?

string[] sounds = new string[] { "nero", "fai", "mpanio", "tv1", "volta", 
                                 "sleep1" }; 
private int currentAudioIndex = 0;

private void timer1_Tick(object sender, EventArgs e)
{
   timer1.Stop();
   try
   {
      timer1.Interval = 5000; // Next time, wait 5 secs
      button1.BackgroundImage = (Image)Properties.Resources.ResourceManager.GetObject(arr1[currentImageIndex]);
      new SoundPlayer(Properties.Resources.nero).Play();// plays only one sound "nero"

      currentImageIndex++;
   }
   finally
   {
      if (currentImageIndex < arr1.Length)
      timer1.Start();
   }
}
Brandon
  • 645
  • 5
  • 13
  • Typically, you'd have list of sound files - either stored on the hard drive, or online, and you'd store the list of urls (or paths) to those files to play them. That said, it seems it'd be much easier to use one of the many free video and slideshow creator programs out there to just make a slideshow and save it as a true video file. – David May 05 '14 at 16:44
  • The audio files are in the resources folder of the program. i dont want a video , i will add more to the program and i have this problem at the moment , just to play sounds from array each time the picture changes – user3605083 May 05 '14 at 16:48

1 Answers1

0

I'm assuming you have wav file resources named "nero.wav", "fai.wav", etc...

From there, you can load the resources as a Stream and then pass the stream along to the SoundPlayer constructor:

Stream stream = Properties.Resources.ResourceManager.GetStream(arr1[currentImageIndex] + ".wav");
new SoundPlayer(stream).Play();
jaket
  • 9,140
  • 2
  • 25
  • 44
  • I have tried this , but the only sound is played is just a beep and not my sounds – user3605083 May 07 '14 at 10:44
  • Remove file extension string in `GetStream` method, because you only have to pass project resource name string, it will automatically gets right file otherwise if you give file name with extension in `GetStream` then sound is played is just a beep. – Muzammil Imran Jan 15 '22 at 07:32