4/23/1
This commit is contained in:
@@ -95,7 +95,7 @@ class LoginController extends GetxController {
|
||||
if (jsonDecoeded.isNotEmpty) {
|
||||
if (jsonDecoeded['status'] == 'success') {
|
||||
print(jsonDecoeded['data'][0]['verified']);
|
||||
if (jsonDecoeded['data'][0]['verified'] == '1') {
|
||||
if (jsonDecoeded['data'][0]['verified'] == 1) {
|
||||
box.write(BoxName.passengerID, jsonDecoeded['data'][0]['id']);
|
||||
box.write(BoxName.email, jsonDecoeded['data'][0]['email']);
|
||||
box.write(
|
||||
|
||||
119
lib/controller/functions/audio_record1.dart
Normal file
119
lib/controller/functions/audio_record1.dart
Normal file
@@ -0,0 +1,119 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:SEFER/controller/home/map_passenger_controller.dart';
|
||||
// import 'package:flutter_sound/flutter_sound.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'package:just_audio/just_audio.dart';
|
||||
import 'package:record/record.dart';
|
||||
|
||||
class AudioRecorderController extends GetxController {
|
||||
AudioPlayer audioPlayer = AudioPlayer();
|
||||
AudioRecorder recorder = AudioRecorder();
|
||||
|
||||
bool isRecording = false;
|
||||
String filePath = '';
|
||||
String? selectedFilePath;
|
||||
double currentPosition = 0;
|
||||
double totalDuration = 0;
|
||||
String? selectedFile;
|
||||
|
||||
Future<void> startRecording() async {
|
||||
final bool isPermissionGranted = await recorder.hasPermission();
|
||||
if (!isPermissionGranted) {
|
||||
// RecordingPermissionException('l');
|
||||
print('sss');
|
||||
return;
|
||||
}
|
||||
|
||||
final directory = await getApplicationDocumentsDirectory();
|
||||
// Generate a unique file name using the current timestamp
|
||||
String fileName =
|
||||
'${DateTime.now().year}-${DateTime.now().month}-${DateTime.now().day}_${Get.find<MapPassengerController>().rideId}.m4a';
|
||||
filePath = '${directory.path}/$fileName';
|
||||
|
||||
// Define the configuration for the recording
|
||||
const config = RecordConfig(
|
||||
// Specify the format, encoder, sample rate, etc., as needed
|
||||
encoder: AudioEncoder.aacLc, // For example, using AAC codec
|
||||
sampleRate: 44100, // Sample rate
|
||||
bitRate: 128000, // Bit rate
|
||||
);
|
||||
|
||||
// Start recording to file with the specified configuration
|
||||
await recorder.start(config, path: filePath);
|
||||
|
||||
isRecording = true;
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> stopRecording() async {
|
||||
final path = await recorder.stop();
|
||||
print(path);
|
||||
isRecording = false;
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> playRecording() async {
|
||||
if (filePath != null) {
|
||||
await audioPlayer.setFilePath(filePath!);
|
||||
totalDuration = audioPlayer.duration?.inSeconds.toDouble() ?? 0;
|
||||
audioPlayer.play();
|
||||
|
||||
audioPlayer.positionStream.listen((position) {
|
||||
currentPosition = position.inSeconds.toDouble();
|
||||
});
|
||||
selectedFilePath = filePath;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<String>> getRecordedFiles() async {
|
||||
final directory = await getApplicationDocumentsDirectory();
|
||||
final files = await directory.list().toList();
|
||||
return files
|
||||
.map((file) => file.path)
|
||||
.where((path) => path.endsWith('.m4a'))
|
||||
.toList();
|
||||
}
|
||||
|
||||
Future<void> playRecordedFile(String filePath) async {
|
||||
await audioPlayer.setFilePath(filePath);
|
||||
totalDuration = audioPlayer.duration?.inSeconds.toDouble() ?? 0;
|
||||
audioPlayer.play();
|
||||
|
||||
audioPlayer.positionStream.listen((position) {
|
||||
currentPosition = position.inSeconds.toDouble();
|
||||
});
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> deleteRecordedFile(String filePath) async {
|
||||
final file = File(filePath);
|
||||
if (await file.exists()) {
|
||||
await file.delete();
|
||||
print('File deleted: $filePath');
|
||||
await getRecordedFiles();
|
||||
} else {
|
||||
print('File not found: $filePath');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteAllRecordedFiles() async {
|
||||
final directory = await getApplicationDocumentsDirectory();
|
||||
final files = await directory.list().toList();
|
||||
for (final file in files) {
|
||||
if (file.path.endsWith('.m4a')) {
|
||||
await deleteRecordedFile(file.path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
audioPlayer.dispose();
|
||||
recorder.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_sound/flutter_sound.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
import '../home/map_passenger_controller.dart';
|
||||
|
||||
class AudioController extends GetxController {
|
||||
final recorder = FlutterSoundRecorder();
|
||||
bool isRecording = false;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
initRecorder();
|
||||
}
|
||||
|
||||
Future<void> initRecorder() async {
|
||||
final status = await Permission.microphone.request();
|
||||
if (status != PermissionStatus.granted) {
|
||||
if (status.isPermanentlyDenied) {
|
||||
// Handle permission permanently denied
|
||||
showPermissionDeniedDialog();
|
||||
} else if (status.isDenied) {
|
||||
// Handle permission denied
|
||||
showPermissionDeniedSnackbar();
|
||||
} else if (status.isRestricted) {
|
||||
// Handle permission restricted
|
||||
// showPermissionDeniedSnackbar();
|
||||
}
|
||||
return;
|
||||
}
|
||||
await recorder.openRecorder();
|
||||
recorder.setSubscriptionDuration(const Duration(minutes: 50));
|
||||
}
|
||||
|
||||
Future<void> startRecording() async {
|
||||
if (!recorder.isStopped) {
|
||||
await recorder.startRecorder();
|
||||
}
|
||||
isRecording = 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
|
||||
isRecording = false;
|
||||
update();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
recorder.stopRecorder();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
void showPermissionDeniedDialog() {
|
||||
showDialog(
|
||||
context: Get.context!,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Microphone Permission'),
|
||||
content:
|
||||
const Text('Microphone permission is required to record audio.'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
openAppSettings();
|
||||
},
|
||||
child: const Text('Open Settings'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void showPermissionDeniedSnackbar() {
|
||||
Get.snackbar(
|
||||
'Microphone Permission',
|
||||
'Microphone permission is required to record audio.',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
duration: const Duration(seconds: 5),
|
||||
mainButton: TextButton(
|
||||
onPressed: () {
|
||||
openAppSettings();
|
||||
},
|
||||
child: const Text(
|
||||
'Open Settings',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:flutter_sound/public/flutter_sound_recorder.dart';
|
||||
// import 'package:get/get.dart';
|
||||
// // import 'package:flutter_sound/flutter_sound.dart';
|
||||
// import 'package:permission_handler/permission_handler.dart';
|
||||
//
|
||||
// class AudioController extends GetxController {
|
||||
// final flutterSoundHelper = FlutterSoundHelper();
|
||||
//
|
||||
// bool isRecording = false;
|
||||
//
|
||||
// Future<void> startRecording() async {
|
||||
// if (!await flutterSoundHelper.hasPermissions()) {
|
||||
// await flutterSoundHelper.requestPermissions();
|
||||
// }
|
||||
//
|
||||
// if (!await flutterSoundHelper.hasPermissions()) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// await flutterSoundHelper.startRecorder();
|
||||
// isRecording = true;
|
||||
// }
|
||||
//
|
||||
// Future<void> stopRecording() async {
|
||||
// if (!isRecording) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// await flutterSoundHelper.stopRecorder();
|
||||
// isRecording = false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// class FlutterSoundHelper {
|
||||
// final flutterSound = FlutterSoundRecorder();
|
||||
//
|
||||
// Future<bool> hasPermissions() async {
|
||||
// return await Permission.microphone.isGranted;
|
||||
// }
|
||||
//
|
||||
// Future<void> requestPermissions() async {
|
||||
// await Permission.microphone.request();
|
||||
// }
|
||||
//
|
||||
// Future<void> startRecorder() async {
|
||||
// await flutterSound.openRecorder();
|
||||
// await flutterSound.startRecorder(toFile: 'audio.wav');
|
||||
// }
|
||||
//
|
||||
// Future<void> stopRecorder() async {
|
||||
// await flutterSound.stopRecorder();
|
||||
// await flutterSound.closeRecorder();
|
||||
// }
|
||||
// }
|
||||
File diff suppressed because it is too large
Load Diff
@@ -98,7 +98,9 @@ class RateController extends GetxController {
|
||||
await CRUD().post(link: AppLink.addDriversWalletPoints, payload: {
|
||||
'driverID': Get.find<MapPassengerController>().driverId.toString(),
|
||||
'paymentID': '${Get.find<MapPassengerController>().rideId}tip',
|
||||
'amount': (tip * 100).toString(),
|
||||
'amount': box.read(BoxName.countryCode) == 'Egypt'
|
||||
? tip.toStringAsFixed(0)
|
||||
: (tip * 100).toString(),
|
||||
'paymentMethod': 'visa-tip',
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user