Music Implementation
In these pages we will cover how music was implemented and how to use the audio files in our resources.resx
We decided to go with a blend of divorced dad rock and some alternative rock. All music that gets added in the playlist must comply with these guidelines, we gotta give the people what they want.
How it works
private void LoadSong() {
if (currentSong >= 0 && currentSong < songNames.Length) {
StopAndDispose();
string song = songNames[currentSong];
try {
Stream stream = (Stream)rm.GetObject(song);
var waveStream = new RawSourceWaveStream(stream, new WaveFormat());
waveOut.Init(waveStream);
}
catch (Exception ex) {
MessageBox.Show("Error loading the song" + ex.Message);
audio = null;
}
}
}
It all works through the LoadSong() function essentially. All this does it is check first if the index is within the songList parameters. Then it Calls StopAndDispose() which simply stops and gets rid of current song so there are no errors in starting the new song. The it gets the song from the playlist and it uses the Stream variable to get the bytes of the song from our resources.Designer.cs using rm (ResourseManager function). Then uses the NAudio library to play the .wav
To learn how to add music and functionality in the code checkout
How to add music in the codeTo learn how to add music to the resources to use checkout
How to add music to ResourcesLast updated