Git Product home page Git Product logo

flutter_record's Introduction

DEPRECATED

This is no longer supported, please consider using flutter_sound instead.

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

pub version license github stars

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.volumeSubscription.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('pausePlayer'),
                onPressed: () async {
                  await _flutterRecord.pausePlayer();
                },
              ),
              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;
                  });
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}

flutter_record's People

Contributors

ened avatar rurico avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

flutter_record's Issues

the voice is too smal (ios)

The voice is too small and the volume doesn't work.
i set like this "_flutterRecord.setVolume(999999.0);" " _flutterRecord.startRecorder(path: 'test',maxVolume: 999999.0)" but the voice Still too small

'flutter_record/flutter_record-Swift.h' file not found

Xcode print:
#import <flutter_record/flutter_record-Swift.h>
'flutter_record/flutter_record-Swift.h' file not found



VSCode print:

=== BUILD TARGET flutter_record OF PROJECT Pods WITH CONFIGURATION Debug ===
/Users/zhangzhengyu/.pub-cache/hosted/pub.dartlang.org/flutter_record-0.1.3/ios/Classes/SwiftFlutterRecordPlugin.swift:69:14: warning: instance method 'audioPlayerDidFinishPlaying(_:successfully:)' nearly matches optional requirement 'audioPlayerDidFinishPlaying(_:successfully:)' of protocol 'AVAudioPlayerDelegate'
@objc func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
^
/Users/zhangzhengyu/.pub-cache/hosted/pub.dartlang.org/flutter_record-0.1.3/ios/Classes/SwiftFlutterRecordPlugin.swift:69:14: note: candidate exactly matches
@objc func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
^
/Users/zhangzhengyu/.pub-cache/hosted/pub.dartlang.org/flutter_record-0.1.3/ios/Classes/SwiftFlutterRecordPlugin.swift:69:14: note: move 'audioPlayerDidFinishPlaying(_:successfully:)' to an extension to silence this warning
@objc func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
^
/Users/zhangzhengyu/.pub-cache/hosted/pub.dartlang.org/flutter_record-0.1.3/ios/Classes/SwiftFlutterRecordPlugin.swift:69:14: note: make 'audioPlayerDidFinishPlaying(_:successfully:)' non-public to silence this warning
@objc func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
^
private
AVFoundation.AVAudioPlayerDelegate:3:26: note: requirement 'audioPlayerDidFinishPlaying(_:successfully:)' declared here
optional public func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool)
^
/Users/zhangzhengyu/.pub-cache/hosted/pub.dartlang.org/flutter_record-0.1.3/ios/Classes/SwiftFlutterRecordPlugin.swift:69:14: warning: instance method 'audioPlayerDidFinishPlaying(_:successfully:)' nearly matches optional requirement 'audioPlayerDidFinishPlaying(_:successfully:)' of protocol 'AVAudioPlayerDelegate'
@objc func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
^
/Users/zhangzhengyu/.pub-cache/hosted/pub.dartlang.org/flutter_record-0.1.3/ios/Classes/SwiftFlutterRecordPlugin.swift:69:14: note: candidate exactly matches
@objc func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
^
/Users/zhangzhengyu/.pub-cache/hosted/pub.dartlang.org/flutter_record-0.1.3/ios/Classes/SwiftFlutterRecordPlugin.swift:69:14: note: move 'audioPlayerDidFinishPlaying(_:successfully:)' to an extension to silence this warning
@objc func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
^
/Users/zhangzhengyu/.pub-cache/hosted/pub.dartlang.org/flutter_record-0.1.3/ios/Classes/SwiftFlutterRecordPlugin.swift:69:14: note: make 'audioPlayerDidFinishPlaying(_:successfully:)' non-public to silence this warning
@objc func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
^
private
AVFoundation.AVAudioPlayerDelegate:3:26: note: requirement 'audioPlayerDidFinishPlaying(_:successfully:)' declared here
optional public func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool)
^
/Users/zhangzhengyu/.pub-cache/hosted/pub.dartlang.org/flutter_record-0.1.3/ios/Classes/FlutterRecordPlugin.m:2:9: fatal error: 'flutter_record/flutter_record-Swift.h' file not found
#import <flutter_record/flutter_record-Swift.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

provide a stream to listen for both recording and playback

Currently there is a StreamController for Volume playback - presumably this is to display some type of audio graph as a user records a message. It would be great also to have the ability to subscribe to a recordSubscription and a playSubscription so that the flutter client can listen on these streams and provide some additional UI feedback - use case -> To display a playback / record duration which constantly ticks as the audio is recorded or played back.

Pause player functionality

The player allows Start & Stop. If we would like to build an interface (Attached image) - that allows a recorded sound file to be played, paused, stopped - there currently lacks a PAUSE callback. It would be great if :

_flutterRecord.pausePlayer()

is added.
stop pause stop

Unsupported value: kotlin.Unit

When recording starts with a invalid path, perhaps.

In any case the "unsupported Value" error should not happen.

java.lang.IllegalArgumentException: Unsupported value: kotlin.Unit
	at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:289)
	at io.flutter.plugin.common.StandardMethodCodec.encodeErrorEnvelope(StandardMethodCodec.java:70)
	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.error(MethodChannel.java:209)
	at att.moe.flutterrecord.FlutterRecordPlugin.startRecorder(FlutterRecordPlugin.kt:132)
	at att.moe.flutterrecord.FlutterRecordPlugin.onMethodCall(FlutterRecordPlugin.kt:56)
	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:201)
	at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:88)
	at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:202)
	at android.os.MessageQueue.nativePollOnce(Native Method)
	at android.os.MessageQueue.next(MessageQueue.java:326)
	at android.os.Looper.loop(Looper.java:160)
	at android.app.ActivityThread.main(ActivityThread.java:6718)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

run mistake

我下载了你的项目,运行后报出一下错误:

optional public func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool)
^
/Users/zhangzhengyu/Downloads/flutter_record-0.1.3/ios/Classes/SwiftFlutterRecordPlugin.swift:147:33: error: cannot convert value of type 'Int' to expected argument type 'TimeInterval' (aka 'Double')
player!.play(atTime: self.pausePosition)
~~~~~^~~~~~~~~~~~~
TimeInterval(     )
/Users/zhangzhengyu/Downloads/flutter_record-0.1.3/ios/Classes/SwiftFlutterRecordPlugin.swift:174:38: error: cannot assign value of type 'TimeInterval' (aka 'Double') to type 'Int'
self.pausePosition = player!.currentTime
~~~~~~~~^~~~~~~~~~~
Int(               )
Could not build the precompiled application for the device.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.