C
C#2mo ago
nutsack 2003

adding music on forms app

i added a main menu music that plays on main menu yes great and also selection screen also great it stops at the loading screen which is what i wanted but im trying to add another song for loading screen and no matter what i do it wont play
51 Replies
nutsack 2003
nutsack 2003OP2mo ago
i can send the code $code
MODiX
MODiX2mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
nutsack 2003
nutsack 2003OP2mo ago
i used chatgpt for help cause when i tried it didnt work and chatgpt didnt fix anything either
nutsack 2003
nutsack 2003OP2mo ago
BlazeBin - zsgmksxluohb
A tool for sharing your source code with the world!
surf68
surf682mo ago
- you're instantiating two soundplayers for some reason - have you tried playing the same file as the main menu to rule out file issues?
nutsack 2003
nutsack 2003OP2mo ago
yes ive tried the main menu music didnt work either if im not wrong also am i supposed to use the same sound player? i thought i had to make a new one since its gonna play something else
surf68
surf682mo ago
i'm not sure. i'm talking about line 22 of your code specifically.
nutsack 2003
nutsack 2003OP2mo ago
let me see yeah im confused
surf68
surf682mo ago
by?
nutsack 2003
nutsack 2003OP2mo ago
i dont get it i checked the line
surf68
surf682mo ago
the code you've just pasted, you create a new instance of SoundPlayer on line 22 and assign it to Loadingmusic then on line 23 you create another instance of SoundPlayer and assign it to Loadingmusic the one created and assigned on line 22 never does anything
nutsack 2003
nutsack 2003OP2mo ago
can you tell me how i really dont know anything about forums create a new soundplayer right
surf68
surf682mo ago
why do you have line 22?
nutsack 2003
nutsack 2003OP2mo ago
oh yeah about that i fixed it but i forgot to send the new version my bad should i send the updated version
surf68
surf682mo ago
go for it and send the equivalent code from your other form that does work
nutsack 2003
nutsack 2003OP2mo ago
BlazeBin - qshacdhpbxue
A tool for sharing your source code with the world!
nutsack 2003
nutsack 2003OP2mo ago
i also changed the name of the file both in files and in the code oh fuck me my bad wrong one again so sorry here is the final code of loading screen
nutsack 2003
nutsack 2003OP2mo ago
BlazeBin - cxkccinjxzfd
A tool for sharing your source code with the world!
nutsack 2003
nutsack 2003OP2mo ago
and im gona send the selection form
nutsack 2003
nutsack 2003OP2mo ago
BlazeBin - fcxzsmistjks
A tool for sharing your source code with the world!
surf68
surf682mo ago
right, so that form is having its soundplayer passed in via constructor. where's the code that does that?
nutsack 2003
nutsack 2003OP2mo ago
yes let me send it its in the main menu
nutsack 2003
nutsack 2003OP2mo ago
BlazeBin - hmbcsipawekw
A tool for sharing your source code with the world!
surf68
surf682mo ago
so the main screen loads and plays the wav file correctly?
nutsack 2003
nutsack 2003OP2mo ago
yes do you want me to record it?
surf68
surf682mo ago
and when you click on label3, the selection form is shown and the sound continues to play?
nutsack 2003
nutsack 2003OP2mo ago
yes nevermind i just am facing another error that i was not facing let me fix that on the mainscreen right now
surf68
surf682mo ago
and you then click on startgame, the sound stops and the loading screen is shown?
nutsack 2003
nutsack 2003OP2mo ago
yes oh what the hell now the label3 is giving an error it was working perfect let me fix that rq okay fixed let me show you the program real quick and now it works? dude i swear it didnt work before and i didnt face any of those issues and also another question when i mistakenly add an event how do i remove it thats what casued me errors in my program i deleted them manually from the code
surf68
surf682mo ago
what do you mean by add an event?
nutsack 2003
nutsack 2003OP2mo ago
like lets say i double click on a button that i am not supposed to and it adds a click event
surf68
surf682mo ago
you mean it adds a function to act as an event handler?
nutsack 2003
nutsack 2003OP2mo ago
yes i think so it adds a "click" event
surf68
surf682mo ago
the event already exists (it's part of the framework), you're talking about generating an event handler and wiring it up
nutsack 2003
nutsack 2003OP2mo ago
and i want to add music to the game screen aswell so the same steps right ?
surf68
surf682mo ago
if you're using the GUI i believe you'd need to go back onto the button, go to its properties and remove the handler there. you can then just delete the code.
nutsack 2003
nutsack 2003OP2mo ago
so remove handler and delete the code got it
surf68
surf682mo ago
it's been a long time since i worked with win forms but it'll be something like that
nutsack 2003
nutsack 2003OP2mo ago
and also one more question i want to add a specific sound effect when a button is clicked but i want it to play once only and then move to the next forms so i just add a sound player and then make it during the mouseclick event right i am a really bad perfectionist because of the menu and sound stuff i didnt even get to develpp my game yet
surf68
surf682mo ago
yeah but another thing to bear in mind is that playing sound uses external resources which is why these SoundPlayers implement IDisposable
nutsack 2003
nutsack 2003OP2mo ago
what does that mean
surf68
surf682mo ago
Using objects that implement IDisposable - .NET
Learn how to use objects that implement the IDisposable interface in .NET. Types that use unmanaged resources implement IDisposable to allow resource reclaiming.
nutsack 2003
nutsack 2003OP2mo ago
i added them to my project so it could play on my professors computer would it not work then? to the resources
surf68
surf682mo ago
as long as you distribute them with the application, yes
nutsack 2003
nutsack 2003OP2mo ago
i will read this im confused what do you mean
surf68
surf682mo ago
i'm talking about resources like file handles etc rather than the actual files and other system resources it'll be using to play the audio so you want to make sure that the SoundPlayers are disposed of (you'll see what that means when you read the link)
nutsack 2003
nutsack 2003OP2mo ago
also how do i export my project as a rar and one more thing i want to save a backup project like this one works perfectly i want to save this as a new one and move on another just inc ase somethnig goes wrong
surf68
surf682mo ago
your click handler will end up something like
using (var player = new SoundPlayer("path_to_sound.wav"))
{
player.Play();
}
using (var player = new SoundPlayer("path_to_sound.wav"))
{
player.Play();
}
nutsack 2003
nutsack 2003OP2mo ago
thanks
surf68
surf682mo ago
- you'll end up publishing the application (or just using the build output) and you'll have to RAR it separately - generally people keep track of the state of their source code using a version control system (VCS). git is by far the most popular VCS in use these days anyhow i've got to dip, you've got a bunch of reading to do so good luck.
nutsack 2003
nutsack 2003OP2mo ago
thanks

Did you find this page helpful?