feat: Convert opus to aac on iOS before playing

This commit is contained in:
Krille 2024-08-04 15:00:23 +02:00
commit 0bd61ced3f
No known key found for this signature in database
GPG key ID: E067ECD60F1A0652
6 changed files with 59 additions and 4 deletions

View file

@ -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<AudioPlayerWidget> {
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<File>();
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(() {