Code sample - VU meter and Waveform painter

WinForms sample

VU meter

1. Add VisioForge.Controls.UI.WinForms.VolumeMeterPro.VolumeMeter control to the form. For stereo you can add second control.

2. Set Audio_VUMeter_Pro_Enabled property to true before Start/Play method call.

3. Add OnAudioVUMeterProVolume event handle in your MediaPlayer or VideoCapture control instance.

private void VideoCapture1_OnAudioVUMeterProVolume(object sender, AudioLevelEventArgs e)
{
    volumeMeter1.Amplitude = e.ChannelLevelsDb[0];
    if (e.ChannelLevelsDb.Length > 1)
    {
        volumeMeter2.Amplitude = e.ChannelLevelsDb[1];
    }
}

Waveform painter

1. Add VisioForge.Controls.UI.WinForms.VolumeMeterPro.WaveformPainter control to the form. For stereo you can add second control.

2. Set Audio_VUMeter_Pro_Enabled property to true before Start/Play method call.

3. Add OnAudioVUMeterProVolume event handle in your MediaPlayer or VideoCapture control instance.

private void VideoCapture1_OnAudioVUMeterProVolume(object sender, AudioLevelEventArgs e)
{
    waveformPainter1.AddMax(e.ChannelLevelsDb[0]);
    if (e.ChannelLevelsDb.Length > 1)
    {
        waveformPainter2.AddMax(e.ChannelLevelsDb[1]);
    }
}

WPF sample

VU meter

1. Add VisioForge.Controls.UI.WPF.VolumeMeterPro.VolumeMeter control to the form. For stereo you can add second control.

2. Set Audio_VUMeter_Pro_Enabled property to true before Start/Play method call.

VideoCapture1.Audio_VUMeter_Pro_Enabled = true;

volumeMeter1.Start();
volumeMeter2.Start();

3. Add OnAudioVUMeterProVolume event handle in your MediaPlayer or VideoCapture control instance.

private delegate void AudioVUMeterProVolumeDelegate(AudioLevelEventArgs e);

private void AudioVUMeterProVolumeDelegateMethod(AudioLevelEventArgs e)
{
    volumeMeter1.Amplitude = e.ChannelLevelsDb[0];
    volumeMeter1.Update();

    if (e.ChannelLevelsDb.Length > 1)
    {
        volumeMeter2.Amplitude = e.ChannelLevelsDb[1];
        volumeMeter2.Update();
    }
}

private void VideoCapture1_OnAudioVUMeterProVolume(object sender, AudioLevelEventArgs e)
{
    Dispatcher.BeginInvoke(new AudioVUMeterProVolumeDelegate(AudioVUMeterProVolumeDelegateMethod), e);
}

4. After stopping playback stop volume meters

volumeMeter1.Stop();
volumeMeter1.Clear();

volumeMeter2.Stop();
volumeMeter2.Clear();

Waveform painter

1. Add VisioForge.Controls.UI.WPF.VolumeMeterPro.WaveformPainter control to the form. For stereo you can add second control.

2. Set Audio_VUMeter_Pro_Enabled property to true before Start/Play method call.

VideoCapture1.Audio_VUMeter_Pro_Enabled = true;
waveformPainter.Start();

3. Add OnAudioVUMeterProMaximumCalculated event handle in your MediaPlayer or VideoCapture control instance.

private delegate void AudioVUMeterProMaximumCalculatedDelegate(VUMeterMaxSampleEventArgs e);

private void AudioVUMeterProMaximumCalculatedelegateMethod(VUMeterMaxSampleEventArgs e)
{
    waveformPainter.AddValue(e.MaxSample, e.MinSample);
}

private void VideoCapture1_OnAudioVUMeterProMaximumCalculated(object sender, VUMeterMaxSampleEventArgs e)
{
    Dispatcher.BeginInvoke(new AudioVUMeterProMaximumCalculatedDelegate(AudioVUMeterProMaximumCalculatedelegateMethod), e);
}

4. After stopping playback stop volume meters

waveformPainter.Stop();
waveformPainter.Clear();

VisioForge © 2006-2020

  • GitHub-Mark-64px
  • Twitter Социальные Иконка
  • VisioForge Facebook page
  • YouTube channel