Skip to content

Commit

Permalink
chore: Update example
Browse files Browse the repository at this point in the history
fix #240, fix #212
  • Loading branch information
llfbandit committed Dec 14, 2023
1 parent f587fa3 commit 7d2ddb6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
4 changes: 2 additions & 2 deletions record/example/lib/audio_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class AudioPlayer extends StatefulWidget {
final VoidCallback onDelete;

const AudioPlayer({
Key? key,
super.key,
required this.source,
required this.onDelete,
}) : super(key: key);
});

@override
AudioPlayerState createState() => AudioPlayerState();
Expand Down
32 changes: 23 additions & 9 deletions record/example/lib/audio_recorder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'platform/audio_recorder_platform.dart';
class Recorder extends StatefulWidget {
final void Function(String path) onStop;

const Recorder({Key? key, required this.onStop}) : super(key: key);
const Recorder({super.key, required this.onStop});

@override
State<Recorder> createState() => _RecorderState();
Expand Down Expand Up @@ -46,19 +46,14 @@ class _RecorderState extends State<Recorder> with AudioRecorderMixin {
if (await _audioRecorder.hasPermission()) {
const encoder = AudioEncoder.aacLc;

// We don't do anything with this but printing
final isSupported = await _audioRecorder.isEncoderSupported(
encoder,
);

if (!isSupported) {
debugPrint('${encoder.name} supported: $isSupported');
if (!await _isEncoderSupported(encoder)) {
return;
}

final devs = await _audioRecorder.listInputDevices();
debugPrint(devs.toString());

const config = RecordConfig(encoder: encoder);
const config = RecordConfig(encoder: encoder, numChannels: 1);

// Record to file
await recordFile(_audioRecorder, config);
Expand Down Expand Up @@ -108,6 +103,25 @@ class _RecorderState extends State<Recorder> with AudioRecorderMixin {
}
}

Future<bool> _isEncoderSupported(AudioEncoder encoder) async {
final isSupported = await _audioRecorder.isEncoderSupported(
encoder,
);

if (!isSupported) {
debugPrint('${encoder.name} is not supported on this platform.');
debugPrint('Supported encoders are:');

for (final e in AudioEncoder.values) {
if (await _audioRecorder.isEncoderSupported(e)) {
debugPrint('- ${encoder.name}');
}
}
}

return isSupported;
}

@override
Widget build(BuildContext context) {
return MaterialApp(
Expand Down
2 changes: 1 addition & 1 deletion record/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:record_example/audio_recorder.dart';
void main() => runApp(const MyApp());

class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
const MyApp({super.key});

@override
State<MyApp> createState() => _MyAppState();
Expand Down
3 changes: 2 additions & 1 deletion record/example/lib/platform/audio_recorder_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ mixin AudioRecorderMixin {
html.document.body!.children.add(anchor);
anchor.click();
html.document.body!.children.remove(anchor);
html.Url.revokeObjectUrl(path);

// html.Url.revokeObjectUrl(path);
}
}
4 changes: 2 additions & 2 deletions record/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ environment:
dependencies:
path: ^1.8.0
path_provider: ^2.0.1
audioplayers: ^5.2.0
audioplayers: ^5.2.1

flutter:
sdk: flutter
Expand All @@ -22,7 +22,7 @@ dependencies:
path: ../

dev_dependencies:
flutter_lints: ^2.0.3
flutter_lints: ^3.0.0

# The following section is specific to Flutter.
flutter:
Expand Down

0 comments on commit 7d2ddb6

Please sign in to comment.