NateRickard / Plugin.AudioRecorder

Audio Recorder plugin for Xamarin and Windows
MIT License
164 stars 68 forks source link

Not implemented exception #44

Closed 1-max-1 closed 4 years ago

1-max-1 commented 4 years ago

When I try and run the example code it just throws an exception that says its not implemented.

using System;
using System.Threading.Tasks;
using Plugin.AudioRecorder;

namespace csharp_mic_thingy
{
    class Program
    {
        static async Task Main()
        {
            var recorder = new AudioRecorderService
            {
                StopRecordingOnSilence = true, //will stop recording after 2 seconds (default)
                StopRecordingAfterTimeout = true,  //stop recording after a max timeout (defined below)
                TotalAudioTimeout = TimeSpan.FromMinutes(1), //audio will stop recording after 1 minute
                AudioSilenceTimeout = TimeSpan.FromSeconds(1),
                SilenceThreshold = 0.2f
            };

            recorder.AudioInputReceived += Recorder_AudioInputReceived;

            Console.WriteLine("Enter \"go\" into the console when you are ready (no qoutes).\nDont forget to press enter!");
            string go = Console.ReadLine();
            if (go != "go") return;

            await RecordAudio(recorder);
        }

        static void Recorder_AudioInputReceived(object sender, string e)
        {
            Console.WriteLine("YO... received some data");
        }

        static async Task RecordAudio(AudioRecorderService recorder)
        {
            try
            {
                if (!recorder.IsRecording)
                {
                    await recorder.StartRecording();
                }
                else
                {
                    await recorder.StopRecording();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception occured:\n\n" + ex);
        }
        }
    }
}

Here is the console output:

System.NotImplementedException: The method or operation is not implemented.
   at Plugin.AudioRecorder.AudioStream.get_ChannelCount()
   at Plugin.AudioRecorder.WaveRecorder.StopRecorder()
   at Plugin.AudioRecorder.WaveRecorder.StartRecorder(IAudioStream stream, String filePath)
   at Plugin.AudioRecorder.AudioRecorderService.StartRecording()
   at csharp_mic_thingy.Program.RecordAudio(AudioRecorderService recorder) in C:\Users\Max\Documents\csharp_mic_thingy\Program.cs:line 40
NateRickard commented 4 years ago

What platform are you targeting? This library supports (Xamarin) iOS/Android/UWP projects.

This error typically indicates using the package on an unsupported platform, OR (more commonly) a failure to add the package to your platform project as well as the shared code, per the setup guide.

1-max-1 commented 4 years ago

Im running it on windows 10, with .net core, if that's what you're asking for

NateRickard commented 4 years ago

This library is designed to work with Xamarin.iOS, Xamarin.Android, and UWP apps. If you're writing a different type of Windows app, or .NET Core code that will end up on any other platform than the 3 mentioned, it will not work. The actual implementation is written in the platform code, as there is no .NET Core API that provides this functionality across all supported platforms.

npostma commented 4 years ago

@maxymoo22 I think you need to use a library like https://github.com/naudio/NAudio for .net. It has some capture libraries in it.