diff --git a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/Write/CreatorCommunityRecordingVoiceView.swift b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/Write/CreatorCommunityRecordingVoiceView.swift index 41a01c6..f9e207a 100644 --- a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/Write/CreatorCommunityRecordingVoiceView.swift +++ b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/Write/CreatorCommunityRecordingVoiceView.swift @@ -7,15 +7,9 @@ import SwiftUI -struct CreatorCommunityRecordingVoiceView: View { - enum RecordMode { - case RECORD, PLAY - } - +struct CreatorCommunityRecordingVoiceView: View { @StateObject var soundManager = CreatorCommunitySoundManager() - @State var recordMode = RecordMode.RECORD - @Binding var isShowing: Bool @Binding var isShowPopup: Bool @Binding var errorMessage: String @@ -57,7 +51,7 @@ struct CreatorCommunityRecordingVoiceView: View { .foregroundColor(.white) .padding(.top, 80) - switch recordMode { + switch soundManager.recordMode { case .RECORD: if !soundManager.isLoading { Image(soundManager.isRecording ? "ic_record_stop" : "ic_record") @@ -71,7 +65,7 @@ struct CreatorCommunityRecordingVoiceView: View { soundManager.startRecording(tempFileName) } else { soundManager.stopRecording() - recordMode = .PLAY + soundManager.recordMode = .PLAY } } } @@ -112,12 +106,12 @@ struct CreatorCommunityRecordingVoiceView: View { .onTapGesture { soundManager.stopAudio() soundManager.deleteAudioFile() - recordMode = .RECORD + soundManager.recordMode = .RECORD } Spacer() } - .padding(.top, 80) + .padding(.vertical, 52.3) HStack(spacing: 13.3) { Text("다시 녹음") @@ -133,7 +127,7 @@ struct CreatorCommunityRecordingVoiceView: View { .onTapGesture { soundManager.stopAudio() soundManager.deleteAudioFile() - recordMode = .RECORD + soundManager.recordMode = .RECORD } Text("녹음완료") @@ -154,7 +148,7 @@ struct CreatorCommunityRecordingVoiceView: View { } } } - .padding(.vertical, 40) + .padding(.bottom, 40) .padding(.horizontal, 13.3) } } diff --git a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/Write/CreatorCommunitySoundManager.swift b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/Write/CreatorCommunitySoundManager.swift index 2795744..b35d767 100644 --- a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/Write/CreatorCommunitySoundManager.swift +++ b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/Write/CreatorCommunitySoundManager.swift @@ -10,6 +10,12 @@ import AVKit import Combine class CreatorCommunitySoundManager: NSObject, ObservableObject { + enum RecordMode { + case RECORD, PLAY + } + + @Published var recordMode = RecordMode.RECORD + @Published var errorMessage = "" @Published var isShowPopup = false @Published var isLoading = false @@ -176,6 +182,11 @@ class CreatorCommunitySoundManager: NSObject, ObservableObject { let centiseconds = Int((elapsedTime - Double(minutes * 60) - Double(seconds)) * 100) timeString = String(format: "%02d:%02d.%02d", minutes, seconds, centiseconds) + + if minutes >= 3 { + stopRecording() + recordMode = .PLAY + } } deinit { diff --git a/SodaLive/Sources/Message/Voice/SoundManager.swift b/SodaLive/Sources/Message/Voice/SoundManager.swift index 3fdd49e..f39b6bb 100644 --- a/SodaLive/Sources/Message/Voice/SoundManager.swift +++ b/SodaLive/Sources/Message/Voice/SoundManager.swift @@ -24,13 +24,15 @@ class SoundManager: NSObject, ObservableObject { var startTimer: (() -> Void)? var stopTimer: (() -> Void)? + let audioSession = AVAudioSession.sharedInstance() + func prepareRecording() { isLoading = true - let audioSession = AVAudioSession.sharedInstance() do { try audioSession.setCategory(.playAndRecord, mode: .default) try audioSession.setActive(true) + audioSession.requestRecordPermission() { [weak self] allowed in DispatchQueue.main.async { if !allowed { @@ -58,6 +60,9 @@ class SoundManager: NSObject, ObservableObject { ] do { + try audioSession.setCategory(.playAndRecord, mode: .default) + try audioSession.setActive(true) + audioRecorder = try AVAudioRecorder(url: getAudioFileURL(), settings: settings) audioRecorder.record() @@ -91,9 +96,9 @@ class SoundManager: NSObject, ObservableObject { isLoading = true DispatchQueue.main.async { - let audioSession = AVAudioSession.sharedInstance() do { - try audioSession.setCategory(.playback, mode: .default) + try self.audioSession.setCategory(.playAndRecord, mode: .default) + try self.audioSession.setActive(true) if let url = url { self.player = try AVAudioPlayer(data: Data(contentsOf: url))