Reputation:
This is my code:
import 'package:audio_session/audio_session.dart';
import 'package:flutter/material.dart';
import 'package:flutter_sound/flutter_sound.dart';
import 'package:flutter_sound_platform_interface/flutter_sound_recorder_platform_interface.dart';
import 'package:path_provider/path_provider.dart';
class MicTest {
static FlutterSoundRecorder? _mRecorder = FlutterSoundRecorder();
static Codec _codec = Codec.aacMP4;
static const theSource = AudioSource.microphone;
static void startRecorder() async {
await _mRecorder!.openRecorder();
final session = await AudioSession.instance;
await session.configure(AudioSessionConfiguration(
avAudioSessionCategory: AVAudioSessionCategory.playAndRecord,
avAudioSessionCategoryOptions:
AVAudioSessionCategoryOptions.allowBluetooth |
AVAudioSessionCategoryOptions.defaultToSpeaker,
avAudioSessionMode: AVAudioSessionMode.spokenAudio,
avAudioSessionRouteSharingPolicy:
AVAudioSessionRouteSharingPolicy.defaultPolicy,
avAudioSessionSetActiveOptions: AVAudioSessionSetActiveOptions.none,
androidAudioAttributes: const AndroidAudioAttributes(
contentType: AndroidAudioContentType.speech,
flags: AndroidAudioFlags.none,
usage: AndroidAudioUsage.voiceCommunication,
),
androidAudioFocusGainType: AndroidAudioFocusGainType.gain,
androidWillPauseWhenDucked: true,
));
print("initialized");
String _mPath = 'tau_file.mp4';
var tempPath = await getTemporaryDirectory();
_mPath = tempPath.path + "/" + _mPath;
_mRecorder!
.startRecorder(
toFile: _mPath,
codec: _codec,
audioSource: theSource,
)
.then((value) {
//setState(() {});
});
}
static void stopRecorder() async {
await _mRecorder!.stopRecorder().then((value) {
// setState(() {
// //var url = value;
// _mplaybackReady = true;
// });
});
}
}
When I call MicTest.startRecorder() I get:
I/flutter ( 6616): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 6616): │ #0 new FlutterSoundRecorder (package:flutter_sound/public/flutter_sound_recorder.dart:140:13)
I/flutter ( 6616): │ #1 MicrophoneUtils._mRecorder (package:myapp/utils/mic_test.dart:9:45)
I/flutter ( 6616): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter ( 6616): │ 🐛 ctor: FlutterSoundRecorder()
I/flutter ( 6616): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 6616): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 6616): │ #0 FlutterSoundRecorder.openRecorder (package:flutter_sound/public/flutter_sound_recorder.dart:372:13)
I/flutter ( 6616): │ #1 MicrophoneUtils.startRecorder (package:myapp/utils/mic_test.dart:16:23)
I/flutter ( 6616): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter ( 6616): │ 🐛 FS:---> openAudioSession
I/flutter ( 6616): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 6616): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 6616): │ #0 FlutterSoundRecorder._openAudioSession (package:flutter_sound/public/flutter_sound_recorder.dart:381:13)
I/flutter ( 6616): │ #1 FlutterSoundRecorder.openRecorder.<anonymous closure> (package:flutter_sound/public/flutter_sound_recorder.dart:374:17)
I/flutter ( 6616): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter ( 6616): │ 🐛 ---> openAudioSession
I/flutter ( 6616): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 6616): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 6616): │ #0 FlutterSoundRecorder._openAudioSession (package:flutter_sound/public/flutter_sound_recorder.dart:396:17)
I/flutter ( 6616): │ #1 FlutterSoundRecorder.openRecorder.<anonymous closure> (package:flutter_sound/public/flutter_sound_recorder.dart:374:17)
I/flutter ( 6616): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter ( 6616): │ 🐛 Resetting flutter_sound Recorder Plugin
I/flutter ( 6616): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
E/MediaRecorder( 6616): resume called in an invalid state: 1
E/MediaRecorder( 6616): stop called in an invalid state: 1
E/MethodChannel#com.dooboolab.flutter_sound_recorder( 6616): Failed to handle method call
E/MethodChannel#com.dooboolab.flutter_sound_recorder( 6616): java.lang.IllegalStateException: Reply already submitted
E/MethodChannel#com.dooboolab.flutter_sound_recorder( 6616): at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:430)
E/MethodChannel#com.dooboolab.flutter_sound_recorder( 6616): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:267)
E/MethodChannel#com.dooboolab.flutter_sound_recorder( 6616): at com.dooboolab.fluttersound.FlutterSoundManager.resetPlugin(FlutterSoundManager.java:88)
E/MethodChannel#com.dooboolab.flutter_sound_recorder( 6616): at com.dooboolab.fluttersound.FlutterSoundRecorderManager.onMethodCall(FlutterSoundRecorderManager.java:70)
E/MethodChannel#com.dooboolab.flutter_sound_recorder( 6616): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/MethodChannel#com.dooboolab.flutter_sound_recorder( 6616): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#com.dooboolab.flutter_sound_recorder( 6616): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/MethodChannel#com.dooboolab.flutter_sound_recorder( 6616): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#com.dooboolab.flutter_sound_recorder( 6616): at android.os.Handler.handleCallback(Handler.java:938)
E/MethodChannel#com.dooboolab.flutter_sound_recorder( 6616): at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#com.dooboolab.flutter_sound_recorder( 6616): at android.os.Looper.loop(Looper.java:223)
E/MethodChannel#com.dooboolab.flutter_sound_recorder( 6616): at android.app.ActivityThread.main(ActivityThread.java:7656)
E/MethodChannel#com.dooboolab.flutter_sound_recorder( 6616): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#com.dooboolab.flutter_sound_recorder( 6616): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/MethodChannel#com.dooboolab.flutter_sound_recorder( 6616): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/DartMessenger( 6616): Uncaught exception in binary message listener
E/DartMessenger( 6616): java.lang.IllegalStateException: Reply already submitted
E/DartMessenger( 6616): at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:430)
E/DartMessenger( 6616): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:282)
E/DartMessenger( 6616): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/DartMessenger( 6616): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/DartMessenger( 6616): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/DartMessenger( 6616): at android.os.Handler.handleCallback(Handler.java:938)
E/DartMessenger( 6616): at android.os.Handler.dispatchMessage(Handler.java:99)
E/DartMessenger( 6616): at android.os.Looper.loop(Looper.java:223)
E/DartMessenger( 6616): at android.app.ActivityThread.main(ActivityThread.java:7656)
E/DartMessenger( 6616): at java.lang.reflect.Method.invoke(Native Method)
E/DartMessenger( 6616): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/DartMessenger( 6616): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
I/flutter ( 6616): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 6616): │ #0 FlutterSoundRecorder.openRecorderCompleted (package:flutter_sound/public/flutter_sound_recorder.dart:171:13)
I/flutter ( 6616): │ #1 MethodChannelFlutterSoundRecorder.channelMethodCallHandler (package:flutter_sound_platform_interface/method_channel_flutter_sound_recorder.dart:98:22)
I/flutter ( 6616): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter ( 6616): │ 🐛 ---> openRecorderCompleted: true
I/flutter ( 6616): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 6616): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 6616): │ #0 FlutterSoundRecorder.openRecorderCompleted (package:flutter_sound/public/flutter_sound_recorder.dart:182:13)
I/flutter ( 6616): │ #1 MethodChannelFlutterSoundRecorder.channelMethodCallHandler (package:flutter_sound_platform_interface/method_channel_flutter_sound_recorder.dart:98:22)
I/flutter ( 6616): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter ( 6616): │ 🐛 <--- openRecorderCompleted: true
I/flutter ( 6616): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 6616): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 6616): │ #0 FlutterSoundRecorder._openAudioSession (package:flutter_sound/public/flutter_sound_recorder.dart:412:13)
I/flutter ( 6616): │ #1 <asynchronous suspension>
I/flutter ( 6616): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter ( 6616): │ 🐛 <--- openAudioSession
I/flutter ( 6616): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 6616): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 6616): │ #0 FlutterSoundRecorder.openRecorder (package:flutter_sound/public/flutter_sound_recorder.dart:376:13)
I/flutter ( 6616): │ #1 <asynchronous suspension>
I/flutter ( 6616): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter ( 6616): │ 🐛 FS:<--- openAudioSession
I/flutter ( 6616): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 6616): initialized
I/flutter ( 6616): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 6616): │ #0 FlutterSoundRecorder.startRecorder (package:flutter_sound/public/flutter_sound_recorder.dart:590:13)
I/flutter ( 6616): │ #1 MicrophoneUtils.startRecorder (package:myapp/utils/mic_test.dart:40:10)
I/flutter ( 6616): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter ( 6616): │ 🐛 FS:---> startRecorder
I/flutter ( 6616): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 6616): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 6616): │ #0 FlutterSoundRecorder._startRecorder (package:flutter_sound/public/flutter_sound_recorder.dart:614:13)
I/flutter ( 6616): │ #1 FlutterSoundRecorder.startRecorder.<anonymous closure> (package:flutter_sound/public/flutter_sound_recorder.dart:592:13)
I/flutter ( 6616): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter ( 6616): │ 🐛 FS:---> _startRecorder.
I/flutter ( 6616): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
E/flutter ( 6616): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: PlatformException(startRecorder, startRecorder, Failure to start recorder, null)
E/flutter ( 6616): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter ( 6616): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:167:18)
E/flutter ( 6616): <asynchronous suspension>
E/flutter ( 6616): #2 FlutterSoundRecorder._startRecorder (package:flutter_sound/public/flutter_sound_recorder.dart:671:7)
E/flutter ( 6616): <asynchronous suspension>
E/flutter ( 6616): #3 FlutterSoundRecorder.startRecorder.<anonymous closure> (package:flutter_sound/public/flutter_sound_recorder.dart:592:7)
E/flutter ( 6616): <asynchronous suspension>
E/flutter ( 6616): #4 BasicLock.synchronized (package:synchronized/src/basic_lock.dart:33:16)
E/flutter ( 6616): <asynchronous suspension>
E/flutter ( 6616): #5 FlutterSoundRecorder.startRecorder (package:flutter_sound/public/flutter_sound_recorder.dart:591:5)
E/flutter ( 6616): <asynchronous suspension>
E/flutter ( 6616):
I've just started using flutter_sound, so I think the problem is in my code. Could anyone say how to fix this problem?
Upvotes: 1
Views: 1066
Reputation: 459
The solution is to just import
import 'package:flutter_sound/public/flutter_sound_recorder.dart';
instead of
import 'package:flutter_sound/flutter_sound.dart';
from the same flutter_sound package.
However, I suggest you to use another package for recording audio because flutter_sound seems like an abandoned package.
My choice for now is this record package.
Here is how to implement record package with ease.
Upvotes: 1