record 6.1.2
record: ^6.1.2 copied to clipboard
Audio recorder from microphone to file or stream with multiple codecs, bit rate and sampling rate options.
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:record_example/audio_player.dart';
import 'package:record_example/audio_recorder.dart';
void main() => runApp(const MyApp());
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String? audioPath;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: audioPath != null
? Padding(
padding: const EdgeInsets.symmetric(horizontal: 25),
child: AudioPlayer(
source: audioPath!,
onDelete: () {
if (!kIsWeb) {
try {
File(audioPath!).deleteSync();
} catch (_) {
// Ignored
}
}
setState(() => audioPath = null);
},
),
)
: Recorder(
onStop: (path) {
if (kDebugMode) print('Recorded file path: $path');
setState(() => audioPath = path);
},
),
),
),
);
}
}