|
|
|
@ -970,15 +970,15 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
|
|
|
|
|
|
|
//////// Audio Recoding Work ////////////////////
|
|
|
|
//////// Audio Recoding Work ////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> initAudio() async {
|
|
|
|
Future<void> initAudio({required int receiverId}) async {
|
|
|
|
appDirectory = await getApplicationDocumentsDirectory();
|
|
|
|
appDirectory = await getApplicationDocumentsDirectory();
|
|
|
|
path = "${appDirectory.path}/${AppState().chatDetails!.response!.id}-${DateTime.now().microsecondsSinceEpoch}.aac";
|
|
|
|
path = "${appDirectory.path}/${AppState().chatDetails!.response!.id}-$receiverID-${DateTime.now().microsecondsSinceEpoch}.aac";
|
|
|
|
recorderController = RecorderController()
|
|
|
|
recorderController = RecorderController()
|
|
|
|
..androidEncoder = AndroidEncoder.aac
|
|
|
|
..androidEncoder = AndroidEncoder.aac
|
|
|
|
..androidOutputFormat = AndroidOutputFormat.mpeg4
|
|
|
|
..androidOutputFormat = AndroidOutputFormat.mpeg4
|
|
|
|
..iosEncoder = IosEncoder.kAudioFormatMPEG4AAC
|
|
|
|
..iosEncoder = IosEncoder.kAudioFormatMPEG4AAC
|
|
|
|
..sampleRate = 8000
|
|
|
|
..sampleRate = 6000
|
|
|
|
..bitRate = 32000;
|
|
|
|
..bitRate = 18000;
|
|
|
|
playerController = PlayerController();
|
|
|
|
playerController = PlayerController();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -992,7 +992,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
|
|
|
|
|
|
|
void startRecoding() async {
|
|
|
|
void startRecoding() async {
|
|
|
|
PermissionStatus status = await Permission.microphone.request();
|
|
|
|
PermissionStatus status = await Permission.microphone.request();
|
|
|
|
print(status);
|
|
|
|
|
|
|
|
if (status.isDenied == true) {
|
|
|
|
if (status.isDenied == true) {
|
|
|
|
startRecoding();
|
|
|
|
startRecoding();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
@ -1014,6 +1013,15 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void _pauseTimer() {
|
|
|
|
|
|
|
|
_timer?.cancel();
|
|
|
|
|
|
|
|
_timer = Timer.periodic(const Duration(seconds: 1), (Timer t) {
|
|
|
|
|
|
|
|
_recodeDuration++;
|
|
|
|
|
|
|
|
// buildTimer();
|
|
|
|
|
|
|
|
notifyListeners();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> pauseRecoding() async {
|
|
|
|
Future<void> pauseRecoding() async {
|
|
|
|
isPause = true;
|
|
|
|
isPause = true;
|
|
|
|
isPlaying = true;
|
|
|
|
isPlaying = true;
|
|
|
|
@ -1025,6 +1033,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
await playerController.preparePlayer(file.path, 1.0);
|
|
|
|
await playerController.preparePlayer(file.path, 1.0);
|
|
|
|
var tempDuration = _recodeDuration;
|
|
|
|
var tempDuration = _recodeDuration;
|
|
|
|
_recodeDuration = tempDuration;
|
|
|
|
_recodeDuration = tempDuration;
|
|
|
|
|
|
|
|
_pauseTimer();
|
|
|
|
_timer?.cancel();
|
|
|
|
_timer?.cancel();
|
|
|
|
notifyListeners();
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -1077,11 +1086,41 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
|
|
|
|
|
|
|
void playRecoding() async {
|
|
|
|
void playRecoding() async {
|
|
|
|
isPlaying = true;
|
|
|
|
isPlaying = true;
|
|
|
|
await playerController.startPlayer(finishMode: FinishMode.stop);
|
|
|
|
await playerController.startPlayer(finishMode: FinishMode.pause);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void playOrPause() async {
|
|
|
|
void playOrPause() async {
|
|
|
|
playerController.playerState == PlayerState.playing ? await playerController.pausePlayer() : playRecoding();
|
|
|
|
playerController.playerState == PlayerState.playing ? await playerController.pausePlayer() : playRecoding();
|
|
|
|
notifyListeners();
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void sendVoiceMessage(BuildContext context, {required int targetUserId, required int userStatus, required String userEmail, required String targetUserName}) async {
|
|
|
|
|
|
|
|
recorderController.pause();
|
|
|
|
|
|
|
|
path = await recorderController.stop(false);
|
|
|
|
|
|
|
|
print(path);
|
|
|
|
|
|
|
|
File voiceFile = File(path!);
|
|
|
|
|
|
|
|
voiceFile.readAsBytesSync();
|
|
|
|
|
|
|
|
_pauseTimer();
|
|
|
|
|
|
|
|
_timer?.cancel();
|
|
|
|
|
|
|
|
isPause = false;
|
|
|
|
|
|
|
|
isPlaying = false;
|
|
|
|
|
|
|
|
isRecoding = false;
|
|
|
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
|
|
|
dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), voiceFile);
|
|
|
|
|
|
|
|
logger.d(value);
|
|
|
|
|
|
|
|
String? ext = getFileExtension(voiceFile.path);
|
|
|
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
|
|
|
sendChatToServer(
|
|
|
|
|
|
|
|
chatEventId: 2,
|
|
|
|
|
|
|
|
fileTypeId: getFileType(ext.toString()),
|
|
|
|
|
|
|
|
targetUserId: targetUserId,
|
|
|
|
|
|
|
|
targetUserName: targetUserName,
|
|
|
|
|
|
|
|
isAttachment: true,
|
|
|
|
|
|
|
|
chatReplyId: null,
|
|
|
|
|
|
|
|
isReply: false,
|
|
|
|
|
|
|
|
isImageLoaded: true,
|
|
|
|
|
|
|
|
image: voiceFile.readAsBytesSync());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
notifyListeners();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|