Answers for "if audio is playing"

C#
0

if audio is playing

public class SoundEffect
{
    string _soundFile;
    Thread _soundThread;
    bool _isStopped = true;

    public bool IsFinished { get { return _isStopped; } }    

    public SoundEffect(string soundFile)
    {
        _soundFile = soundFile;
    }

    public void Play()
    {
       if (!_isStopped)
           return;

       _soundThread = new Thread(PlayThread);
       _soundThread.Start();
    }

    private void PlayThread()
    {
        _isStopped = false;
        System.Media.SoundPlayer player = new System.Media.SoundPlayer(_soundFile);
        player.PlaySync();
        _isStopped = true;
    }
}
Posted by: Guest on September-14-2021

Code answers related to "if audio is playing"

C# Answers by Framework

Browse Popular Code Answers by Language