Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.6.0
Fixing output file header for Android & migrate to null safety.

## 0.5.5
migrate to Android X.

Expand Down
2 changes: 1 addition & 1 deletion README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Flutter 录音插件 支持录音/暂停/继续/停止, 可以在录音的同时
## 其他配置
#### iOS Deployment Target is 8.0
#### Android
- 开启AndroidX的项目: 请使用最新版本 (`0.5.x`)
- 开启AndroidX的项目: 请使用最新版本 (`0.6.x`)
- 未使用AndroidX的项目: 可以使用旧版本 (`0.4.9`)

### 注意: iOS Deployment Target 是 8.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ add `flutter_audio_recorder` to your `pubspec.yaml`
## Configuration
#### iOS Deployment Target is 8.0 above
#### Android
- AndroidX: use latest version (`0.5.x`)
- AndroidX: use latest version (`0.6.x`)
- Legacy Android: use old version (`0.4.9`)

## Usage
Expand Down
13 changes: 7 additions & 6 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
group 'com.zeno.flutter_audio_recorder'
version '0.5.4'
version '0.6.1'

buildscript {
repositories {
google()
jcenter()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:8.1.2'
}
}

rootProject.allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

apply plugin: 'com.android.library'

android {
compileSdkVersion 28
compileSdkVersion 34
namespace 'com.zeno.flutter_audio_recorder'

defaultConfig {
minSdkVersion 16
targetSdkVersion 28
targetSdkVersion 34
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions {
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.zeno.flutter_audio_recorder;

import android.app.Activity;
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;
import android.os.Build.VERSION;

import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.util.Log;
Expand All @@ -29,12 +32,15 @@
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.Registrar;

import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.embedding.engine.plugins.activity.*;
import io.flutter.plugin.common.BinaryMessenger;

/** FlutterAudioRecorderPlugin */
public class FlutterAudioRecorderPlugin implements MethodCallHandler, PluginRegistry.RequestPermissionsResultListener {
public class FlutterAudioRecorderPlugin implements MethodCallHandler, PluginRegistry.RequestPermissionsResultListener, FlutterPlugin, ActivityAware {
private static final String LOG_NAME = "AndroidAudioRecorder";
private static final int PERMISSIONS_REQUEST_RECORD_AUDIO = 200;
private static final byte RECORDER_BPP = 16; // we use 16bit
private Registrar registrar;
private int mSampleRate = 16000; // 16Khz
private AudioRecord mRecorder = null;
private String mFilePath;
Expand All @@ -47,20 +53,53 @@ public class FlutterAudioRecorderPlugin implements MethodCallHandler, PluginRegi
private Thread mRecordingThread = null;
private long mDataSize = 0;
private Result _result;

private MethodChannel channel;
private Context context;
protected Activity activity;

/** Plugin registration. */
public static void registerWith(Registrar registrar) {
final FlutterAudioRecorderPlugin plugin = new FlutterAudioRecorderPlugin();
plugin.setupChannel(registrar.messenger(), registrar.context());
plugin.activity = registrar.activity();
}

private void setupChannel(BinaryMessenger messenger, Context context) {
channel = new MethodChannel(messenger, "flutter_audio_recorder");
channel.setMethodCallHandler(this);
this.context = context;
}

@Override
public void onAttachedToActivity​(@NonNull ActivityPluginBinding binding) {
activity = binding.getActivity();
}

@Override
public void onReattachedToActivityForConfigChanges​(@NonNull ActivityPluginBinding binding){}

@Override
public void onDetachedFromActivityForConfigChanges(){}

final MethodChannel channel = new MethodChannel(registrar.messenger(), "flutter_audio_recorder");
channel.setMethodCallHandler(new FlutterAudioRecorderPlugin(registrar));
@Override
public void onDetachedFromActivity() {
activity = null;
}

public FlutterAudioRecorderPlugin(Registrar registrar) {
this.registrar = registrar;
this.registrar.addRequestPermissionsResultListener(this);
@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
setupChannel(binding.getBinaryMessenger(), binding.getApplicationContext());
}

@Override
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
channel.setMethodCallHandler(null);
channel = null;
context = null;
}

public FlutterAudioRecorderPlugin() {}

@Override
public boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
final int REQUEST_RECORD_AUDIO_PERMISSION = 200;
Expand All @@ -86,13 +125,7 @@ public boolean onRequestPermissionsResult(int requestCode, String[] permissions,
}

private boolean hasRecordPermission(){
// if after [Marshmallow], we need to check permission on runtime
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
return (ContextCompat.checkSelfPermission(registrar.context(), Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED)
&& (ContextCompat.checkSelfPermission(registrar.context(), Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED);
} else {
return ContextCompat.checkSelfPermission(registrar.context(), Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;
}
return ContextCompat.checkSelfPermission(context, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;
}

@Override
Expand Down Expand Up @@ -138,9 +171,9 @@ private void handleHasPermission(){
Log.d(LOG_NAME, "handleHasPermission false");

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
ActivityCompat.requestPermissions(registrar.activity(), new String[]{Manifest.permission.RECORD_AUDIO, Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSIONS_REQUEST_RECORD_AUDIO);
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.RECORD_AUDIO, Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSIONS_REQUEST_RECORD_AUDIO);
} else {
ActivityCompat.requestPermissions(registrar.activity(), new String[]{Manifest.permission.RECORD_AUDIO}, PERMISSIONS_REQUEST_RECORD_AUDIO);
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.RECORD_AUDIO}, PERMISSIONS_REQUEST_RECORD_AUDIO);
}
}

Expand Down Expand Up @@ -354,8 +387,13 @@ private void WriteWaveFileHeader(FileOutputStream out, long totalAudioLen,
header[29] = (byte) ((byteRate >> 8) & 0xff);
header[30] = (byte) ((byteRate >> 16) & 0xff);
header[31] = (byte) ((byteRate >> 24) & 0xff);
header[32] = (byte) (1); // block align
header[33] = 0;

long blockAlign = channels * (int) RECORDER_BPP / 8;
//header[32] = (byte) (1); // block align
header[32] = (byte) (blockAlign);
//header[33] = 0;
header[33] = (byte) (blockAlign >> 8);

header[34] = RECORDER_BPP; // bits per sample
header[35] = 0;
header[36] = 'd';
Expand Down
1 change: 1 addition & 0 deletions example/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"audioplayers","path":"/home/arditya/.pub-cache/hosted/pub.dev/audioplayers-0.20.1/","native_build":true,"dependencies":[]},{"name":"flutter_audio_recorder","path":"/home/arditya/Documents/dev/Me/flutter_audio_recorder/","native_build":true,"dependencies":[]},{"name":"path_provider_ios","path":"/home/arditya/.pub-cache/hosted/pub.dev/path_provider_ios-2.0.7/","native_build":true,"dependencies":[]}],"android":[{"name":"audioplayers","path":"/home/arditya/.pub-cache/hosted/pub.dev/audioplayers-0.20.1/","native_build":true,"dependencies":[]},{"name":"flutter_audio_recorder","path":"/home/arditya/Documents/dev/Me/flutter_audio_recorder/","native_build":true,"dependencies":[]},{"name":"path_provider_android","path":"/home/arditya/.pub-cache/hosted/pub.dev/path_provider_android-2.0.11/","native_build":true,"dependencies":[]}],"macos":[{"name":"audioplayers","path":"/home/arditya/.pub-cache/hosted/pub.dev/audioplayers-0.20.1/","native_build":true,"dependencies":[]},{"name":"path_provider_macos","path":"/home/arditya/.pub-cache/hosted/pub.dev/path_provider_macos-2.0.5/","native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/home/arditya/.pub-cache/hosted/pub.dev/path_provider_linux-2.1.5/","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/home/arditya/.pub-cache/hosted/pub.dev/path_provider_windows-2.0.5/","native_build":false,"dependencies":[]}],"web":[{"name":"audioplayers","path":"/home/arditya/.pub-cache/hosted/pub.dev/audioplayers-0.20.1/","dependencies":[]}]},"dependencyGraph":[{"name":"audioplayers","dependencies":["path_provider"]},{"name":"flutter_audio_recorder","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_ios","path_provider_linux","path_provider_macos","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_ios","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2024-03-16 19:02:27.631437","version":"3.16.9"}
4 changes: 2 additions & 2 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28
compileSdkVersion 31

lintOptions {
disable 'InvalidPackage'
Expand All @@ -35,7 +35,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.zeno.flutter_audio_recorder_example"
minSdkVersion 16
targetSdkVersion 28
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand Down
7 changes: 5 additions & 2 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:name="${applicationName}"
android:label="flutter_audio_recorder_example"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:name="io.flutter.embedding.android.FlutterActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
Expand All @@ -29,6 +29,9 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Expand Down

This file was deleted.

6 changes: 3 additions & 3 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:4.0.1'
}
}

allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.1-all.zip
14 changes: 9 additions & 5 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/nikk.li/Work/development/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/wenyan/zeno/project/flutter_audio_recorder/example"
export "FLUTTER_TARGET=/Users/wenyan/zeno/project/flutter_audio_recorder/example/lib/main.dart"
export "FLUTTER_ROOT=/home/arditya/flutter"
export "FLUTTER_APPLICATION_PATH=/home/arditya/Documents/dev/Me/flutter_audio_recorder/example"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "FLUTTER_FRAMEWORK_DIR=/Users/nikk.li/Work/development/flutter/bin/cache/artifacts/engine/ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=.dart_tool/package_config.json"
Loading