diff --git a/ios/Podfile b/ios/Podfile index c8df069d3..1f9db6f6e 100644 --- a/ios/Podfile +++ b/ios/Podfile @@ -1,5 +1,5 @@ # Uncomment this line to define a global platform for your project -platform :ios, '12.0' +platform :ios, '12.1' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 8d75b924a..9d57b73aa 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -475,7 +475,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.1; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -564,7 +564,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.1; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -613,7 +613,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.1; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; diff --git a/lib/pages/chat/events/audio_player.dart b/lib/pages/chat/events/audio_player.dart index 40d4cf29f..430bac2d7 100644 --- a/lib/pages/chat/events/audio_player.dart +++ b/lib/pages/chat/events/audio_player.dart @@ -6,6 +6,7 @@ import 'package:flutter/material.dart'; import 'package:just_audio/just_audio.dart'; import 'package:matrix/matrix.dart'; +import 'package:opus_caf_converter_dart/opus_caf_converter_dart.dart'; import 'package:path_provider/path_provider.dart'; import 'package:fluffychat/utils/error_reporter.dart'; @@ -70,7 +71,18 @@ class AudioPlayerState extends State { widget.event.attachmentOrThumbnailMxcUrl()!.pathSegments.last, ); file = File('${tempDir.path}/${fileName}_${matrixFile.name}'); + await file.writeAsBytes(matrixFile.bytes); + + if (Platform.isIOS && + matrixFile.mimeType.toLowerCase() == 'audio/ogg') { + Logs().v('Convert ogg audio file for iOS...'); + final convertedFile = File('${file.path}.caf'); + if (await convertedFile.exists() == false) { + OpusCaf().convertOpusToCaf(file.path, convertedFile.path); + } + file = convertedFile; + } } setState(() { diff --git a/lib/pages/chat/recording_dialog.dart b/lib/pages/chat/recording_dialog.dart index bc92f3ff5..be22ff308 100644 --- a/lib/pages/chat/recording_dialog.dart +++ b/lib/pages/chat/recording_dialog.dart @@ -13,7 +13,6 @@ import 'package:fluffychat/utils/platform_infos.dart'; import 'events/audio_player.dart'; class RecordingDialog extends StatefulWidget { - static const String recordingFileType = 'm4a'; const RecordingDialog({ super.key, }); @@ -36,9 +35,11 @@ class RecordingDialogState extends State { Future startRecording() async { try { + final useOpus = + await _audioRecorder.isEncoderSupported(AudioEncoder.opus); final tempDir = await getTemporaryDirectory(); final path = _recordedPath = - '${tempDir.path}/recording${DateTime.now().microsecondsSinceEpoch}.${RecordingDialog.recordingFileType}'; + '${tempDir.path}/recording${DateTime.now().microsecondsSinceEpoch}.${useOpus ? 'ogg' : 'm4a'}'; final result = await _audioRecorder.hasPermission(); if (result != true) { @@ -46,14 +47,16 @@ class RecordingDialogState extends State { return; } await WakelockPlus.enable(); + await _audioRecorder.start( - const RecordConfig( + RecordConfig( bitRate: bitRate, sampleRate: samplingRate, numChannels: 1, autoGain: true, echoCancel: true, noiseSuppress: true, + encoder: useOpus ? AudioEncoder.opus : AudioEncoder.aacLc, ), path: path, ); diff --git a/licenses.yaml b/licenses.yaml index 7b2f79bbf..ebab43440 100644 --- a/licenses.yaml +++ b/licenses.yaml @@ -12,6 +12,7 @@ permittedLicenses: - BSD-2-Clause - BSD-3-Clause - EUPL-1.2 + - LGPL-3.0 - MIT - MPL-2.0 - Zlib diff --git a/pubspec.lock b/pubspec.lock index c46a3944f..0979b4a90 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1278,6 +1278,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.3" + opus_caf_converter_dart: + dependency: "direct main" + description: + name: opus_caf_converter_dart + sha256: e08156066916f790a54df305e103d6dec4d853ec23147e6a02eda3c06f67ba1a + url: "https://pub.dev" + source: hosted + version: "1.0.1" package_config: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 69c80d6e1..9d00c0d9d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -66,6 +66,7 @@ dependencies: linkify: ^5.0.0 matrix: ^0.31.0 native_imaging: ^0.1.1 + opus_caf_converter_dart: ^1.0.1 package_info_plus: ^6.0.0 pasteboard: ^0.2.0 path: ^1.9.0