|
|
|
|
@ -1,13 +1,16 @@
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
|
import 'package:flutter_sound/flutter_sound.dart';
|
|
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
|
|
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
|
import 'package:rive/rive.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/buttons/app_icon_button2.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/buttons/app_small_button.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/sound/sound_player.dart';
|
|
|
|
|
|
|
|
|
|
import 'package:record_mp3/record_mp3.dart';
|
|
|
|
|
import '../../app_style/sizing.dart';
|
|
|
|
|
|
|
|
|
|
class RecordSound extends StatefulWidget {
|
|
|
|
|
@ -21,7 +24,8 @@ class RecordSound extends StatefulWidget {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _RecordSoundState extends State<RecordSound> {
|
|
|
|
|
FlutterSoundRecorder _myRecorder = FlutterSoundRecorder();
|
|
|
|
|
// FlutterSoundRecorder _myRecorder = FlutterSoundRecorder();
|
|
|
|
|
|
|
|
|
|
bool _recorderIsOpened = false;
|
|
|
|
|
bool _recording = false;
|
|
|
|
|
String _record;
|
|
|
|
|
@ -35,10 +39,15 @@ class _RecordSoundState extends State<RecordSound> {
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
_myRecorder.openRecorder().then((value) {
|
|
|
|
|
|
|
|
|
|
_recorderIsOpened = true;
|
|
|
|
|
setState(() {});
|
|
|
|
|
});
|
|
|
|
|
// RecordMp3.instance.start(recordFilePath, (type) {
|
|
|
|
|
// // record fail callback
|
|
|
|
|
// });
|
|
|
|
|
// _myRecorder.openRecorder().then((value) {
|
|
|
|
|
// _recorderIsOpened = true;
|
|
|
|
|
// setState(() {});
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// Load the animation file from the bundle, note that you could also
|
|
|
|
|
// download this. The RiveFile just expects a list of bytes.
|
|
|
|
|
@ -62,11 +71,14 @@ class _RecordSoundState extends State<RecordSound> {
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
// Be careful : you must `close` the audio session when you have finished with it.
|
|
|
|
|
_myRecorder.closeRecorder();
|
|
|
|
|
_myRecorder = null;
|
|
|
|
|
RecordMp3.instance.stop();
|
|
|
|
|
//_myRecorder.closeRecorder();
|
|
|
|
|
// _myRecorder = null;
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String recordingFileDirectory;
|
|
|
|
|
|
|
|
|
|
_startRecording() async {
|
|
|
|
|
// await Permission.camera
|
|
|
|
|
PermissionStatus status = await Permission.microphone.request();
|
|
|
|
|
@ -79,11 +91,16 @@ class _RecordSoundState extends State<RecordSound> {
|
|
|
|
|
}
|
|
|
|
|
_rive.addController(SimpleAnimation('recording'));
|
|
|
|
|
if (!_recorderIsOpened) {
|
|
|
|
|
await _myRecorder.openRecorder();
|
|
|
|
|
// await _myRecorder.openRecorder();
|
|
|
|
|
_recorderIsOpened = true;
|
|
|
|
|
}
|
|
|
|
|
final Directory tempDir = await getTemporaryDirectory();
|
|
|
|
|
recordingFileDirectory = "${tempDir.path}/record_${DateTime.now().millisecondsSinceEpoch}.mp3";
|
|
|
|
|
RecordMp3.instance.start(recordingFileDirectory, (type) {
|
|
|
|
|
// record fail callback
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await _myRecorder.startRecorder(toFile: "record_${DateTime.now().millisecondsSinceEpoch}.mp4", codec: Codec.aacMP4, sampleRate: 360000, bitRate: 360000);
|
|
|
|
|
// await _myRecorder.startRecorder(toFile: "record_${DateTime.now().millisecondsSinceEpoch}.mp3", codec: Codec.aacADTS, sampleRate: 360000, bitRate: 360000);
|
|
|
|
|
|
|
|
|
|
_recording = true;
|
|
|
|
|
setState(() {});
|
|
|
|
|
@ -94,17 +111,21 @@ class _RecordSoundState extends State<RecordSound> {
|
|
|
|
|
setState(() {});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
String path = (await _myRecorder.stopRecorder()).toString();
|
|
|
|
|
_record = path;
|
|
|
|
|
widget.onRecord(path);
|
|
|
|
|
|
|
|
|
|
RecordMp3.instance.stop();
|
|
|
|
|
|
|
|
|
|
//String path = (await _myRecorder.stopRecorder()).toString();
|
|
|
|
|
_record = recordingFileDirectory;
|
|
|
|
|
widget.onRecord(recordingFileDirectory);
|
|
|
|
|
_recording = false;
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cancelRecording() async {
|
|
|
|
|
if (!_recording) return;
|
|
|
|
|
String path = await _myRecorder.stopRecorder();
|
|
|
|
|
_myRecorder.deleteRecord(fileName: path);
|
|
|
|
|
RecordMp3.instance.stop();
|
|
|
|
|
// String path = await _myRecorder.stopRecorder();
|
|
|
|
|
// _myRecorder.deleteRecord(fileName: path);
|
|
|
|
|
_rive.addController(SimpleAnimation('delete'));
|
|
|
|
|
|
|
|
|
|
// rebuild();
|
|
|
|
|
|