The method 'openAudioSession' isn't defined for the type 'FlutterSoundRecorder'
Asked Answered
M

1

8

I am writing a flutter app for recording voice using flutter_sound package

environment:
  sdk: ">=2.15.1 <3.0.0"
dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.2
  flutter_sound: ^9.1.2
  permission_handler: ^8.3.0
import 'package:flutter_sound/flutter_sound.dart';
import 'package:permission_handler/permission_handler.dart';
Future init() async {
    _audioRecorder = FlutterSoundRecorder();

    final status = await Permission.microphone.request();
    if (status != PermissionStatus.granted){
      throw RecordingPermissionException('Microphone permission denied.');
    }
    await _audioRecorder!.openAudioSession();
    _isRecorderInitiated = true;
 }

I am getting this error

The method 'openAudioSession' isn't defined for the type 'FlutterSoundRecorder'.

Can anybody help me in finding out what's wrong with the code?

Menhir answered 1/2, 2022 at 9:26 Comment(0)
T
15

It seems to have been removed in version 9, but the documentation has not been updated. You can use openRecorder() instead or switch to an older version of the library.

Troudeloup answered 1/2, 2022 at 9:40 Comment(1)
Thanks for your answer. Seems you'r right. I replaced openAudioSession() with openRecorder() and closeAudioSession() with closeRecorder(). It works. There may be more changes in flutter_sound package. Can you suggest me how can I learn about flutter_sound more.Menhir

© 2022 - 2024 — McMap. All rights reserved.