Merge pull request #1262 from krille-chan/krille/convert-ogg-to-aac-on-ios
feat: Convert opus to aac on iOS before playing
This commit is contained in:
commit
be0fbd5ab0
7 changed files with 32 additions and 7 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
# Uncomment this line to define a global platform for your project
|
# 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.
|
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
|
||||||
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
|
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
|
||||||
|
|
|
||||||
|
|
@ -475,7 +475,7 @@
|
||||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 12.1;
|
||||||
MTL_ENABLE_DEBUG_INFO = NO;
|
MTL_ENABLE_DEBUG_INFO = NO;
|
||||||
SDKROOT = iphoneos;
|
SDKROOT = iphoneos;
|
||||||
SUPPORTED_PLATFORMS = iphoneos;
|
SUPPORTED_PLATFORMS = iphoneos;
|
||||||
|
|
@ -564,7 +564,7 @@
|
||||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 12.1;
|
||||||
MTL_ENABLE_DEBUG_INFO = YES;
|
MTL_ENABLE_DEBUG_INFO = YES;
|
||||||
ONLY_ACTIVE_ARCH = YES;
|
ONLY_ACTIVE_ARCH = YES;
|
||||||
SDKROOT = iphoneos;
|
SDKROOT = iphoneos;
|
||||||
|
|
@ -613,7 +613,7 @@
|
||||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 12.1;
|
||||||
MTL_ENABLE_DEBUG_INFO = NO;
|
MTL_ENABLE_DEBUG_INFO = NO;
|
||||||
SDKROOT = iphoneos;
|
SDKROOT = iphoneos;
|
||||||
SUPPORTED_PLATFORMS = iphoneos;
|
SUPPORTED_PLATFORMS = iphoneos;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:just_audio/just_audio.dart';
|
import 'package:just_audio/just_audio.dart';
|
||||||
import 'package:matrix/matrix.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:path_provider/path_provider.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/utils/error_reporter.dart';
|
import 'package:fluffychat/utils/error_reporter.dart';
|
||||||
|
|
@ -70,7 +71,18 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
||||||
widget.event.attachmentOrThumbnailMxcUrl()!.pathSegments.last,
|
widget.event.attachmentOrThumbnailMxcUrl()!.pathSegments.last,
|
||||||
);
|
);
|
||||||
file = File('${tempDir.path}/${fileName}_${matrixFile.name}');
|
file = File('${tempDir.path}/${fileName}_${matrixFile.name}');
|
||||||
|
|
||||||
await file.writeAsBytes(matrixFile.bytes);
|
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(() {
|
setState(() {
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
import 'events/audio_player.dart';
|
import 'events/audio_player.dart';
|
||||||
|
|
||||||
class RecordingDialog extends StatefulWidget {
|
class RecordingDialog extends StatefulWidget {
|
||||||
static const String recordingFileType = 'm4a';
|
|
||||||
const RecordingDialog({
|
const RecordingDialog({
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
|
@ -36,9 +35,11 @@ class RecordingDialogState extends State<RecordingDialog> {
|
||||||
|
|
||||||
Future<void> startRecording() async {
|
Future<void> startRecording() async {
|
||||||
try {
|
try {
|
||||||
|
final useOpus =
|
||||||
|
await _audioRecorder.isEncoderSupported(AudioEncoder.opus);
|
||||||
final tempDir = await getTemporaryDirectory();
|
final tempDir = await getTemporaryDirectory();
|
||||||
final path = _recordedPath =
|
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();
|
final result = await _audioRecorder.hasPermission();
|
||||||
if (result != true) {
|
if (result != true) {
|
||||||
|
|
@ -46,14 +47,16 @@ class RecordingDialogState extends State<RecordingDialog> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await WakelockPlus.enable();
|
await WakelockPlus.enable();
|
||||||
|
|
||||||
await _audioRecorder.start(
|
await _audioRecorder.start(
|
||||||
const RecordConfig(
|
RecordConfig(
|
||||||
bitRate: bitRate,
|
bitRate: bitRate,
|
||||||
sampleRate: samplingRate,
|
sampleRate: samplingRate,
|
||||||
numChannels: 1,
|
numChannels: 1,
|
||||||
autoGain: true,
|
autoGain: true,
|
||||||
echoCancel: true,
|
echoCancel: true,
|
||||||
noiseSuppress: true,
|
noiseSuppress: true,
|
||||||
|
encoder: useOpus ? AudioEncoder.opus : AudioEncoder.aacLc,
|
||||||
),
|
),
|
||||||
path: path,
|
path: path,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ permittedLicenses:
|
||||||
- BSD-2-Clause
|
- BSD-2-Clause
|
||||||
- BSD-3-Clause
|
- BSD-3-Clause
|
||||||
- EUPL-1.2
|
- EUPL-1.2
|
||||||
|
- LGPL-3.0
|
||||||
- MIT
|
- MIT
|
||||||
- MPL-2.0
|
- MPL-2.0
|
||||||
- Zlib
|
- Zlib
|
||||||
|
|
|
||||||
|
|
@ -1278,6 +1278,14 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.3"
|
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:
|
package_config:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@ dependencies:
|
||||||
linkify: ^5.0.0
|
linkify: ^5.0.0
|
||||||
matrix: ^0.31.0
|
matrix: ^0.31.0
|
||||||
native_imaging: ^0.1.1
|
native_imaging: ^0.1.1
|
||||||
|
opus_caf_converter_dart: ^1.0.1
|
||||||
package_info_plus: ^6.0.0
|
package_info_plus: ^6.0.0
|
||||||
pasteboard: ^0.2.0
|
pasteboard: ^0.2.0
|
||||||
path: ^1.9.0
|
path: ^1.9.0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue