Some audio recording fixes

This commit is contained in:
Selim Mustafaev 2020-07-15 09:37:33 +03:00
parent 55e3a3008e
commit 6a53f7d953
7 changed files with 18 additions and 8 deletions

View File

@ -683,7 +683,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 19;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_TEAM = 46DTTB8X4S;
INFOPLIST_FILE = AutoCat/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
@ -705,7 +705,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 19;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_TEAM = 46DTTB8X4S;
INFOPLIST_FILE = AutoCat/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;

View File

@ -75,7 +75,5 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
}

View File

@ -173,6 +173,8 @@ class CheckController: UIViewController, MaskedTextFieldDelegateListener, UITabl
}
updateAction.image = UIImage(systemName: "arrow.2.circlepath")
updateAction.backgroundColor = .systemBlue
return UISwipeActionsConfiguration(actions: [updateAction])
let configuration = UISwipeActionsConfiguration(actions: [updateAction])
configuration.performsFirstActionWithFullSwipe = false
return configuration
}
}

View File

@ -115,6 +115,7 @@ class RecordsController: UIViewController, UITableViewDelegate {
do {
let alert = UIAlertController(title: "Recording...", message: nil, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { _ in self.recorder?.cancelRecording() }))
alert.addAction(UIAlertAction(title: "Done", style: .default, handler: { _ in self.recorder?.stopRecording() }))
self.present(alert, animated: true)
let date = Date()
@ -235,7 +236,9 @@ class RecordsController: UIViewController, UITableViewDelegate {
delete.image = UIImage(systemName: "trash")
let actions = record.number == nil ? [delete, action] : [delete, check, action]
return UISwipeActionsConfiguration(actions: actions)
let configuration = UISwipeActionsConfiguration(actions: actions)
configuration.performsFirstActionWithFullSwipe = false
return configuration
}
func moreActions(for record: AudioRecord, cell: UITableViewCell) {

View File

@ -1,5 +1,6 @@
import UIKit
import os.log
import AVFoundation
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
@ -56,6 +57,12 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
// Called as the scene transitions from the foreground to the background.
// Use this method to save data, release shared resources, and store enough scene-specific state information
// to restore the scene back to its current state.
do {
try AVAudioSession.sharedInstance().setActive(false)
} catch {
print("sceneDidEnterBackground failed to deactivate audio session: \(error.localizedDescription)")
}
}
func windowScene(_ windowScene: UIWindowScene, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {

View File

@ -37,7 +37,7 @@ class AudioPlayer: NSObject, AVAudioPlayerDelegate {
try AVAudioSession.sharedInstance().setActive(false)
self.state.accept(.paused)
} else {
try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .default, options: [.defaultToSpeaker])
try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: [.duckOthers])
try AVAudioSession.sharedInstance().setActive(true)
player.play()
self.state.accept(.playing)

View File

@ -59,7 +59,6 @@ class Recorder {
}
func startRecording(to file: URL, completion: @escaping (String) -> Void) throws {
let inFormat = self.engine.inputNode.outputFormat(forBus: 0)
guard let aac = AVAudioFormat(settings: self.recordingSettings) else {
throw CocoaError.error("Recording error", suggestion: "Format not supported")
}
@ -72,6 +71,7 @@ class Recorder {
try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .default, options: [])
try AVAudioSession.sharedInstance().setActive(true)
let inFormat = self.engine.inputNode.outputFormat(forBus: 0)
ExtAudioFileSetProperty(fileRef, kExtAudioFileProperty_ClientDataFormat, UInt32(MemoryLayout<AudioStreamBasicDescription>.size), inFormat.streamDescription)
self.engine.inputNode.installTap(onBus: 0, bufferSize: 1024, format: inFormat) { buffer, time in