|  |  |  | @ -12,6 +12,7 @@ import 'package:mohem_flutter_app/classes/utils.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/extensions/int_extensions.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/extensions/string_extensions.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/extensions/widget_extensions.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/main.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/models/chat/get_single_user_chat_list_model.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/provider/chat_provider_model.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/ui/chat/chat_full_image_preview.dart'; | 
		
	
	
		
			
				
					|  |  |  | @ -56,35 +57,70 @@ class ChatBubble extends StatelessWidget { | 
		
	
		
			
				|  |  |  |  |     userName = AppState().chatDetails!.response!.userName == cItem.currentUserName.toString() ? "You" : cItem.currentUserName.toString(); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<String> getCurrentUrl(String url)async{ | 
		
	
		
			
				|  |  |  |  |     if(Platform.isIOS){ | 
		
	
		
			
				|  |  |  |  |       String a = url.substring(url.indexOf("Documents/") + 10, url.length) ; | 
		
	
		
			
				|  |  |  |  |       Directory dir = await getApplicationDocumentsDirectory(); | 
		
	
		
			
				|  |  |  |  |       a = "${dir.path}/$a"; | 
		
	
		
			
				|  |  |  |  |       return a; | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |     else{ | 
		
	
		
			
				|  |  |  |  |       return url; | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   void playVoice( | 
		
	
		
			
				|  |  |  |  |     BuildContext context, { | 
		
	
		
			
				|  |  |  |  |     required SingleUserChatModel data, | 
		
	
		
			
				|  |  |  |  |   }) async { | 
		
	
		
			
				|  |  |  |  |     if (data.voice != null && data.voice!.existsSync()) { | 
		
	
		
			
				|  |  |  |  |       await data.voiceController!.setFilePath(data!.voice!.path); | 
		
	
		
			
				|  |  |  |  |       await data.voiceController!.setLoopMode(LoopMode.off); | 
		
	
		
			
				|  |  |  |  |       Duration? duration = await data.voiceController!.load(); | 
		
	
		
			
				|  |  |  |  |       await data.voiceController!.seek(duration); | 
		
	
		
			
				|  |  |  |  |       await data.voiceController!.play(); | 
		
	
		
			
				|  |  |  |  |     } else { | 
		
	
		
			
				|  |  |  |  |       Utils.showLoading(context); | 
		
	
		
			
				|  |  |  |  |       Uint8List encodedString = await ChatApiClient().downloadURL(fileName: data.contant!, fileTypeDescription: provider.getFileTypeDescription(data.fileTypeResponse!.fileTypeName ?? "")); | 
		
	
		
			
				|  |  |  |  |       try { | 
		
	
		
			
				|  |  |  |  |         String path = await provider.downChatVoice(encodedString, data.fileTypeResponse!.fileTypeName ?? "", data); | 
		
	
		
			
				|  |  |  |  |         File file = File(path!); | 
		
	
		
			
				|  |  |  |  |         await file.readAsBytes(); | 
		
	
		
			
				|  |  |  |  |         data.voice = file; | 
		
	
		
			
				|  |  |  |  |         Duration? duration = await data.voiceController!.setFilePath(file.path); | 
		
	
		
			
				|  |  |  |  |         await data.voiceController!.setLoopMode(LoopMode.off); | 
		
	
		
			
				|  |  |  |  |       if (Platform.isIOS) { | 
		
	
		
			
				|  |  |  |  |         Duration? duration = await data.voiceController!.setAudioSource(MyCustomStream(data.voice!.readAsBytesSync())); | 
		
	
		
			
				|  |  |  |  |         await data.voiceController!.seek(duration); | 
		
	
		
			
				|  |  |  |  |         await data.voiceController!.setLoopMode(LoopMode.off); | 
		
	
		
			
				|  |  |  |  |         await data.voiceController!.setVolume(1.0); | 
		
	
		
			
				|  |  |  |  |         await data.voiceController!.load(); | 
		
	
		
			
				|  |  |  |  |         Utils.hideLoading(context); | 
		
	
		
			
				|  |  |  |  |         data.voiceController!.play(); | 
		
	
		
			
				|  |  |  |  |       } else { | 
		
	
		
			
				|  |  |  |  |         await data.voiceController!.setFilePath(data!.voice!.path); | 
		
	
		
			
				|  |  |  |  |         Duration? duration = await data.voiceController!.load(); | 
		
	
		
			
				|  |  |  |  |         await data.voiceController!.seek(duration); | 
		
	
		
			
				|  |  |  |  |         await data.voiceController!.setLoopMode(LoopMode.off); | 
		
	
		
			
				|  |  |  |  |         await data.voiceController!.play(); | 
		
	
		
			
				|  |  |  |  |       } catch (e) { | 
		
	
		
			
				|  |  |  |  |         Utils.hideLoading(context); | 
		
	
		
			
				|  |  |  |  |         Utils.showToast(e.toString()); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     } else { | 
		
	
		
			
				|  |  |  |  |       Utils.showLoading(context); | 
		
	
		
			
				|  |  |  |  |       Uint8List encodedString = await ChatApiClient().downloadURL(fileName: data.contant!, fileTypeDescription: provider.getFileTypeDescription(data.fileTypeResponse!.fileTypeName ?? "")); | 
		
	
		
			
				|  |  |  |  |      // try { | 
		
	
		
			
				|  |  |  |  |         File sFile = await provider.downChatVoice(encodedString, data.fileTypeResponse!.fileTypeName ?? "", data); | 
		
	
		
			
				|  |  |  |  |         if(sFile.path.isEmpty){ | 
		
	
		
			
				|  |  |  |  |           logger.d("Path Is Emptyyyyyyy"); | 
		
	
		
			
				|  |  |  |  |         }else{ | 
		
	
		
			
				|  |  |  |  |           logger.d("Path Exsists"); | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |         data.voice = sFile; | 
		
	
		
			
				|  |  |  |  |         if (Platform.isIOS) { | 
		
	
		
			
				|  |  |  |  |           logger.d("isIOS"); | 
		
	
		
			
				|  |  |  |  |           Duration? duration = await data.voiceController!.setAudioSource(MyCustomStream(data.voice!.readAsBytesSync())); | 
		
	
		
			
				|  |  |  |  |           await data.voiceController!.seek(duration); | 
		
	
		
			
				|  |  |  |  |           await data.voiceController!.setLoopMode(LoopMode.off); | 
		
	
		
			
				|  |  |  |  |           await data.voiceController!.setVolume(1.0); | 
		
	
		
			
				|  |  |  |  |         await data.voiceController!.load(); | 
		
	
		
			
				|  |  |  |  |           Utils.hideLoading(context); | 
		
	
		
			
				|  |  |  |  |           data.voiceController!.play(); | 
		
	
		
			
				|  |  |  |  |         } else { | 
		
	
		
			
				|  |  |  |  |           Duration? duration = await data.voiceController!.setFilePath(sFile.path); | 
		
	
		
			
				|  |  |  |  |           await data.voiceController!.setLoopMode(LoopMode.off); | 
		
	
		
			
				|  |  |  |  |           await data.voiceController!.seek(duration); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |           Utils.hideLoading(context); | 
		
	
		
			
				|  |  |  |  |           await data.voiceController!.play(); | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       // } catch (e) { | 
		
	
		
			
				|  |  |  |  |       //   Utils.hideLoading(context); | 
		
	
		
			
				|  |  |  |  |       //   Utils.showToast(e.toString()); | 
		
	
		
			
				|  |  |  |  |       // } | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
	
		
			
				
					|  |  |  | @ -439,3 +475,23 @@ class ChatBubble extends StatelessWidget { | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | // Feed your own stream of bytes into the player | 
		
	
		
			
				|  |  |  |  | class MyCustomStream extends StreamAudioSource { | 
		
	
		
			
				|  |  |  |  |   final Uint8List bytes; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   MyCustomStream(this.bytes); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   @override | 
		
	
		
			
				|  |  |  |  |   Future<StreamAudioResponse> request([int? start, int? end]) async { | 
		
	
		
			
				|  |  |  |  |     start ??= 0; | 
		
	
		
			
				|  |  |  |  |     end ??= bytes.length; | 
		
	
		
			
				|  |  |  |  |     return StreamAudioResponse( | 
		
	
		
			
				|  |  |  |  |       sourceLength: bytes.length, | 
		
	
		
			
				|  |  |  |  |       contentLength: end - start, | 
		
	
		
			
				|  |  |  |  |       offset: start, | 
		
	
		
			
				|  |  |  |  |       stream: Stream.value(bytes.sublist(start, end)), | 
		
	
		
			
				|  |  |  |  |       contentType: 'audio/aac', | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | } | 
		
	
	
		
			
				
					|  |  |  | 
 |