You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For animation - there should be a way to get the power levels continuously. Example implementation using the framework at the moment:
import SwiftUI
import Media
import Combine
classRecordingWaveViewModel:ObservableObject{privateletrecorder:AudioRecorderprivatevarcancellables=Set<AnyCancellable>()privatevartimer:Timer?@Publishedvarsamples:[Float]=[]init(recorder:AudioRecorder){self.recorder = recorder
observeRecorderState()}privatefunc observeRecorderState(){
recorder.$state
.receive(on:RunLoop.main).sink{[weak self] newState inself?.handleStateChange(newState)}.store(in:&cancellables)}privatefunc handleStateChange(_ newState:AudioRecorder.State){
switch newState {case.recording:startTimer()default:stopTimer()}}privatefunc startTimer(){
// Start or reset the timer to update the samples
timer?.invalidate() // Invalidate any existing timer
timer =Timer.scheduledTimer(withTimeInterval: 0.05, repeats: true){[weak self] _ in
guard let self =selfelse{return}letpower=1-self.recorder.normalizedPowerLevel
// add three times to show the wave as faster
self.samples.append(contentsOf:[power,power,power])}}privatefunc stopTimer(){
timer?.invalidate()
timer =nil
samples =[]}}
The text was updated successfully, but these errors were encountered:
For animation - there should be a way to get the power levels continuously. Example implementation using the framework at the moment:
The text was updated successfully, but these errors were encountered: