medcorder_audio 0.0.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 87

medcorder_audio

Flutter record/play audio plugin.

Getting Started

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

For help on editing plugin code, view the documentation.

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

Plugin functions

setAudioSettings

Future<String> setAudioSettings() iOS only. open PlayAndRecord audio session returns: 'OK', 'FAIL'

backAudioSettings

Future<String> backAudioSettings() iOS only. close PlayAndRecord audio session returns: 'OK', 'FAIL'

startRecord

Future<String> startRecord(String fileId) start record audio file to app documents path returns: 'OK', 'FAIL'

stopRecord

Future<String> stopRecord() stop audio recording process returns: 'OK', 'FAIL'

checkMicrophonePermissions

Future<String> checkMicrophonePermissions() check if you have recording audio permissions returns: 'OK', 'NO'

startPlay

Future<String> startPlay(dynamic params) async 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<String> stopPlay() stop audio playing returns: 'OK', 'FAIL' params: Map<String, String>

Plugin events

for recieving plugin events you need assign callback function void _onEvent(Map<String, 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] - TODO: Add release date.

  • audio record/play plugin

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('No permissions for record'),
        ),
      ),
    );
  }
}

1. Depend on it

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


dependencies:
  medcorder_audio: "^0.0.1"

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support packages 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';
        
Version Uploaded Documentation Archive
0.0.1 Oct 10, 2017 Go to the documentation of medcorder_audio 0.0.1 Download medcorder_audio 0.0.1 archive

Analysis

We analyzed this package on Apr 9, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.46.0
  • pana: 0.10.6
  • Flutter: 0.2.9

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
80 / 100
Health:
Code health derived from static analysis. [more]
91 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
87
Learn more about scoring.

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 1 warning 2 hints.

    Strong-mode analysis of lib/medcorder_audio.dart gave the following warning:

    line: 16 col: 50
    A function of type '(Map<String, dynamic>) → void' can't be assigned to a location of type '(dynamic) → void'.

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
flutter 0.0.0
Transitive dependencies
collection 1.14.6 1.14.9
meta 1.1.2
sky_engine 0.0.99
typed_data 1.1.5
vector_math 2.0.5 2.0.6