NAUDIO.dll C# event handler issue

  • Context: C# 
  • Thread starter Thread starter Superposed_Cat
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around an issue with event handlers in a C# application using the NAudio library. Participants are addressing a specific error related to the use of the StoppedEventArgs in the event handler for audio recording, exploring potential causes and solutions.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant reports an error with the syntax " += new EventHandler" in their code sample and seeks clarification on the issue.
  • Another participant asks for clarification on whether the application is a console application and requests additional information about the version of NAudio being used and the nature of the error.
  • A different participant inquires whether the error occurs at runtime or compile time, noting that their own code compiles without issues.
  • A later reply suggests that the original poster may have been using an incompatible version of the NAudio library, as referencing the DLL from another project resolved the issue for them.

Areas of Agreement / Disagreement

Participants have not reached a consensus on the root cause of the issue, as there are multiple perspectives on the problem, including potential version incompatibilities and differences in project types.

Contextual Notes

There is a lack of specific information regarding the version of NAudio being used and the exact nature of the error, which may limit the ability to diagnose the issue accurately.

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;
        }

    }
    }
}
 
Technology news 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
3K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K