This commit is contained in:
Hamza Aleghwairyeen
2024-04-07 04:29:28 +03:00
parent 5624cb9a2f
commit 6276c82c1c
6 changed files with 125 additions and 20 deletions

View File

@@ -0,0 +1,49 @@
import 'dart:io';
import 'package:SEFER/controller/home/captin/map_driver_controller.dart';
import 'package:flutter_sound/flutter_sound.dart';
import 'package:get/get.dart';
import 'package:permission_handler/permission_handler.dart';
class AudioController extends GetxController {
final recorder = FlutterSoundRecorder();
bool isRecoding = false;
@override
void onInit() {
super.onInit();
initRecorder();
}
Future<void> initRecorder() async {
final status = await Permission.microphone.request();
if (status != PermissionStatus.granted) {
// Handle permission denied
return;
}
await recorder.openRecorder();
recorder.setSubscriptionDuration(const Duration(milliseconds: 500));
}
Future<void> startRecording() async {
await recorder.startRecorder(
toFile:
'audio_${Get.find<MapDriverController>().rideId}.wav'); // Specify the file name
isRecoding = true;
update();
}
Future<void> stopRecording() async {
final filePath = await recorder.stopRecorder();
final audioFile = File(filePath!);
print('Recorded file path: $audioFile');
// Now you can send this file to the server
isRecoding = false;
update();
}
@override
void onClose() {
recorder.closeRecorder();
super.onClose();
}
}