0

A simple program, where a random note is being chosen, shown and played. It supposed to use random number that will be used as an address in the name and file location arrays. But the program gives an error - "make sure the file is here". It is. Is there a specific place where it should be? I've tried almost all folders it the project folder. I don't want to inflate my array with a full path or add an extra code to combine paths, what is the problem here?

using System;
using System.Media;
class BassPractice {
  static void Main() {
    string[] notesArr = new string[]{"E - mi big","F - fa big","G - sol' big","A - la big",
                                   "H - si big","a - la small","h - si small","c - do small",
                                   "d - re small","e - mi small","f - fa small","g - sol' small","c1 - do first"};
    string[] locations = new string[]{"Ebig.wav","Fbig.wav","Gbig.wav","Abig.wav","Hbig.wav","a.wav","h.wav","c.wav","d.wav","e.wav","f.wav","g.wav","c1.wav"};
    Random note = new Random();
    SoundPlayer sound = new SoundPlayer();
    int ArrSize = notesArr.Length;
    int current = 0;
    Console.WriteLine ("Any Key to start");
    for (;;)
    {
        Console.ReadKey();
        Console.Clear();
        current = note.Next(ArrSize);
        Console.WriteLine ("note:");
        Console.WriteLine ("");
        Console.WriteLine (notesArr[current]);
        sound.SoundLocation = locations[current];
        sound.Play();
        Console.WriteLine ("");
        Console.WriteLine ("Any Key for the next one");
    }
  }
}

I thought that the folder with the .cs is the root, so I copied files there. Didn't work, so I copied it practically everywhere. Nothing changed.

Kaman
  • 1
  • When you debug a program inside Visual Studio the location where the executable is built and where it is run is the BIN\DEBUG or BIN\x86\DEBUG. Because your files have no path they should exist in that location – Steve Jul 01 '23 at 10:28

1 Answers1

0

Find where the executable file of your program is located and paste the audio wav file there and it should be able to play it. It should be in the Bin folder which is a sub directory of the Debug directory. The executable is always given a name similar to the name of your solution in most cases.

Son of Man
  • 1,213
  • 2
  • 7
  • 27