NAUDIO.dll C# event handler issue

  • Context: C# 
  • Thread starter Thread starter Superposed_Cat
  • Start date Start date
Superposed_Cat
Messages
388
Reaction score
5
This is one of the many code samples I've tried for NAUDIO,but on all of them they say that += new EventHandler<StoppedEventArgs> is incorrect. There is no other issue. Anybody know what's happening?

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using NAudio;
using System.Windows.Forms;
using NAudio.Wave;
using NAudio.Utils;
using NAudio.Mixer;
using NAudio.Midi;

using System.Timers;

namespace WindowsFormsApplication4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

       
         public WaveIn waveSource = null;
    public WaveFileWriter waveFile = null;
    public string RECORDING_PATH;

    public void AudioRecorder(string fileName)
    {
        RECORDING_PATH = fileName;
    }

    public void Start()
    {
        waveSource = new WaveIn();
        waveSource.WaveFormat = new WaveFormat(44100, 1);
        waveSource.DeviceNumber = 0;
        waveSource.DataAvailable += new EventHandler<WaveInEventArgs>(waveSource_DataAvailable);
        waveSource.RecordingStopped += new EventHandler<StoppedEventArgs>(waveSource_RecordingStopped);

        waveFile = new WaveFileWriter(RECORDING_PATH, waveSource.WaveFormat);

        System.Timers.Timer t = new System.Timers.Timer(30000);

        t.Elapsed += new ElapsedEventHandler(Stop);

        waveSource.StartRecording();

        t.Start();


    }

    private void Stop(object sender, ElapsedEventArgs args)
    {
        waveSource.StopRecording();
    }

    private void waveSource_DataAvailable(object sender, WaveInEventArgs e)
    {
        if (waveFile != null)
        {
            waveFile.WriteData(e.Buffer, 0, e.BytesRecorded);
            waveFile.Flush();
        }
    }

    private void waveSource_RecordingStopped(object sender, StoppedEventArgs e)
    {
        if (waveSource != null)
        {
            waveSource.Dispose();
            waveSource = null;
        }

        if (waveFile != null)
        {
            waveFile.Dispose();
            waveFile = null;
        }

    }
    }
}
 
on Phys.org
You aren't coding this as a console application, are you?

Some more information would be helpful, such as the version of NAudio you're using, and a detailed description of the error you're seeing.
 
Are you getting this error at runtime or compile time? It compiles fine for me.
 
I think I just had an incompatible version because I referenced the DLL from one of my other projects and it works fine. Thanks anyways, apologies for the inconveniance.
 

Similar threads

  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K