i developed a simple app to play music.
When i run it on debug it works just fine. But after i published it as an application and install it on another machine, it won't run because the file paths is not recognized.
Here is my code:
SoundPlayer player = new SoundPlayer();
player.SoundLocation = @"C:\Users\chris\source\repos\Aplikasi Reminder\Aplikasi Reminder\Resources\mixkit-correct-answer-tone-2870.wav";
player.Play();
I tried to change the paths into:
player.SoundLocation = @"Aplikasi_reminder.Properties.Resources.mixkit-correct-answer-tone-2870.wav";
and it won't too..
Please can someone tell me how to fix that, thank you..
CodePudding user response:
Include your files in the project`s resources folder by right-clicking on your project name>>properties>>Recources>>select audio>>drag your .wav file.
Then you can play the file from Memory Stream
:
public void Play()
{
SoundPlayer player = new SoundPlayer();
player.Stream = YOUR_PROJECT_NAME.Properties.Resources.YOUR_FILE_NAME;
player.Play();
}