C# NAUDIO.dll C# event handler issue

  • Thread starter Thread starter Superposed_Cat
  • Start date Start date
Click For Summary
The discussion centers on an issue with using NAudio in a Windows Forms application, specifically regarding the incorrect usage of the EventHandler for the StoppedEventArgs. The user reports that all code samples they have tried result in an error related to the line "+= new EventHandler<StoppedEventArgs>". Other participants request additional details, such as the version of NAudio being used and whether the error occurs at runtime or compile time. One user mentions that the code compiles successfully on their end and suggests that the issue may stem from referencing an incompatible version of the NAudio DLL. The conversation highlights the importance of ensuring compatibility with the correct version of libraries when developing applications.
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.
 
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

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