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
5 changes: 4 additions & 1 deletion record/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Upcoming
## 6.1.3
* feat: Add `request` parameter to `hasPermission()` method to check permission status without requesting.
* fix(android): Release audio focus when calling `cancel()` method.
* fix(android): Use `AUDIOFOCUS_GAIN_TRANSIENT` instead of `AUDIOFOCUS_GAIN` to allow other audio apps to resume automatically.
* fix(ios): Deactivate audio session when calling `stop()`, `pause()` methods to allow other audio apps to resume automatically.

## 6.1.2
* chore: Updated transitive dependencies.
Expand Down
10 changes: 5 additions & 5 deletions record/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: record
description: Audio recorder from microphone to file or stream with multiple codecs, bit rate and sampling rate options.
version: 6.1.2
version: 6.1.3
homepage: https://github.com/llfbandit/record/tree/master/record

environment:
Expand All @@ -15,13 +15,13 @@ dependencies:

uuid: ">=3.0.7 <5.0.0"

record_platform_interface: ^1.4.0
record_platform_interface: ^1.4.1
record_web: ^1.2.0
record_windows: ^1.0.7
record_linux: ^1.2.1
record_android: ^1.4.3
record_ios: ^1.1.3
record_macos: ^1.1.2
record_android: ^1.4.6
record_ios: ^1.1.6
record_macos: ^1.1.3

dev_dependencies:
flutter_lints: ^6.0.0
Expand Down
4 changes: 3 additions & 1 deletion record_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Upcoming
## 1.4.6
* feat: Add `request` parameter to `hasPermission()` method to check permission status without requesting.
* fix: Release audio focus when calling `cancel()` method.
* fix: Use `AUDIOFOCUS_GAIN_TRANSIENT` instead of `AUDIOFOCUS_GAIN` to allow other audio apps to resume automatically after recording stops.

## 1.4.5
* fix: WAVE header for files larger than 2GB.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class AudioRecorder(

override fun cancel() {
recorderThread?.cancelRecording()
restoreAudioManagerSettings()
}

override fun pause() {
Expand Down Expand Up @@ -246,7 +247,7 @@ class AudioRecorder(
}

if (Build.VERSION.SDK_INT >= 26) {
afRequest = AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN).run {
afRequest = AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT).run {
setAudioAttributes(AudioAttributes.Builder().run {
setUsage(AudioAttributes.USAGE_MEDIA)
setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
Expand All @@ -259,7 +260,7 @@ class AudioRecorder(
audioManager.requestAudioFocus(afRequest!!)
} else {
audioManager.requestAudioFocus(
afChangeListener, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN
afChangeListener, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions record_android/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: record_android
description: Android specific implementation for record package called by record_platform_interface.
version: 1.4.5
version: 1.4.6
homepage: https://github.com/llfbandit/record/tree/master/record_android

environment:
Expand All @@ -13,7 +13,7 @@ dependencies:
flutter:
sdk: flutter

record_platform_interface: ^1.4.0
record_platform_interface: ^1.4.1

flutter:
plugin:
Expand Down
3 changes: 2 additions & 1 deletion record_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Upcoming
## 1.1.6
* feat: Add `request` parameter to `hasPermission()` method to check permission status without requesting.
* fix: Deactivate audio session when calling `stop()`, `pause()`, or `cancel()` to allow other audio apps to resume automatically.

## 1.1.5
* fix: Clamp to supported sample rates for Opus.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import Foundation

class RecorderFileDelegate: NSObject, AudioRecordingFileDelegate, AVAudioRecorderDelegate {
var config: RecordConfig?

private var audioRecorder: AVAudioRecorder?
private var path: String?
private var onPause: () -> ()
private var onStop: () -> ()
private var onPause: () -> Void
private var onStop: () -> Void
private let manageAudioSession: Bool
init(manageAudioSession: Bool, onPause: @escaping () -> (), onStop: @escaping () -> ()) {

init(manageAudioSession: Bool, onPause: @escaping () -> Void, onStop: @escaping () -> Void) {
self.manageAudioSession = manageAudioSession
self.onPause = onPause
self.onStop = onStop
Expand All @@ -28,68 +28,72 @@ class RecorderFileDelegate: NSObject, AudioRecordingFileDelegate, AVAudioRecorde
recorder.delegate = self
recorder.isMeteringEnabled = true
recorder.prepareToRecord()

recorder.record()

audioRecorder = recorder
self.path = path
self.config = config
}

func stop(completionHandler: @escaping (String?) -> ()) {
func stop(completionHandler: @escaping (String?) -> Void) {
audioRecorder?.stop()
audioRecorder = nil

deactivateAudioSession()

completionHandler(path)
onStop()

path = nil
config = nil
}

func pause() {
guard let recorder = audioRecorder, recorder.isRecording else {
return
}

recorder.pause()
deactivateAudioSession()
onPause()
}

func resume() {
audioRecorder?.record()
}

func cancel() throws {
guard let path = path else { return }

stop { path in }

try deleteFile(path: path)
}

func getAmplitude() -> Float {
audioRecorder?.updateMeters()
return audioRecorder?.averagePower(forChannel: 0) ?? -160
}

func dispose() {
stop { path in }
}

func audioRecorderDidFinishRecording(_ recorder: AVAudioRecorder, successfully flag: Bool) {
// Audio recording has stopped
// Audio recording has stopped
}

private func deleteFile(path: String) throws {
do {
let fileManager = FileManager.default

if fileManager.fileExists(atPath: path) {
try fileManager.removeItem(atPath: path)
}
} catch {
throw RecorderError.error(message: "Failed to delete previous recording", details: error.localizedDescription)
throw RecorderError.error(
message: "Failed to delete previous recording", details: error.localizedDescription)
}
}
}
Loading