@Paul_Crawley wrote:
Was trying to find a way of playing song after song, or selecting them from a list etc, couldn't find exactly what i needed so i wrote this, all the songs are oog format, hope it helps someone
public class AudioClass { private List<Song> songList; public List<SoundEffect> sfxList; private int songIndex = 0; public float musicVolume = 0.5f; // How to make an instance of a sound effect // var instance = sfxList[0].CreateInstance(); // instance.IsLooped = true; // instance.Play(); #region Audio Constructor /********************************************************************************************* * Function Name : Audio Constructor * Description : do any initialization for the audio * ******************************************************************************************/ public AudioClass() { sfxList = new List<SoundEffect>(); songList = new List<Song>(); songList.Add(Game1.sContent.Load<Song>(assetName: @"Soundfx\pnp1")); // load a song songList.Add(Game1.sContent.Load<Song>(assetName: @"Soundfx\pnp2")); // load a song songList.Add(Game1.sContent.Load<Song>(assetName: @"Soundfx\pnp3")); // load a song sfxList.Add(Game1.sContent.Load<SoundEffect>(assetName: @"Soundfx\balldrop")); // load a soundfx MediaPlayer.Volume = musicVolume; songIndex = 0; MediaPlayer.Play(songList[songIndex]); MediaPlayer.MediaStateChanged += MediaPlayer_MediaStateChanged; } private void MediaPlayer_MediaStateChanged(object sender, EventArgs e) { songIndex += 1; if (songIndex >= songList.Count) songIndex = 0; MediaPlayer.Play(songList[songIndex]); } #endregion ~AudioClass() { songList.Clear(); sfxList.Clear(); } } public enum eSFXList { balldrop = 0, } }
Posts: 1
Participants: 1