NAudio播放声音并监听进度

        WaveOut waveOutDevice;
        AudioFileReader audioFileReader;
        SampleToWaveProvider waveProvider;
        SampleChannel sampleChannel;
        public void PlayWavWithPath(string FilePath)
        {
           // this.CreateGraphics().Clear(Color.Empty);

            waveOutDevice = new WaveOut();
            audioFileReader = new AudioFileReader(FilePath);
            waveProvider = new SampleToWaveProvider(audioFileReader);

            sampleChannel = new SampleChannel(waveProvider, false);
            sampleChannel.PreVolumeMeter += OnPreVolumeMeter;//播放进度回调波形图

            waveOutDevice.Init(sampleChannel);
            waveOutDevice.Play();
        }

        //回调
        void OnPreVolumeMeter(object sender, StreamVolumeEventArgs e)
        {
            Console.WriteLine(e.MaxSampleValues[0] + "->>>>>>>--" + e.MaxSampleValues[1]);
            AddMax(e.MaxSampleValues[0]);//绘制波形
        }

 

你可能感兴趣的:(DaoNetC#)