✅ 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
146 Replies
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.xnow is this error, is a different one so, progress?
Did you add the dependency dll yourself?
dont know what that is lol
u have to add to the csproj to use WPF
Show the contents of the file with an extension being
.csproj
so i install the csproj extension?
No, a file extension
Like txt, exe, etc.
my program should have the csproj extension? because it doesn't
it has dsl
sln srry
u just double click the project like I did in this video
and it opens the csproj if u are on .net 8
it shows this
yep
now U add that line I highlighted in my video to yours
okok
does it matter where?
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
like this?
as u can see it works
the casing of the words matter
S and P upper case
hol up im gonna copy yours if you dont mind hhehehe
u already have it all
u just need to change the first letter S and first letter P in your code
i did that, still shows me the error
this one
and what is the error?
shouldn't try to build
u know how to build right?
right click the project and build
nope
like this is a thing for school, im just trying to add music because i thought it would be cool
what is nope referring to? that u dont know how to build? or build does not work?
it can be...
i do not know how to build
remember when u open the csproj?
instead of double clicking the project
u right click and go to build
ok
from the file explorer or visual studio?
in the solution explorer in visual studio
oh okokok
yes
does it error?
ok progress, it does run now but something that the file does not exist at the location let me check real quick
your sound
youre being really helpful btw, thanks
u have to copy into your project
then u select it
yes
then in properties u change it to copy if newer
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
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
u select the song in the Explorer
right click
copy
u go to your visual studio
right click the project
paste
dem
aigh aight
u can drag and drop too
either works
lets goooooooo
its working
let me try to do all this on the real project real quick
gimme a sec
wait
wait
wait
the real project is what?
yeah
Winforms?
WPF?
i do not know, but i can change it to wpf like i did with this one right?
no
if its winforms
it has its own soundplayer
so u use that instead
mmmmm
WPF is 1 ui framework
Winforms is another ui framework
u dont mix then
let me show you the real one
the properties i mean
go for it
so its a console project as well?
yup
ok then its fine
go for it 😉
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?
multiple Main methods
I see u literally copied the whole code from on file to the other didnt u
hahaha
yes
how do i do that?
u just copy over 3 lines
to your actual Main
and the top using System.Media;
ok
u dont just dump another's project full cs file into another existing project's cs file
ik, but i sometimes do that so force of habit i guess
now its showing the original error
did u change the csproj?
leowest
Quoted by
<@1102729783969861782> from #Little help adding music to a program (click here)
React with ❌ to remove this embed.
wdym?
click the link above and follow the video like u did before
ah yes i did that
and did u add at the top
that was missing
its compiling, it seems like its taking a bit
did u add the song to the project and set it to copy if newer?
i forgot!
its playing the music but its not displaying the following write lines
it stays there
yep
because PlayLooping is a blocking command
ohhh ok
so this might be a bit overcomplicated
how do i keep it in loop while the programs running?
u would run it inside its own task
so the rest of the code runs
okokok
and then at the end of the code u exit that task
ok, how do i do that?
give me a moment and I will explain
ok
can u show ur code as it is now
yes
first step move this above line 27
then add static before the first SoundPlayer
then delete these 2 lines
in the place of those 2 lines u will have
Then at the end of your Main method u add
it will look similar to this
okok
lemme modify it
buncha errors
i saw what i did wrong, added the opening parenthesis
just at the end
with the stop
nvm
i mean it runs but the songs not playing
well the code is not right
i literally wrote it for u to copy paste and u did it wrong 😛
leowest
Then at the end of your Main method u add
Quoted by
<@1102729783969861782> from #Little help adding music to a program (click here)
React with ❌ to remove this embed.
pay close attention and see how they are different
the parenthesis right?
i missed one in the task run
yes
yup, fixed it already
its not playing the song
ok can u repost the code
there are no errors right
dont think so
gimme a sec
and did u add the file to the project and set it to copy if newer?
yup
mmm then try
sound.PlaySync(); before the playlooping
but it works for me so not sure what is wrong in yours
also tried with public static void and async (I assume async is necessary for both to go at the same time?)
no
it can be static void it will work just fine
aight
still nothing
tried with both
void and async i mean
but u do need async Task
because otherwise it wont move forward
and play the rest of the code
so this is right
still nothing
what if u try this
still nothing
hmmmm
well I dont know, ur missing something
either ur code is not running there
yeah
and its running something else
can u $paste teh whole code
idk
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!
shouldnt be
to the above site
like i do have more stuff but it isnt doing anything
well I can't help further without code unhappily
yup pasting it rn
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
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
well yeah
if ur code ends
the song stops
makes sense right
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
¯\_(ツ)_/¯
well no worries do a /close so we can mark this as solved
yes yes
just sending a video for you to watch
thank you so much again