This project is read-only.

Possible incorrect behaviour StreamFinished event

Sep 9, 2014 at 12:27 PM

I catch StreamFinished event of LoopStream and it triggers more than once. I think that it's incorrect. This issue can be reproduced by modifying EqualizerTest example in following way:
        private void button1_Click(object sender, EventArgs e)
            var ofn = new OpenFileDialog();
            ofn.Filter = CodecFactory.SupportedFilesFilterEn;
            if (ofn.ShowDialog() == DialogResult.OK)

                if (WasapiOut.IsSupportedOnCurrentPlatform)
                    _soundOut = new WasapiOut();
                    _soundOut = new DirectSoundOut();

                LoopStream loopStream;
                var source = CodecFactory.Instance.GetCodec(ofn.FileName)
                    .AppendSource(x => new LoopStream(x) { EnableLoop = false }, out loopStream)
                    .AppendSource(Equalizer.Create10BandEqualizer, out _equalizer)

                loopStream.StreamFinished += (s, args) =>
                       button1.Text = button1.Text + "1";

                source.Position = Math.Max(source.Length - 96000, 0);

Stop() raises PlaybackTread exception what gives one execution. But if you comment it and run the application (it's possible that you need to run it without debugger from folder) you will have following text on button 'Open111'. At least I have such text.

Is it correct behavior?
Sep 9, 2014 at 8:18 PM
The behavior that Stop throws an Exception is absolutely correct. The StreamFinished event gets fired on the Playbackthread. Stopping the playback from the Playbackthread is not possible and causes a strange behavior of your application.
But you are right. The behavior that there are 3 "1" is wrong. I've already found the problem. Will be fixed with the next version of cscore. Thanks for reporting.
Sep 9, 2014 at 8:18 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Sep 9, 2014 at 9:44 PM
Thank you for your quick response and quick fix.