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