9/3/1
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
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';
|
||||
|
||||
@@ -13,12 +12,23 @@ class AudioRecorderController extends GetxController {
|
||||
AudioRecorder recorder = AudioRecorder();
|
||||
|
||||
bool isRecording = false;
|
||||
bool isPlaying = false;
|
||||
bool isPaused = false;
|
||||
String filePath = '';
|
||||
String? selectedFilePath;
|
||||
double currentPosition = 0;
|
||||
double totalDuration = 0;
|
||||
String? selectedFile;
|
||||
|
||||
Future<void> playSoundFromAssets(String sound) async {
|
||||
try {
|
||||
await audioPlayer.setAsset(sound);
|
||||
audioPlayer.play();
|
||||
} catch (e) {
|
||||
print("Error playing sound: $e");
|
||||
}
|
||||
}
|
||||
|
||||
// Start recording
|
||||
Future<void> startRecording() async {
|
||||
final bool isPermissionGranted = await recorder.hasPermission();
|
||||
if (!isPermissionGranted) {
|
||||
@@ -48,26 +58,76 @@ class AudioRecorderController extends GetxController {
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> stopRecording() async {
|
||||
final path = await recorder.stop();
|
||||
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;
|
||||
// Pause recording
|
||||
Future<void> pauseRecording() async {
|
||||
if (isRecording && !isPaused) {
|
||||
await recorder.pause();
|
||||
isPaused = true;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
// Resume recording
|
||||
Future<void> resumeRecording() async {
|
||||
if (isRecording && isPaused) {
|
||||
await recorder.resume();
|
||||
isPaused = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
// Stop recording
|
||||
Future<void> stopRecording() async {
|
||||
await recorder.stop();
|
||||
isRecording = false;
|
||||
isPaused = false;
|
||||
update();
|
||||
}
|
||||
|
||||
// Play the selected recorded file
|
||||
Future<void> playRecordedFile(String filePath) async {
|
||||
await audioPlayer.setFilePath(filePath);
|
||||
totalDuration = audioPlayer.duration?.inSeconds.toDouble() ?? 0;
|
||||
audioPlayer.play();
|
||||
|
||||
isPlaying = true;
|
||||
isPaused = false;
|
||||
audioPlayer.positionStream.listen((position) {
|
||||
currentPosition = position.inSeconds.toDouble();
|
||||
update();
|
||||
});
|
||||
selectedFilePath = filePath;
|
||||
update();
|
||||
}
|
||||
|
||||
// Pause playback
|
||||
Future<void> pausePlayback() async {
|
||||
if (isPlaying && !isPaused) {
|
||||
await audioPlayer.pause();
|
||||
isPaused = true;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
// Resume playback
|
||||
Future<void> resumePlayback() async {
|
||||
if (isPlaying && isPaused) {
|
||||
await audioPlayer.play();
|
||||
isPaused = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
// Stop playback
|
||||
Future<void> stopPlayback() async {
|
||||
await audioPlayer.stop();
|
||||
isPlaying = false;
|
||||
isPaused = false;
|
||||
currentPosition = 0;
|
||||
update();
|
||||
}
|
||||
|
||||
// Get a list of recorded files
|
||||
Future<List<String>> getRecordedFiles() async {
|
||||
final directory = await getApplicationDocumentsDirectory();
|
||||
final files = await directory.list().toList();
|
||||
@@ -77,25 +137,16 @@ class AudioRecorderController extends GetxController {
|
||||
.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();
|
||||
}
|
||||
|
||||
// Delete a specific recorded file
|
||||
Future<void> deleteRecordedFile(String filePath) async {
|
||||
final file = File(filePath);
|
||||
if (await file.exists()) {
|
||||
await file.delete();
|
||||
await getRecordedFiles();
|
||||
} else {}
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
// Delete all recorded files
|
||||
Future<void> deleteAllRecordedFiles() async {
|
||||
final directory = await getApplicationDocumentsDirectory();
|
||||
final files = await directory.list().toList();
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:SEFER/constant/box_name.dart';
|
||||
import 'package:SEFER/constant/info.dart';
|
||||
import 'package:SEFER/constant/links.dart';
|
||||
import 'package:SEFER/controller/auth/login_controller.dart';
|
||||
import 'package:SEFER/env/env.dart';
|
||||
import 'package:SEFER/main.dart';
|
||||
import 'package:SEFER/views/widgets/elevated_btn.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -58,7 +59,7 @@ class SmsEgyptController extends GetxController {
|
||||
);
|
||||
} else {
|
||||
Get.defaultDialog(
|
||||
title: 'You will receive code in sms message'.tr,
|
||||
title: 'You will receive a code in SMS message'.tr,
|
||||
middleText: '',
|
||||
confirm: MyElevatedButton(
|
||||
title: 'OK'.tr,
|
||||
@@ -107,4 +108,52 @@ class SmsEgyptController extends GetxController {
|
||||
headers: headers,
|
||||
);
|
||||
}
|
||||
|
||||
Future sendWhatsAppAuth(String to, String token) async {
|
||||
var headers = {
|
||||
'Authorization': 'Bearer ${Env.whatsapp}',
|
||||
'Content-Type': 'application/json'
|
||||
};
|
||||
var request = http.Request(
|
||||
'POST',
|
||||
Uri.parse(
|
||||
'https://graph.facebook.com/v20.0/${Env.whatappID}/messages'));
|
||||
request.body = json.encode({
|
||||
"messaging_product": "whatsapp",
|
||||
"to": to, //"962798583052",
|
||||
"type": "template",
|
||||
"template": {
|
||||
"name": "sefer1",
|
||||
"language": {"code": "en"},
|
||||
"components": [
|
||||
{
|
||||
"type": "body",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": token,
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
request.headers.addAll(headers);
|
||||
|
||||
http.StreamedResponse response = await request.send();
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
print(await response.stream.bytesToString());
|
||||
Get.defaultDialog(
|
||||
title: 'You will receive a code in WhatsApp Messenger'.tr,
|
||||
middleText: '',
|
||||
confirm: MyElevatedButton(
|
||||
title: 'OK'.tr,
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
}));
|
||||
} else {
|
||||
print(response.reasonPhrase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user