简体   繁体   中英

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


         }

}

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();
        }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM