Search code examples
c#soundplayer

Do ... While System.Media.SoundPlayer() is in use


I have been trying to display text on my Console Application while a sound file is currently playing, lyrics as an example. How is the best way to do it?

struct Music 
{
        public
            void PlaySong() {
            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.SoundLocation = @"C:\Users\MyPC\Music\MoreMusic\songsample.wav";
            player.Load();
            player.PlaySync();
        }
}

class Program
{


        static public void Main(string[] args)
        {
            Music music;
            do
            {
                //Display Lyrics
            } while (true); //as the song progresses


         }

}

Solution

  • Replace the PlaySync with Play

        struct Music 
    {
            public
                void PlaySong() {
                System.Media.SoundPlayer player = new System.Media.SoundPlayer();
                player.SoundLocation = @"C:\Users\MyPC\Music\MoreMusic\songsample.wav";
                player.Load();
                player.Play();
            }
    }