medcorder_audio 0.0.1

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

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'),
        ),
      ),
    );
  }
}

Use this package as a library

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 flutter 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
Popularity:
Describes how popular the package is relative to other packages. [more]
65
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
65
Overall:
Weighted score of the above. [more]
75
Learn more about scoring.

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

  • Dart: 2.0.0
  • pana: 0.12.4
  • Flutter: 0.9.5

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/medcorder_audio.dart. (-0.50 points)

Analysis of lib/medcorder_audio.dart reported 1 hint:

line 3 col 8: Duplicate import.

Maintenance issues and suggestions

Add SDK constraint in pubspec.yaml. (-5 points)

For information about setting SDK constraint, please see https://www.dartlang.org/tools/pub/pubspec#sdk-constraints.

The description is too short. (-20 points)

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-v0.1 release. (-10 points)

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

Package is getting outdated.

The package was released 52 weeks ago.

Dependencies

Package Constraint Resolved Available
Direct dependencies
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8