medcorder_audio 0.0.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 84

medcorder_audio #

Flutter record/play audio plugin. #

pub package Language

Sponsored by Evrone

Developed for Evrone.com #

Funded by Medcorder Medcorder.com #

Getting Started #

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

With the medcorder_audio plugin you can integrate record/play audio support into your flutter app for iOS or Android.

Plugin functions #

setAudioSettings #

Future
iOS only. open PlayAndRecord audio session
returns: 'OK', 'FAIL'

backAudioSettings #

Future
iOS only. close PlayAndRecord audio session
returns: 'OK', 'FAIL'

startRecord #

Future
start record audio file to app documents path
returns: 'OK', 'FAIL'

stopRecord #

Future
stop audio recording process
returns: 'OK', 'FAIL'

checkMicrophonePermissions #

Future
check if you have recording audio permissions
returns: 'OK', 'NO'

startPlay #

Future
start audio playing for file with position
returns: 'OK', 'FAIL'
params: Map<String, String>

KeyTypeDescription
fileStringString file Id
positiondoubleplay start position in seconds

stopPlay #

Future
stop audio playing
returns: 'OK', 'FAIL'\

Plugin events #

for recieving plugin events you need assign callback function
void _onEvent(dynamic event) {...}

recording events #

KeyTypeDescription
'code'String'recording',
'url'Stringrecording file url
'peakPowerForChannel'doublepeak power for channel
'currentTime'doublerecording time in seconds

playing events #

KeyTypeDescription
'code'String'playing', 'audioPlayerDidFinishPlaying'
'url'Stringplaying file url
'currentTime'doubleplaying time in seconds
'duration'doubleplaying file duration

0.0.1 #

medcorder_audio #

Flutter record/play audio plugin. #

Developed for Evrone.com #

Funded by David Weekly dweek.ly #

0.0.2 #

  • Flutter SDK upgrade
  • Dart 2 upgrade
  • Errors fix

0.0.3 #

  • readme update

0.0.4 #

  • description update

0.0.5 #

  • flutter upgrade, androidX support

0.0.6 #

  • adding dart and flutter badges

example/lib/main.dart

import 'dart:async';

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

void main() {
  runApp(new MyApp());
}

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

class _MyAppState extends State<MyApp> {
  MedcorderAudio audioModule = new MedcorderAudio();
  bool canRecord = false;
  double recordPower = 0.0;
  double recordPosition = 0.0;
  bool isRecord = false;
  bool isPlay = false;
  double playPosition = 0.0;
  String file = "";

  @override
  initState() {
    super.initState();
    audioModule.setCallBack((dynamic data) {
      _onEvent(data);
    });
    _initSettings();
  }

  Future _initSettings() async {
    final String result = await audioModule.checkMicrophonePermissions();
    if (result == 'OK') {
      await audioModule.setAudioSettings();
      setState(() {
        canRecord = true;
      });
    }
    return;
  }

  Future _startRecord() async {
    try {
      DateTime time = new DateTime.now();
      setState(() {
        file = time.millisecondsSinceEpoch.toString();
      });
      final String result = await audioModule.startRecord(file);
      setState(() {
        isRecord = true;
      });
      print('startRecord: ' + result);
    } catch (e) {
      file = "";
      print('startRecord: fail');
    }
  }

  Future _stopRecord() async {
    try {
      final String result = await audioModule.stopRecord();
      print('stopRecord: ' + result);
      setState(() {
        isRecord = false;
      });
    } catch (e) {
      print('stopRecord: fail');
      setState(() {
        isRecord = false;
      });
    }
  }

  Future _startStopPlay() async {
    if (isPlay) {
      await audioModule.stopPlay();
    } else {
      await audioModule.startPlay({
        "file": file,
        "position": 0.0,
      });
    }
  }

  void _onEvent(dynamic event) {
    if (event['code'] == 'recording') {
      double power = event['peakPowerForChannel'];
      setState(() {
        recordPower = (60.0 - power.abs().floor()).abs();
        recordPosition = event['currentTime'];
      });
    }
    if (event['code'] == 'playing') {
      String url = event['url'];
      setState(() {
        playPosition = event['currentTime'];
        isPlay = true;
      });
    }
    if (event['code'] == 'audioPlayerDidFinishPlaying') {
      setState(() {
        playPosition = 0.0;
        isPlay = false;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Audio example app'),
        ),
        body: new Center(
          child: canRecord
              ? new Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    new InkWell(
                      child: new Container(
                        alignment: FractionalOffset.center,
                        child: new Text(isRecord ? 'Stop' : 'Record'),
                        height: 40.0,
                        width: 200.0,
                        color: Colors.blue,
                      ),
                      onTap: () {
                        if (isRecord) {
                          _stopRecord();
                        } else {
                          _startRecord();
                        }
                      },
                    ),
                    new Text('recording: ' + recordPosition.toString()),
                    new Text('power: ' + recordPower.toString()),
                    new InkWell(
                      child: new Container(
                        margin: new EdgeInsets.only(top: 40.0),
                        alignment: FractionalOffset.center,
                        child: new Text(isPlay ? 'Stop' : 'Play'),
                        height: 40.0,
                        width: 200.0,
                        color: Colors.blue,
                      ),
                      onTap: () {
                        if (!isRecord && file.length > 0) {
                          _startStopPlay();
                        }
                      },
                    ),
                    new Text('playing: ' + playPosition.toString()),
                  ],
                )
              : new Text(
                  'Microphone Access Disabled.\nYou can enable access in Settings',
                  textAlign: TextAlign.center,
                ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  medcorder_audio: ^0.0.6

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:medcorder_audio/medcorder_audio.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
72
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
84
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:medcorder_audio/medcorder_audio.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because of import path [package:medcorder_audio/medcorder_audio.dart] that declares support for platforms: android, ios

Package does not support Flutter platform web

Because of import path [package:medcorder_audio/medcorder_audio.dart] that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because of import path [package:medcorder_audio/medcorder_audio.dart] that declares support for platforms: android, ios

Package not compatible with SDK dart

because of import path [medcorder_audio] that is in a package requiring null.

Health issues and suggestions

Document public APIs. (-1 points)

15 out of 15 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test