flutter_simple_record_and_player 1.0.0+0.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 67

install #

flutter_simple_record_and_player: ^1.0.0+0.1

config iOS Info.plist #

iOS Make sure you add the following key to Info.plist for iOS

<key>NSMicrophoneUsageDescription</key>
<string>xxxxxx</string>

Example #

github Example code

  SimpleSoundRecordAndPlayer _recordAndPlayer = new SimpleSoundRecordAndPlayer();

录音 #

try {
    String path='/cached/demo.mp3';
    _recordAndPlayer.startRecord(path, (error) {
                      print(error);
         });
      } catch (e) {
                  print(e);
              }
        },

结束录音 #

_recordAndPlayer.stopRecord;

获取录音的最新路径 #

_recordAndPlayer.recordListPath.last

播放文件 #

_recordAndPlayer.play(s, isLocal: true);

暂停播放 #

 _recordAndPlayer?.pausePlay();

结束播放 #

_recordAndPlayer?.stopPlay();

播放网络音频 #

_recordAndPlayer.play(
                      'http://music.163.com/song/media/outer/url?id=1447126763.mp3',
                      isLocal: false)

清空录好的文件 #

_recordAndPlayer.clearDiskCache();

录音进度监听 #

 _recordAndPlayer.onAudioPlayerPositionChanged.listen((event) {
      setState(() {
        currentTime = '${event.inMinutes}:${event.inSeconds}';
      });
    });

播放器状态变更 #

 _audioPlayer.onPlayerStateChanged.listen((event) {
      print('状态变更:${event.toString()}');
    });

[1.0.0+0.1] #

修复readme

[1.0.0] #

1.安卓和iOS录制音频 2.播放本地和网络音频 3.清空已经录好的文件

example/lib/main.dart

import 'dart:io';

import 'package:audioplayer/audioplayer.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_simple_record_and_player/fluttersimplerecordandplayer.dart';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';

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

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

class _MyAppState extends State<MyApp> {
  String path = '';

  AudioPlayer _audioPlayer;

  String currentTime = '0:0';
  String allTime = '0:0';

  SimpleSoundRecordAndPlayer _recordAndPlayer;

  Duration allDate;
  @override
  void initState() {
    super.initState();
    _recordAndPlayer = SimpleSoundRecordAndPlayer();
    _recordAndPlayer.onAudioPlayerPositionChanged.listen((event) {
      setState(() {
        currentTime = '${event.inMinutes}:${event.inSeconds}';
      });
    });

    _audioPlayer = new AudioPlayer();
    _audioPlayer.onAudioPositionChanged.listen((duration) {
      setState(() {
        currentTime = '${duration.inMinutes}\'${duration.inSeconds % 60}\'\'';
      });
    });
    _audioPlayer.onPlayerStateChanged.listen((event) {
      print('状态变更:${event.toString()}');
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
//      type: MaterialType.card,
      home: Scaffold(
        appBar: AppBar(
          title: Text('title'),
        ),
        body: Container(
          alignment: Alignment.center,
          child: Column(
            children: <Widget>[
              FlatButton(
                onPressed: () async {
                  try {
                    _recordAndPlayer.startRecord(null, (error) {
                      print(error);
                    });
                  } catch (e) {
                    print(e);
                  }
                },
                child: Text('开始'),
              ),
              FlatButton(
                onPressed: () async {
                  bool s = _recordAndPlayer.stopRecord;
                  print('结束:$s');
                },
                child: Text('结束'),
              ),
              Text(path),
              FlatButton(
                onPressed: () async {
                  String s = _recordAndPlayer.recordListPath.last;
                  print('mp3URL:$s');
                  _recordAndPlayer.play(s, isLocal: true);
                },
                child: Text('play'),
              ),
              FlatButton(
                onPressed: () async {
//                  bool s = await RecordMp3.instance.stop();
//                  _audioPlayer?.pause();
                  _recordAndPlayer?.pausePlay();
                },
                child: Text('暂停'),
              ),
              FlatButton(
                onPressed: () async {
//                  bool s = await RecordMp3.instance.stop();
                  _recordAndPlayer?.stopPlay();
                },
                child: Text('结束'),
              ),
              Text('$currentTime/${_recordAndPlayer?.duration}'),
              Text(
                  '$currentTime/${_audioPlayer?.duration.inMinutes}\'${_audioPlayer?.duration.inSeconds % 60}\'\''),
              FlatButton(
                onPressed: () async {
                  _recordAndPlayer.play(
                      'http://music.163.com/song/media/outer/url?id=1447126763.mp3',
                      isLocal: false);
                },
                child: Text('播放网络语音'),
              ),
              FlatButton(
                onPressed: () async {
                  final f = await _recordAndPlayer.getRecordLastData;
                  print('$f');
                },
                child: Text('输出最后文件'),
              ),
              FlatButton(
                onPressed: () async {
                  _recordAndPlayer.clearDiskCache();
                },
                child: Text('清空文件目录'),
              ),
            ],
          ),
        ),
      ),
    );
  }

  Future<bool> fileExists(String path) async {
    return await File(path).exists();
  }

  Future<String> _createPath() async {
    String p = await _getPath();
    final date = DateTime.now();

    final directory = Directory(p);
    if (directory.existsSync() == false) {
      final success = await directory.create();
      if (success != null) {
        return '$p/${date.year}${date.month}${date.day}${date.hour}${date.minute}${date.second}.mp3';
      }
    }
    return '$p/${date.year}${date.month}${date.day}${date.hour}${date.minute}${date.second}.mp3';
  }

  Future<String> _getPath() async {
    final p = await getTemporaryDirectory();
    print(p);
    return p.path + '/mp3';
  }

  void _play(String path) {}
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_simple_record_and_player: ^1.0.0+0.4

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:flutter_simple_record_and_player/fluttersimplerecordandplayer.dart';
import 'package:flutter_simple_record_and_player/simpleSoundRecordAndPlayer.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
36
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
95
Overall:
Weighted score of the above. [more]
67
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform Android

Because:

  • package:flutter_simple_record_and_player/fluttersimplerecordandplayer.dart that imports:
  • package:flutter_simple_record_and_player/simpleSoundRecordAndPlayer.dart that imports:
  • package:path_provider/path_provider.dart that imports:
  • package:path_provider_linux/path_provider_linux.dart that declares support for platforms: Linux

Package does not support Flutter platform Linux

Because:

  • package:flutter_simple_record_and_player/fluttersimplerecordandplayer.dart that imports:
  • package:flutter_simple_record_and_player/simpleSoundRecordAndPlayer.dart that imports:
  • package:record_mp3/record_mp3.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Web

Because:

  • package:flutter_simple_record_and_player/fluttersimplerecordandplayer.dart that imports:
  • package:flutter_simple_record_and_player/simpleSoundRecordAndPlayer.dart that imports:
  • package:record_mp3/record_mp3.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Windows

Because:

  • package:flutter_simple_record_and_player/fluttersimplerecordandplayer.dart that imports:
  • package:flutter_simple_record_and_player/simpleSoundRecordAndPlayer.dart that imports:
  • package:record_mp3/record_mp3.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform iOS

Because:

  • package:flutter_simple_record_and_player/fluttersimplerecordandplayer.dart that imports:
  • package:flutter_simple_record_and_player/simpleSoundRecordAndPlayer.dart that imports:
  • package:path_provider/path_provider.dart that imports:
  • package:path_provider_linux/path_provider_linux.dart that declares support for platforms: Linux

Package does not support Flutter platform macOS

Because:

  • package:flutter_simple_record_and_player/fluttersimplerecordandplayer.dart that imports:
  • package:flutter_simple_record_and_player/simpleSoundRecordAndPlayer.dart that imports:
  • package:record_mp3/record_mp3.dart that declares support for platforms: Android, iOS

Package not compatible with SDK dart

Because:

  • flutter_simple_record_and_player that is a package requiring null.

Health suggestions

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

Analysis of lib/simpleSoundRecordAndPlayer.dart reported 1 hint:

line 73 col 14: Dead code.

Maintenance suggestions

Homepage URL is insecure. (-5 points)

Update the homepage field and use a secure (https) URL.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
audioplayer ^0.8.1 0.8.1
flutter 0.0.0
path_provider ^1.6.10 1.6.11
permission_handler ^5.0.1 5.0.1+1
record_mp3 ^2.0.0 2.0.0
Transitive dependencies
collection 1.14.12 1.14.13
file 5.2.1
intl 0.16.1
meta 1.1.8 1.2.2
path 1.7.0
path_provider_linux 0.0.1+2
path_provider_macos 0.0.4+3
path_provider_platform_interface 1.0.2
permission_handler_platform_interface 2.0.1
platform 2.2.1
plugin_platform_interface 1.0.2
process 3.0.13
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
xdg_directories 0.1.0
Dev dependencies
flutter_test