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