getting all necessary things in place for recording and storing locally, now just cloud upload and then firestore update

This commit is contained in:
talksik
2021-12-22 04:49:29 -08:00
parent 33916a1663
commit 7284469ff9
4 changed files with 34 additions and 14 deletions
+2
View File
@@ -711,6 +711,7 @@
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "nirvana-ios/Info.plist";
INFOPLIST_KEY_NSContactsUsageDescription = "Please provide access to build your inner circle 🌱";
INFOPLIST_KEY_NSMicrophoneUsageDescription = "Please provide access to send messages 🌱";
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
@@ -745,6 +746,7 @@
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "nirvana-ios/Info.plist";
INFOPLIST_KEY_NSContactsUsageDescription = "Please provide access to build your inner circle 🌱";
INFOPLIST_KEY_NSMicrophoneUsageDescription = "Please provide access to send messages 🌱";
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
@@ -10,6 +10,7 @@ import NavigationStack
import AVKit
struct CircleGridView: View {
@EnvironmentObject var innerCircleVM: InnerCircleViewModel
@EnvironmentObject var authSessionStore: AuthSessionStore
@EnvironmentObject var navigationStack: NavigationStack
@@ -184,6 +185,7 @@ struct CircleGridView: View {
struct CircleGridView_Previews: PreviewProvider {
static var previews: some View {
CircleGridView(selectedFriendIndex: Binding.constant(nil)).environmentObject(AuthSessionStore())
.environmentObject(InnerCircleViewModel())
}
}
@@ -360,14 +362,18 @@ extension CircleGridView {
impactHeavy.impactOccurred()
}
private func record() {
// call parent view model/environment object vm functions
self.innerCircleVM.startRecording()
}
private func recordingGestureDeactived() {
// stop recording
print("stopped recording")
self.selectedFriendIndex = nil
}
private func record() {
// call parent view model/environment object vm functions
self.innerCircleVM.stopRecording()
}
}
@@ -15,6 +15,7 @@ enum SheetView : Identifiable {
}
struct InnerCircleView: View {
@StateObject var innerCircleVM: InnerCircleViewModel = InnerCircleViewModel()
@EnvironmentObject var authSessionStore: AuthSessionStore
@EnvironmentObject var navigationStack: NavigationStack
@@ -31,6 +32,7 @@ struct InnerCircleView: View {
// content
CircleGridView(selectedFriendIndex: self.$selectedFriendIndex)
.environmentObject(innerCircleVM)
// header
VStack(alignment: .leading) {
@@ -14,6 +14,8 @@ class InnerCircleViewModel: ObservableObject {
@Published var isRecording : Bool = false
private var audioLocalUrl: URL?
func startRecording() {
let recordingSession = AVAudioSession.sharedInstance()
do {
@@ -23,8 +25,9 @@ class InnerCircleViewModel: ObservableObject {
print("Can not setup the Recording")
}
let path = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let fileName = path.appendingPathComponent("\(UUID().uuidString).m4a")
let filePath = getTemporaryDirectory().appendingPathComponent("\(UUID().uuidString).m4a")
print("file name of recording will be : \(filePath)")
let settings = [
AVFormatIDKey: Int(kAudioFormatMPEG4AAC),
@@ -33,13 +36,14 @@ class InnerCircleViewModel: ObservableObject {
AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue
]
do {
audioRecorder = try AVAudioRecorder(url: fileName, settings: settings)
audioRecorder = try AVAudioRecorder(url: filePath, settings: settings)
audioRecorder.prepareToRecord()
audioRecorder.record()
isRecording = true
self.audioLocalUrl = filePath // setting this for later use when recording is stopped
} catch {
print("Failed to Setup the Recording")
}
@@ -49,14 +53,20 @@ class InnerCircleViewModel: ObservableObject {
audioRecorder.stop()
isRecording = false
// upload to the cloud storage
// store in firestore for receiving user to automatically get notified
if self.audioLocalUrl != nil {
// upload to the cloud storage
// store in firestore for receiving user to automatically get notified
// delete local audio file from user's phone so that it doesn't get crazy
print("stopped recording: file about to get deleted from \(getTemporaryDirectory()) with filename: \(self.audioLocalUrl)")
try? FileManager.default.removeItem(at: self.audioLocalUrl!)
}
}
func getDocumentsDirectory() -> URL {
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
return paths[0]
func getTemporaryDirectory() -> URL {
return FileManager.default.temporaryDirectory
}
}