feat: Convert opus to aac on iOS before playing
This commit is contained in:
parent
6a776b068d
commit
0bd61ced3f
6 changed files with 59 additions and 4 deletions
|
|
@ -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(() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue