step 11 : play and pause rekaman dan slicing edit screen
This commit is contained in:
@@ -84,78 +84,6 @@ class RekamScreen extends HookConsumerWidget {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> jalankanRekaman() async {
|
||||
try {
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final filePath = '${dir.path}/myFile.aac';
|
||||
// final filePath = '${dir.path}/myFile.mp3';
|
||||
audioPath.value = filePath;
|
||||
|
||||
await recorder.value.startRecorder(
|
||||
toFile: filePath,
|
||||
);
|
||||
|
||||
judulTombol.value = "SELESAI";
|
||||
isSelesaiRekam.value = true;
|
||||
} catch (e) {
|
||||
print("Error start record ${e.toString()}");
|
||||
}
|
||||
}
|
||||
|
||||
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> playRecording() async {
|
||||
try {
|
||||
if (audioPath.value.isNotEmpty && File(audioPath.value).existsSync()) {
|
||||
await player.value.startPlayer(fromURI: audioPath.value);
|
||||
} else {
|
||||
print("Error: Path rekaman kosong atau tidak ditemukan.");
|
||||
}
|
||||
} catch (e) {
|
||||
print("Error saat memutar rekaman: ${e.toString()}");
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> berhentiRekaman() async {
|
||||
try {
|
||||
await recorder.value.stopRecorder();
|
||||
isSelesaiRekam.value = false;
|
||||
|
||||
// panggil fungsi untuk kirim ke BE
|
||||
if (audioPath.value.isNotEmpty) {
|
||||
String? mp3Path = await convertToMp3(audioPath.value);
|
||||
if (mp3Path != null) {
|
||||
// await uploadAudioFile(mp3Path);
|
||||
ref.read(uploadRekamProvider.notifier).uploadRekam(
|
||||
host: host,
|
||||
filePath: mp3Path,
|
||||
userId: userId,
|
||||
qrCodeStr: qrCodeStr.value,
|
||||
);
|
||||
print('mp3 convert $mp3Path');
|
||||
} else {
|
||||
print("Konversi gagal!");
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print("Error stop record ${e.toString()}");
|
||||
}
|
||||
}
|
||||
|
||||
void showLongToast(
|
||||
String title,
|
||||
String message,
|
||||
@@ -192,6 +120,83 @@ class RekamScreen extends HookConsumerWidget {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> jalankanRekaman() async {
|
||||
try {
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final filePath = '${dir.path}/myFile.aac';
|
||||
// final filePath = '${dir.path}/myFile.mp3';
|
||||
audioPath.value = filePath;
|
||||
|
||||
await recorder.value.startRecorder(
|
||||
toFile: filePath,
|
||||
);
|
||||
|
||||
judulTombol.value = "SELESAI";
|
||||
isSelesaiRekam.value = true;
|
||||
} catch (e) {
|
||||
print("Error start record ${e.toString()}");
|
||||
showLongToast(
|
||||
'Error',
|
||||
"Error start record ${e.toString()}",
|
||||
'error',
|
||||
Duration(seconds: 3),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
isSelesaiRekam.value = false;
|
||||
|
||||
// panggil fungsi untuk kirim ke BE
|
||||
if (audioPath.value.isNotEmpty) {
|
||||
String? mp3Path = await convertToMp3(audioPath.value);
|
||||
if (mp3Path != null) {
|
||||
// await uploadAudioFile(mp3Path);
|
||||
ref.read(uploadRekamProvider.notifier).uploadRekam(
|
||||
host: host,
|
||||
filePath: mp3Path,
|
||||
userId: userId,
|
||||
qrCodeStr: qrCodeStr.value,
|
||||
);
|
||||
} else {
|
||||
print("Konversi gagal!");
|
||||
showLongToast(
|
||||
'Error',
|
||||
"Konversi gagal!",
|
||||
'error',
|
||||
Duration(seconds: 3),
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print("Error stop record ${e.toString()}");
|
||||
showLongToast(
|
||||
'Error',
|
||||
"Error stop record ${e.toString()}",
|
||||
'error',
|
||||
Duration(seconds: 3),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// list Riwayat Rekam
|
||||
ref.listen(listRiwayatRekamanProvider, (prev, next) {
|
||||
if (next is ListRiwayatRekamanStateLoading) {
|
||||
@@ -307,7 +312,7 @@ class RekamScreen extends HookConsumerWidget {
|
||||
.copyWith(color: Constant.textWhite),
|
||||
),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.green.shade400,
|
||||
backgroundColor: Constant.textBlack,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
@@ -370,7 +375,7 @@ class RekamScreen extends HookConsumerWidget {
|
||||
padding: EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Column(
|
||||
children: [
|
||||
if (awalan.value == "Info :")
|
||||
if (awalan.value == "Info :")
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: Constant.getActualYPhone(
|
||||
|
||||
Reference in New Issue
Block a user