Quantcast
Channel: NAudio
Viewing all articles
Browse latest Browse all 5831

New Post: waveout get notification after elapsed time

$
0
0
First of all, thanks for your help!
Here is my full Code:
    public class TimeElapsedAudioFileReader : AudioFileReader
    {
        public event Action<TimeSpan> Elapsed;
        public NotifyingSampleProvider Nsp  { get; set; }
        public ETimeSpan SignalTime         { get; set; }

        public TimeElapsedAudioFileReader(string filename) : base(filename)
        {
            Nsp = new NotifyingSampleProvider(this.ToSampleProvider());
            Nsp.Sample += _nsp_Sample;
        }

        private bool _triggered = false;

        private void _nsp_Sample(object sender, SampleEventArgs e)
        {
            if (_triggered)
                return;
            if (this.CurrentTime >= SignalTime.BaseSpan)
            {
                _triggered = true;
                if (Elapsed != null)
                    Elapsed(this.CurrentTime);
            }
        }

        public override int Read(byte[] buffer, int offset, int count)
        {
            return base.Read(buffer, offset, count);
        }

        public void Reset()
        {
            this.Position = 0;
            _triggered = false;
        }
    }
And here how i Init the WaveOutEvent Object:
 private void InitAudioFile()
        {
            try {   
                _source = new TimeElapsedAudioFileReader(_app.Settings.AudioFilePath);
                _source.Elapsed += _audioreader_Elapsed;
                _waveout.DesiredLatency = 150;
                _waveout.NumberOfBuffers = 15;
                _waveout.Init(_source.Nsp);
                
            }
            catch (System.Exception ex)
            {
                ExceptionHandler.HandleException(ex, "Error while Initializing Audiofile", this);
            }
        }
Do I Need to override the Read Method as well?
With this Waveout Settings i can reach a precision to 1/100 of a second but not a 1/1000

Viewing all articles
Browse latest Browse all 5831

Latest Images

Trending Articles



Latest Images