diff --git a/lib/classes/consts.dart b/lib/classes/consts.dart index 52d0407..4a7d7fe 100644 --- a/lib/classes/consts.dart +++ b/lib/classes/consts.dart @@ -3,8 +3,8 @@ import 'package:mohem_flutter_app/ui/marathon/widgets/question_card.dart'; class ApiConsts { //static String baseUrl = "http://10.200.204.20:2801/"; // Local server // static String baseUrl = "https://erptstapp.srca.org.sa"; // SRCA server - static String baseUrl = "https://uat.hmgwebservices.com"; // UAT server - // static String baseUrl = "https://hmgwebservices.com"; // Live server + //static String baseUrl = "https://uat.hmgwebservices.com"; // UAT server + static String baseUrl = "https://hmgwebservices.com"; // Live server static String baseUrlServices = baseUrl + "/Services/"; // server // static String baseUrlServices = "https://api.cssynapses.com/tangheem/"; // Live server static String utilitiesRest = baseUrlServices + "Utilities.svc/REST/"; diff --git a/lib/provider/chat_provider_model.dart b/lib/provider/chat_provider_model.dart index 5f7bf0e..becf4dd 100644 --- a/lib/provider/chat_provider_model.dart +++ b/lib/provider/chat_provider_model.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; import 'dart:typed_data'; + import 'package:audio_waveforms/audio_waveforms.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/cupertino.dart'; @@ -11,7 +12,6 @@ import 'package:http/http.dart'; import 'package:just_audio/just_audio.dart' as JustAudio; import 'package:mohem_flutter_app/api/chat/chat_api_client.dart'; import 'package:mohem_flutter_app/app_state/app_state.dart'; -import 'package:mohem_flutter_app/classes/app_permissions.dart'; import 'package:mohem_flutter_app/classes/consts.dart'; import 'package:mohem_flutter_app/classes/encryption.dart'; import 'package:mohem_flutter_app/classes/utils.dart'; @@ -1292,14 +1292,19 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { File file = File(path!); file.readAsBytesSync(); Utils.hideLoading(context); - await playerController.preparePlayer(file.path, 1.0); + await data.voiceController!.preparePlayer(file.path, 1.0); + data.voiceController!.startPlayer(finishMode: FinishMode.pause); notifyListeners(); - playerController.startPlayer(finishMode: FinishMode.pause); } catch (e) { Utils.showToast("Cannot open file."); } } + void stopPlaying(BuildContext context, {required SingleUserChatModel data}) async { + data.voiceController!.stopPlayer(); + notifyListeners(); + } + Future downChatVoice(Uint8List bytes, String ext, SingleUserChatModel data) async { String dirPath = '${(await getApplicationDocumentsDirectory()).path}/chat_audios'; if (!await Directory(dirPath).exists()) { diff --git a/lib/ui/chat/chat_bubble.dart b/lib/ui/chat/chat_bubble.dart index 9f0396a..d6a6abe 100644 --- a/lib/ui/chat/chat_bubble.dart +++ b/lib/ui/chat/chat_bubble.dart @@ -118,7 +118,11 @@ class ChatBubble extends StatelessWidget { ).paddingOnly(bottom: 4), if (fileTypeID == 13) currentWaveBubble(context, cItem).onPress(() { - data.playVoice(context, data: cItem); + if(cItem.voiceController!.playerState == PlayerState.playing){ + data.stopPlaying(context, data: cItem); + }else{ + data.playVoice(context, data: cItem); + } }) else Row( @@ -203,7 +207,8 @@ class ChatBubble extends StatelessWidget { ], ), ), - ).paddingOnly(bottom: 7).onPress(() {}), + ).paddingOnly(bottom: 7).onPress(() { + }), if (fileTypeID == 12 || fileTypeID == 4 || fileTypeID == 3) ClipRRect( borderRadius: BorderRadius.circular(5.0), @@ -221,7 +226,12 @@ class ChatBubble extends StatelessWidget { ).paddingOnly(bottom: 4), if (fileTypeID == 13) recipetWaveBubble(context, cItem).onPress(() { - data.playVoice(context, data: cItem); + if(cItem.voiceController!.playerState == PlayerState.playing){ + data.stopPlaying(context, data: cItem); + }else{ + data.playVoice(context, data: cItem); + } + }) else Row( @@ -310,8 +320,8 @@ class ChatBubble extends StatelessWidget { child: Row( mainAxisSize: MainAxisSize.max, children: [ - const Icon( - Icons.play_arrow, + Icon( + data.voiceController!.playerState == PlayerState.playing ? Icons.stop_circle : Icons.play_arrow, color: MyColors.lightGreenColor, ).paddingAll(10), AudioFileWaveforms( @@ -338,7 +348,6 @@ class ChatBubble extends StatelessWidget { } Widget recipetWaveBubble(BuildContext context, SingleUserChatModel data) { - PlayerController repController = PlayerController(); return Container( margin: const EdgeInsets.all(0), decoration: BoxDecoration( @@ -359,8 +368,8 @@ class ChatBubble extends StatelessWidget { child: Row( mainAxisSize: MainAxisSize.max, children: [ - const Icon( - Icons.play_arrow, + Icon( + data.voiceController!.playerState == PlayerState.playing ? Icons.stop_circle : Icons.play_arrow, color: MyColors.white, ).paddingAll(10), AudioFileWaveforms(