I want to build an audio recorder with flutter but I cannot seem to find any way to record the audio played from the device rather than the microphone itself. Is there any way I could do this?
https://pub.dev/packages/flutter_audio_recorder
https://pub.dev/packages/audioplayers
These two packages are useful to achieve audio recoding and playing in flutter.
Here's some code reference-
bool isRecordingStarted = false;
bool isPlaying = false;
FlutterAudioRecorder _recorder;
Recording _recording;
Timer _t;
var recordedAudio;
RecordingStatus _currentStatus = RecordingStatus.Unset;
IconData _recordIcon = Icons.mic_none;
Duration _duration;
Duration _position;
Future _startRecording() async {
await _recorder.start();
var current = await _recorder.current();
setState(() {
_recording = current;
});
_t = Timer.periodic(Duration(milliseconds: 10), (Timer t) async {
var current = await _recorder.current();
setState(() {
_recording = current;
_t = t;
});
});
}
Future _stopRecording() async {
var result = await _recorder.stop();
_t.cancel();
setState(() {
// _recording = result;
_recording = new Recording();
});
print("_recording.path : ${result.path}");
setState(() {
recordedAudio = result.path;
});
// Navigator.pushNamed(context, Screen.AudioPostingView.toString(),
// arguments: {"audioUrl": result.path});
}
///For Audio playing
playLocal() async {
int result = await advancedPlayer.play(recordedAudio, isLocal: true);
// setState(() => playerState = PlayerState.playing);
}
@override
void initState() {
// getLastPost();
_init();
_loadRiveFile();
_prepare();
_getDuration();
// startTimer();
advancedPlayer.onDurationChanged
.listen((d) => setState(() => _duration = d));
// _initAudioPlayer();
super.initState();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.