From 0bd61ced3fbb0cfd970a2fb23eef7fbd6676872c Mon Sep 17 00:00:00 2001 From: Krille Date: Sun, 4 Aug 2024 15:00:23 +0200 Subject: [PATCH] feat: Convert opus to aac on iOS before playing --- ios/Podfile | 2 +- ios/Runner.xcodeproj/project.pbxproj | 6 ++-- lib/pages/chat/events/audio_player.dart | 28 +++++++++++++++++++ macos/Flutter/GeneratedPluginRegistrant.swift | 2 ++ pubspec.lock | 24 ++++++++++++++++ pubspec.yaml | 1 + 6 files changed, 59 insertions(+), 4 deletions(-) diff --git a/ios/Podfile b/ios/Podfile index c8df069d..1f9db6f6 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 8d75b924..9d57b73a 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 40d4cf29..a3de4e02 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:nyx_converter/nyx_converter.dart'; import 'package:path_provider/path_provider.dart'; import 'package:fluffychat/utils/error_reporter.dart'; @@ -70,7 +71,34 @@ 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}.aac'); + if (await convertedFile.exists()) { + file = convertedFile; + } else { + final completer = Completer(); + NyxConverter.convertTo( + file.path, + tempDir.path, + fileName: '${fileName}_${matrixFile.name}', + container: NyxContainer.aac, + execution: ( + String? path, + NyxStatus status, { + String? errorMessage, + }) { + if (path != null) completer.complete(File(path)); + if (errorMessage != null) completer.completeError(errorMessage); + }, + ); + file = await completer.future; + } + } } setState(() { diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 50894732..552a22ed 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -11,6 +11,7 @@ import desktop_drop import device_info_plus import dynamic_color import emoji_picker_flutter +import ffmpeg_kit_flutter_full_gpl import file_selector_macos import flutter_app_badger import flutter_local_notifications @@ -42,6 +43,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin")) DynamicColorPlugin.register(with: registry.registrar(forPlugin: "DynamicColorPlugin")) EmojiPickerFlutterPlugin.register(with: registry.registrar(forPlugin: "EmojiPickerFlutterPlugin")) + FFmpegKitFlutterPlugin.register(with: registry.registrar(forPlugin: "FFmpegKitFlutterPlugin")) FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin")) FlutterAppBadgerPlugin.register(with: registry.registrar(forPlugin: "FlutterAppBadgerPlugin")) FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin")) diff --git a/pubspec.lock b/pubspec.lock index c46a3944..98e3900c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -385,6 +385,22 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.2" + ffmpeg_kit_flutter_full_gpl: + dependency: transitive + description: + name: ffmpeg_kit_flutter_full_gpl + sha256: "4f269bcb636bfcb544e5b4d65c706a3d311839970cb42638e72406410c1b5b7b" + url: "https://pub.dev" + source: hosted + version: "6.0.3" + ffmpeg_kit_flutter_platform_interface: + dependency: transitive + description: + name: ffmpeg_kit_flutter_platform_interface + sha256: addf046ae44e190ad0101b2fde2ad909a3cd08a2a109f6106d2f7048b7abedee + url: "https://pub.dev" + source: hosted + version: "0.2.1" file: dependency: transitive description: @@ -1270,6 +1286,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.2" + nyx_converter: + dependency: "direct main" + description: + name: nyx_converter + sha256: "29684f29a650119f0417f7faa736c5b8ac65e5b32dbae40412bd6c3d7a692fc7" + url: "https://pub.dev" + source: hosted + version: "0.1.1" olm: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 69c80d6e..ac334197 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 + nyx_converter: ^0.1.1 package_info_plus: ^6.0.0 pasteboard: ^0.2.0 path: ^1.9.0