step 7 : convert .aac into .mp3
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:ffmpeg_kit_flutter_audio/ffmpeg_kit.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
@@ -64,6 +65,7 @@ class RekamScreen extends HookConsumerWidget {
|
||||
try {
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final filePath = '${dir.path}/myFile.aac';
|
||||
// final filePath = '${dir.path}/myFile.mp3';
|
||||
audioPath.value = filePath;
|
||||
|
||||
await recorder.value.startRecorder(
|
||||
@@ -77,6 +79,22 @@ class RekamScreen extends HookConsumerWidget {
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> convertToMp3(String inputPath) async {
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final outputPath = "${dir.path}/output.mp3";
|
||||
|
||||
// Jalankan perintah FFmpeg untuk konversi
|
||||
await FFmpegKit.execute(
|
||||
'-i $inputPath -codec:a libmp3lame -qscale:a 2 $outputPath');
|
||||
|
||||
// Pastikan file MP3 berhasil dibuat
|
||||
if (File(outputPath).existsSync()) {
|
||||
return outputPath;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> berhentiRekaman() async {
|
||||
try {
|
||||
await recorder.value.stopRecorder();
|
||||
@@ -84,6 +102,15 @@ class RekamScreen extends HookConsumerWidget {
|
||||
isRekam.value = false;
|
||||
|
||||
// panggil fungsi untuk kirim ke BE
|
||||
if (audioPath.value.isNotEmpty) {
|
||||
String? mp3Path = await convertToMp3(audioPath.value);
|
||||
if (mp3Path != null) {
|
||||
// await uploadAudioFile(mp3Path);
|
||||
print('mp3 convert $mp3Path');
|
||||
} else {
|
||||
print("Konversi gagal!");
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print("Error stop record ${e.toString()}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user