Post

Replies

Boosts

Views

Activity

In watchos, How to stay app in background while using avaudioengine.
Hello My app record voice with Record_Engine class(AvaudioEngine). Problem: Even though i made my app go to background, app return to inactive state in few seconds(about 3 seconds after watch screen locked). Example: How can i leave my app background. like built-in record app. and my recorder class is here. //Recorder.swift class Record_Engine : ObservableObject {    @Published var recording_file : AVAudioFile!    private var engine: AVAudioEngine!    private var mixerNode: AVAudioMixerNode!        init() {      setupSession()      setupEngine()    }            fileprivate func setupSession() {      let session = AVAudioSession.sharedInstance()      do {        try session.setCategory(AVAudioSession.Category.playAndRecord, mode: .default)        try session.setActive(true)      } catch {        print(error.localizedDescription)      }    }        fileprivate func setupEngine() {      engine = AVAudioEngine()      mixerNode = AVAudioMixerNode()      mixerNode.volume = 0      engine.attach(mixerNode)      makeConnections()      engine.prepare()    }    fileprivate func makeConnections() {      let inputNode = engine.inputNode      let inputFormat = inputNode.outputFormat(forBus: 0)      engine.connect(inputNode, to: mixerNode, format: inputFormat)      let mainMixerNode = engine.mainMixerNode      let mixerFormat = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: inputFormat.sampleRate, channels: 1, interleaved: false)      engine.connect(mixerNode, to: mainMixerNode, format: mixerFormat)    }        func startRecording() throws {      let tapNode: AVAudioNode = mixerNode        let format = tapNode.outputFormat(forBus: 0)        self.recording_file = try AVAudioFile(forWriting: get_file_path(), settings: format.settings)        tapNode.installTap(onBus: 0, bufferSize: 8192, format: format, block: {          (buffer, time) in          do {try self.recording_file.write(from: buffer)}          catch {print(error.localizedDescription)}        })        try engine.start()    } }
0
0
490
Mar ’23
In watchos, Can we implement the action when the screen is covered with hand?
In watchos we can back to clock(homescreen) by two way. click dial cover screen with hand My app record audio with avaudioengine. But when i try to back to clock by two way written above. App didn't stay in background, but appear in screen with inactive state. For example, built-in voice recording app excuted in background when we go back to clock by clicking dial. And the app also go back to clock when covering screen with hand. How can i make my app stay in background when dial clicked like built-in recording app.
0
0
519
Feb ’23