✅ Little help adding music to a program

I saw this method and I'm trying to implement it to another project, it throws the error "CS0246 The type or namespace 'soundplayer' could not be found (are you missing a using directive or an assembly reference?)" on line 11. Apparently some people solve it by updating their .NET framework but I'm running 8.0 which is the latest (I think). I'm new at this and would appreciate the help, thanks in advance
No description
146 Replies
Buddy
Buddy9mo ago
C# classes uses PascalCase And C# is case-sensitive PascalCase is HelloWorld, in your case it would be SoundPlayer. Each word has an uppercase, so Sound, and Player SoundPlayer Also .net framework and .NET 8 ard two different runtimes. .Net framework is old and shouldnt be used. .NET 8 is the most recent officially released one. .NET Framework only goes up to 4.7.x
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
now is this error, is a different one so, progress?
No description
Buddy
Buddy9mo ago
Did you add the dependency dll yourself?
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
dont know what that is lol
leowest
leowest9mo ago
u have to add to the csproj to use WPF
Buddy
Buddy9mo ago
Show the contents of the file with an extension being .csproj
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
so i install the csproj extension?
Buddy
Buddy9mo ago
No, a file extension Like txt, exe, etc.
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
my program should have the csproj extension? because it doesn't it has dsl
leowest
leowest9mo ago
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
sln srry
leowest
leowest9mo ago
u just double click the project like I did in this video and it opens the csproj if u are on .net 8
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
it shows this
No description
leowest
leowest9mo ago
yep now U add that line I highlighted in my video to yours
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
okok does it matter where?
leowest
leowest9mo ago
yes and no needs to be inside the propertygroup so if u do similar to my video u will fine and I think u might need to change .net8.0 to .net8.0-windows if I recall it right then it will let u access System.Windows.Media in your console
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
like this?
No description
leowest
leowest9mo ago
No description
leowest
leowest9mo ago
as u can see it works the casing of the words matter S and P upper case
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
hol up im gonna copy yours if you dont mind hhehehe
leowest
leowest9mo ago
u already have it all u just need to change the first letter S and first letter P in your code
leowest
leowest9mo ago
No description
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
i did that, still shows me the error this one
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
No description
leowest
leowest9mo ago
and what is the error?
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
No description
leowest
leowest9mo ago
shouldn't try to build u know how to build right? right click the project and build
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
nope like this is a thing for school, im just trying to add music because i thought it would be cool
leowest
leowest9mo ago
what is nope referring to? that u dont know how to build? or build does not work? it can be...
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
i do not know how to build
leowest
leowest9mo ago
remember when u open the csproj? instead of double clicking the project u right click and go to build
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
ok from the file explorer or visual studio?
leowest
leowest9mo ago
in the solution explorer in visual studio
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
oh okokok
leowest
leowest9mo ago
No description
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
yes
leowest
leowest9mo ago
does it error?
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
ok progress, it does run now but something that the file does not exist at the location let me check real quick
leowest
leowest9mo ago
your sound
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
youre being really helpful btw, thanks
leowest
leowest9mo ago
u have to copy into your project then u select it
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
yes
leowest
leowest9mo ago
then in properties u change it to copy if newer
leowest
leowest9mo ago
No description
leowest
leowest9mo ago
then the song will be in the right place and will play to get this window u select the music u have added to your project in the solution explorer
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
ok can you tell me how to copy it to the project? the tutorial said to copy it to the debug folder so im lost kinda
leowest
leowest9mo ago
u select the song in the Explorer right click copy u go to your visual studio right click the project paste
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
dem aigh aight
leowest
leowest9mo ago
u can drag and drop too either works
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
lets goooooooo its working let me try to do all this on the real project real quick gimme a sec
leowest
leowest9mo ago
wait wait wait the real project is what?
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
yeah
leowest
leowest9mo ago
Winforms? WPF?
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
i do not know, but i can change it to wpf like i did with this one right?
leowest
leowest9mo ago
no if its winforms it has its own soundplayer so u use that instead
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
mmmmm
leowest
leowest9mo ago
WPF is 1 ui framework Winforms is another ui framework u dont mix then
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
let me show you the real one the properties i mean
leowest
leowest9mo ago
go for it
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
No description
leowest
leowest9mo ago
so its a console project as well?
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
yup
leowest
leowest9mo ago
ok then its fine go for it 😉
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
ok, final stretch. says i have multiple entry points, i assume this is because i have two programs, how should i arange it so that i can have them both?
No description
leowest
leowest9mo ago
multiple Main methods I see u literally copied the whole code from on file to the other didnt u
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
hahaha yes how do i do that?
leowest
leowest9mo ago
u just copy over 3 lines
leowest
leowest9mo ago
No description
leowest
leowest9mo ago
to your actual Main and the top using System.Media;
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
ok
leowest
leowest9mo ago
u dont just dump another's project full cs file into another existing project's cs file
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
ik, but i sometimes do that so force of habit i guess now its showing the original error
leowest
leowest9mo ago
did u change the csproj?
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
No description
MODiX
MODiX9mo ago
leowest
Quoted by
From leowest
React with ❌ to remove this embed.
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
wdym?
leowest
leowest9mo ago
click the link above and follow the video like u did before
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
ah yes i did that
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
No description
leowest
leowest9mo ago
and did u add at the top
leowest
leowest9mo ago
No description
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
that was missing its compiling, it seems like its taking a bit
leowest
leowest9mo ago
did u add the song to the project and set it to copy if newer?
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
i forgot! its playing the music but its not displaying the following write lines
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
it stays there
No description
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
No description
leowest
leowest9mo ago
yep because PlayLooping is a blocking command
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
ohhh ok
leowest
leowest9mo ago
so this might be a bit overcomplicated
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
how do i keep it in loop while the programs running?
leowest
leowest9mo ago
u would run it inside its own task so the rest of the code runs
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
okokok
leowest
leowest9mo ago
and then at the end of the code u exit that task
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
ok, how do i do that?
leowest
leowest9mo ago
give me a moment and I will explain ok can u show ur code as it is now
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
yes
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
No description
leowest
leowest9mo ago
first step move this above line 27
No description
leowest
leowest9mo ago
then add static before the first SoundPlayer
leowest
leowest9mo ago
then delete these 2 lines
No description
leowest
leowest9mo ago
in the place of those 2 lines u will have
_ = Task.Run(() =>
{
sound.PlayLooping();
});
_ = Task.Run(() =>
{
sound.PlayLooping();
});
Then at the end of your Main method u add
sound.Stop();
sound.Stop();
leowest
leowest9mo ago
it will look similar to this
No description
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
okok lemme modify it
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
buncha errors
No description
No description
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
i saw what i did wrong, added the opening parenthesis just at the end
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
with the stop
No description
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
nvm i mean it runs but the songs not playing
leowest
leowest9mo ago
well the code is not right i literally wrote it for u to copy paste and u did it wrong 😛
MODiX
MODiX9mo ago
leowest
_ = Task.Run(() =>
{
sound.PlayLooping();
});
_ = Task.Run(() =>
{
sound.PlayLooping();
});
Then at the end of your Main method u add
sound.Stop();
sound.Stop();
Quoted by
React with ❌ to remove this embed.
leowest
leowest9mo ago
pay close attention and see how they are different
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
the parenthesis right? i missed one in the task run
leowest
leowest9mo ago
yes
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
yup, fixed it already its not playing the song
leowest
leowest9mo ago
ok can u repost the code there are no errors right
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
dont think so gimme a sec
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
No description
leowest
leowest9mo ago
and did u add the file to the project and set it to copy if newer?
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
yup
leowest
leowest9mo ago
mmm then try sound.PlaySync(); before the playlooping but it works for me so not sure what is wrong in yours
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
also tried with public static void and async (I assume async is necessary for both to go at the same time?)
leowest
leowest9mo ago
no it can be static void it will work just fine
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
aight still nothing tried with both void and async i mean
leowest
leowest9mo ago
but u do need async Task because otherwise it wont move forward and play the rest of the code
leowest
leowest9mo ago
so this is right
No description
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
still nothing
leowest
leowest9mo ago
_ = Task.Run(() =>
{
sound.SoundLocation = "In the Cave.wav";
sound.Load();
sound.PlayLooping();
});
_ = Task.Run(() =>
{
sound.SoundLocation = "In the Cave.wav";
sound.Load();
sound.PlayLooping();
});
what if u try this
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
still nothing hmmmm
leowest
leowest9mo ago
well I dont know, ur missing something either ur code is not running there
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
yeah
leowest
leowest9mo ago
and its running something else can u $paste teh whole code
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
idk
MODiX
MODiX9mo ago
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
shouldnt be
leowest
leowest9mo ago
to the above site
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
like i do have more stuff but it isnt doing anything
leowest
leowest9mo ago
well I can't help further without code unhappily
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
yup pasting it rn
leowest
leowest9mo ago
because if u done all exactly like the other app we just did and its not working then either something is stopping it or its not even running maybe ur code reaches the stop so fast it doesnt run at all
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
i added a console read line to stop it earlier, imma try that again okkkkkk it does work but as sook as i click enter it stops the song ohhh wait wait
leowest
leowest9mo ago
well yeah if ur code ends the song stops makes sense right
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
AHAHAHAH YESSSSS added another readline at the end thank you so much and for being patient, i just thought it would be cooler if the character builder they asked for had music and stuff
leowest
leowest9mo ago
¯\_(ツ)_/¯ well no worries do a /close so we can mark this as solved
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
yes yes
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
BΣΛПƧЦПDΛΣ
BΣΛПƧЦПDΛΣOP9mo ago
just sending a video for you to watch thank you so much again
Want results from more Discord servers?
Add your server