Beispiel #1
0
        private async void Open_Click(object sender, RoutedEventArgs e)
        {
            var ofn = new OpenFileDialog {
                Filter = CodecFactory.SupportedFilesFilterEn
            };

            if (ofn.ShowDialog() == true)
            {
                _soundOut.Stop();
                if (_notificationSource != null)
                {
                    _notificationSource.Dispose();
                }

                var source = CodecFactory.Instance.GetCodec(ofn.FileName);

                //since the mediafoundationdecoder isn't really accurate what position and length concerns
                //read the whole file into a cache
                if (source is MediaFoundationDecoder)
                {
                    if (source.Length < 10485760) //10MB
                    {
                        source = new CachedSoundSource(source);
                    }
                    else
                    {
                        Stopwatch stopwatch = Stopwatch.StartNew();
                        source = new FileCachedSoundSource(source);
                        stopwatch.Stop();
                        Debug.WriteLine(stopwatch.Elapsed.ToString());
                    }
                }
                source.Position = 0;
                //load the waveform
                await LoadWaveformsAsync(source);

                source.Position = 0;

                _sampleSource       = source.ToSampleSource();
                _notificationSource = new NotificationSource(_sampleSource)
                {
                    Interval = 100
                };
                _notificationSource.BlockRead += (o, args) => { UpdatePosition(); };
                _soundOut.Initialize(_notificationSource.ToWaveSource());
                _soundOut.Play();
            }
        }
Beispiel #2
0
        private async void Open_Click(object sender, RoutedEventArgs e)
        {
            var ofn = new OpenFileDialog {Filter = CodecFactory.SupportedFilesFilterEn};
            if (ofn.ShowDialog() == true)
            {
                _soundOut.Stop();
                if (_notificationSource != null)
                    _notificationSource.Dispose();

                var source = CodecFactory.Instance.GetCodec(ofn.FileName);
                
                //since the mediafoundationdecoder isn't really accurate what position and length concerns
                //read the whole file into a cache
                if (source is MediaFoundationDecoder)
                {
                    if (source.Length < 10485760) //10MB
                    {
                        source = new CachedSoundSource(source);
                    }
                    else
                    {
                        Stopwatch stopwatch = Stopwatch.StartNew();
                        source = new FileCachedSoundSource(source);
                        stopwatch.Stop();
                        Debug.WriteLine(stopwatch.Elapsed.ToString());
                    }
                }
                source.Position = 0;
                //load the waveform
                await LoadWaveformsAsync(source);
                source.Position = 0;

                _sampleSource = source.ToSampleSource();
                _notificationSource = new NotificationSource(_sampleSource) {Interval = 100};
                _notificationSource.BlockRead += (o, args) => { UpdatePosition(); };
                _soundOut.Initialize(_notificationSource.ToWaveSource());
                _soundOut.Play();
            }
        }