Reputation: 25
I need the audio file to played when the app runs and it does this successfully, the only problem is is when I move the application to a different PC, the sound won't work because the file path doesn't return true any more. How do I fix this?
namespace Dewey_Decimal_System
{
public partial class Dewery_Decimal_System : Form
{
private int _ticks;
public Dewery_Decimal_System()
{
InitializeComponent();
Second();
timer1.Start();
SoundPlayer splayer = new SoundPlayer(@"C:\Users\Luke Warren\Desktop\Prog3B\Dewey Decimal
System\Media\EntroMusic2.wav");
splayer.Play();
panel1.Hide();
button1.Hide();
button2.Hide();
button3.Hide();
this.Hide();
}
Upvotes: 0
Views: 422
Reputation: 1
Code:
string path = Path.Combine(Environment.CurrentDirectory, "Sounds", "SoundForCorrectAnswer.wav");
SoundPlayer player = new SoundPlayer(path);
player.Play();
("Sounds" is the folder where the sounds are located, in this situation SoundForCorrectAnswer.wav) Here's the code, but you have to go properties of the sound and try the following steps:
Right-click on the sound file in the Solution Explorer and select Properties.
In the Properties window, set the "Copy to Output Directory" property to "Copy always" and for "Build Action" set "Content".
Run
Upvotes: 0
Reputation: 1
I have the same problem, the target pc give error for the audio path is in the home pc! I search google no one have a solution all say the same thing "put it resource, make content. embed in resource, output directory and many answers but nothing worked ! it still error shows file missing which point the file path from the home pc. I was forced to put all audio files in aseperate mapp and send it to the friend and told him to put tha mapp on his pc under C:\GameAudio and changed all the audio in the program to the new location t.ex C:\GameAudio\hit.wav.
Upvotes: 0
Reputation: 25
You would do something like this to get the path "Data\ich_will.mp3" inside your application environments folder.
string fileName = "ich_will.mp3";
string path = Path.Combine(Environment.CurrentDirectory, @"Data\", fileName);
In my case it would return the following:
C:\MyProjects\Music\MusicApp\bin\Debug\Data\ich_will.mp3
Upvotes: 1
Reputation: 1
SoundPlayer splayer = new SoundPlayer(@"EntroMusic2.wav");
And move file "EntroMusic2.wav" into the same folder with the application exe file.Upvotes: 0