How to play sound in C# without knowing the sound's location... And also how to send them for some dude😅 | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

How to play sound in C# without knowing the sound's location... And also how to send them for some dude😅

So this was someone's suggestion and I followed that guy's lead. Add music file into Solution Project -> Add Existing Item... -> Add your .wav file. 1.Set the file to Copy always 2.Click the music file in Solution Explorer. 3.In the Properties panel, set Copy to Output Directory to Copy always. 4.Also, set Build Action to Content. This will make Visual Studio always copying the music file into the output directory (e.g. Debug folder). Use this code using System.Media; SoundPlayer player = new SoundPlayer(); player.SoundLocation = AppDomain.CurrentDomain.BaseDirectory + "\\yourmusic.wav"; player.Play(); 👉the code is Super good But here is the problem: I need to send the project for someone. I still have to send the music file for him.don't I?...and the problem is that I don't know how to send him the music file... should I just send him the //myProject.exe and the music file one by one, Plane and sample? Or should I put them in some special file or in some special format?😅

15th Jul 2020, 5:17 PM
Registered_Dodo
Registered_Dodo - avatar
4 Antworten
+ 2
Well thanks bro. You're a legend.\(^o^)/
15th Jul 2020, 7:39 PM
Registered_Dodo
Registered_Dodo - avatar
+ 1
Put the sound file somewhere in your project directory and reference it relative to the file which is accessing it. The way you've done it might work if you tweak the path, e.g. the backslashes, but I wouldn't know without having a fiddle with it. Read this about the difference between relative and absolute paths: https://phpdelusions.net/articles/paths#difference
15th Jul 2020, 6:27 PM
benjamin
0
You could include it somewhere in the project files and reference it with a relative path. Another option is Azure Blob storage.
15th Jul 2020, 6:01 PM
benjamin
0
benjamin you see I'm a total beginner and S#ck at English. So Could you explain it a little easier.(・–・;)ゞ
15th Jul 2020, 6:05 PM
Registered_Dodo
Registered_Dodo - avatar