flutter_record

A flutter plugin for recorder audio and audio player.of course, you can cancel the recording.

pub version

Installation

First, add flutter_record as a dependency in your pubspec.yaml file.

Run flutter packages get

iOS

Add two rows to the ios/Runner/Info.plist:

  • one with the key Privacy - Microphone Usage Description and a usage description.
  • and one with the key UIBackgroundModes and a usage description.
<key>NSMicrophoneUsageDescription</key>
<string>Can I use the mic please?</string>
<key>UIBackgroundModes</key>
<array>
	<string>audio</string>
</array>

Android

configuration required - the plugin should work out of the box.

Example

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutter_record/flutter_record.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  FlutterRecord _flutterRecord;
  double _volume = 0.0;
  int _duration = 0;

  @override
  void initState() {
    super.initState();
    initPlatformState();
    _flutterRecord = FlutterRecord();
  }

  Future<void> initPlatformState() async {
    String platformVersion;

    try {
      platformVersion = await FlutterRecord.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Plugin example app')),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text('Running on: $_platformVersion\n'),
              SizedBox(height: 50.0),
              Text('$_volume'),
              FlatButton(
                child: Text('startRecorder'),
                onPressed: () async {
                  String path = await _flutterRecord.startRecorder(
                      path: 'test', maxVolume: 7.0);

                  print(path);

                  _flutterRecord.volumeController.stream.listen((volume) {
                    setState(() {
                      _volume = volume;
                    });
                  });
                },
              ),
              FlatButton(
                child: Text('stopRecorder'),
                onPressed: () async {
                  await _flutterRecord.stopRecorder();
                },
              ),
              FlatButton(
                child: Text('cancelRecorder'),
                onPressed: () async {
                  await _flutterRecord.cancelRecorder();
                },
              ),
              FlatButton(
                child: Text('startPlayer'),
                onPressed: () async {
                  await _flutterRecord.startPlayer(path: 'test');
                  await _flutterRecord.setVolume(1.0);
                },
              ),
              FlatButton(
                child: Text('stopPlay'),
                onPressed: () async {
                  await _flutterRecord.stopPlayer();
                },
              ),
              Text('$_duration'),
              FlatButton(
                child: Text('getDuration'),
                onPressed: () async {
                  final int duration =
                      await _flutterRecord.getDuration(path: 'test');
                  setState(() {
                    _duration = duration;
                  });
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Libraries

flutter_record

Dart

dart:ui
Built-in types and core primitives for a Flutter application. [...]

Core

dart:async
Support for asynchronous programming, with classes such as Future and Stream. [...]
dart:collection
Classes and utilities that supplement the collection support in dart:core. [...]
dart:convert
Encoders and decoders for converting between different data representations, including JSON and UTF-8. [...]
dart:core
Built-in types, collections, and other core functionality for every Dart program. [...]
dart:developer
Interact with developer tools such as the debugger and inspector. [...]
dart:math
Mathematical constants and functions, plus a random number generator. [...]
dart:typed_data
Lists that efficiently handle fixed sized data (for example, unsigned 8 byte integers) and SIMD numeric types. [...]

VM

dart:io
File, socket, HTTP, and other I/O support for non-web applications. [...]
dart:isolate
Concurrent programming using isolates: independent workers that are similar to threads but don't share memory, communicating only via messages. [...]