getting Unhandled Exception: Instance of '_CodecNotSupportedException'"while using flutter_sound package

2.2k Views Asked by At

I want to record audio while pressing a button. here is my code.

 var tempDir = await getTemporaryDirectory();
 String path = '${tempDir.path}/audio.acc';

await _myRecorder.openRecorder();
await _myRecorder.startRecorder(
                        toFile: path,
                        codec: Codec.aacMP4,
                      );

// after recording another button to stop the recording. to stop this recording i used the code:

await _myRecorder.stopRecorder();
_myRecorder.closeRecorder();
_myRecorder = null;

i get my above mentioned error while i call "await _myRecorder.startRecorder" function. please help. thank you.

3

There are 3 best solutions below

4
Sipho Sikakane On

I recently had the same problem, it seems you should not append the file type at the end when declaring your path and should change:

String path = '${tempDir.path}/audio.acc';

To:

String path = '${tempDir.path}/audio';

Secondly some codecs currently are not supported but I am struggling to find which ones as their codec compatibility page is down:

https://flutter-sound.canardoux.xyz/guides_codec.html

0
Muhammad Umair Saqib On

I was facing this error and solved this by removing codec parameter. Use following code to record

    await mRecorder!.setSubscriptionDuration(const Duration(seconds: 1));
var tempDir = await getTemporaryDirectory();
mPath = '${tempDir.path}/audio';
// String tempPath = "";
// log("tempPath : $tempPath");

mRecorder!
    .startRecorder(
  toFile: mPath,
  // codec: codec,
  audioSource: AudioSource.microphone,
)
0
Husam Alhwadi On

Audio file extension should be '.aac' and not '.acc' just correct the extension type and give it one more try

String path = '${tempDir.path}/audio.aac';