From 85a871693cdb6ff509f6df6a6d7371feaed0dc72 Mon Sep 17 00:00:00 2001 From: Yu Sung Date: Thu, 8 Aug 2024 01:34:14 +0900 Subject: [PATCH] =?UTF-8?q?=EC=BB=A4=EB=AE=A4=EB=8B=88=ED=8B=B0=20?= =?UTF-8?q?=EC=98=A4=EB=94=94=EC=98=A4=20=EB=85=B9=EC=9D=8C=20-=20audioSes?= =?UTF-8?q?sion.setCategory=20mode=20videoRecording=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CreatorCommunityRecordingVoiceView.swift | 12 ++++++------ .../Write/CreatorCommunitySoundManager.swift | 16 +++++++++++----- .../Write/CreatorCommunityWriteView.swift | 1 + 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/Write/CreatorCommunityRecordingVoiceView.swift b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/Write/CreatorCommunityRecordingVoiceView.swift index eb95fd5..41a01c6 100644 --- a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/Write/CreatorCommunityRecordingVoiceView.swift +++ b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/Write/CreatorCommunityRecordingVoiceView.swift @@ -23,6 +23,8 @@ struct CreatorCommunityRecordingVoiceView: View { @Binding var fileName: String @Binding var soundData: Data? + @State private var tempFileName = "" + var body: some View { ZStack { Color.black.opacity(0.7) @@ -65,9 +67,8 @@ struct CreatorCommunityRecordingVoiceView: View { .onTapGesture { if !soundManager.isLoading { if !soundManager.isRecording { - let fileName = "\(Date().timeIntervalSince1970 * 1000).m4a" - self.fileName = fileName - soundManager.startRecording(fileName) + tempFileName = "now_voice_\(Int(Date().timeIntervalSince1970 * 1000)).m4a" + soundManager.startRecording(tempFileName) } else { soundManager.stopRecording() recordMode = .PLAY @@ -84,7 +85,7 @@ struct CreatorCommunityRecordingVoiceView: View { Text("삭제") .font(.custom(Font.medium.rawValue, size: 15.3)) - .foregroundColor(Color(hex: "bbbbbb").opacity(0)) + .foregroundColor(Color.graybb.opacity(0)) Spacer() @@ -112,7 +113,6 @@ struct CreatorCommunityRecordingVoiceView: View { soundManager.stopAudio() soundManager.deleteAudioFile() recordMode = .RECORD - fileName = "녹음" } Spacer() @@ -134,7 +134,6 @@ struct CreatorCommunityRecordingVoiceView: View { soundManager.stopAudio() soundManager.deleteAudioFile() recordMode = .RECORD - fileName = "녹음" } Text("녹음완료") @@ -147,6 +146,7 @@ struct CreatorCommunityRecordingVoiceView: View { do { let soundData = try Data(contentsOf: soundManager.getAudioFileURL()) self.soundData = soundData + self.fileName = tempFileName self.isShowing = false } catch { errorMessage = "녹음파일을 생성하지 못했습니다.\n다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다." diff --git a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/Write/CreatorCommunitySoundManager.swift b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/Write/CreatorCommunitySoundManager.swift index 26a5c8e..2795744 100644 --- a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/Write/CreatorCommunitySoundManager.swift +++ b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/Write/CreatorCommunitySoundManager.swift @@ -26,14 +26,14 @@ class CreatorCommunitySoundManager: NSObject, ObservableObject { var player: AVAudioPlayer! var audioRecorder: AVAudioRecorder! - var fileName = "record.m4a" + var fileName = "now_voice.m4a" + let audioSession = AVAudioSession.sharedInstance() func prepareRecording() { isLoading = true - let audioSession = AVAudioSession.sharedInstance() do { - try audioSession.setCategory(.playAndRecord, mode: .default) + try audioSession.setCategory(.playAndRecord, mode: .videoRecording) try audioSession.setActive(true) audioSession.requestRecordPermission() { [weak self] allowed in DispatchQueue.main.async { @@ -56,6 +56,9 @@ class CreatorCommunitySoundManager: NSObject, ObservableObject { func startRecording(_ fileName: String) { self.fileName = fileName + player?.stop() + player = nil + isLoading = true let settings = [ AVFormatIDKey: Int(kAudioFormatMPEG4AAC), @@ -66,6 +69,9 @@ class CreatorCommunitySoundManager: NSObject, ObservableObject { ] do { + try audioSession.setCategory(.playAndRecord, mode: .videoRecording) + try audioSession.setActive(true) + audioRecorder = try AVAudioRecorder(url: getAudioFileURL(), settings: settings) audioRecorder.record() isRecording = true @@ -91,9 +97,9 @@ class CreatorCommunitySoundManager: NSObject, ObservableObject { isLoading = true DispatchQueue.main.async { - let audioSession = AVAudioSession.sharedInstance() do { - try audioSession.setCategory(.playback, mode: .default) + try self.audioSession.setCategory(.playback, mode: .default) + try self.audioSession.setActive(true) if let url = url { self.player = try AVAudioPlayer(data: Data(contentsOf: url)) diff --git a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/Write/CreatorCommunityWriteView.swift b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/Write/CreatorCommunityWriteView.swift index 438de37..9955795 100644 --- a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/Write/CreatorCommunityWriteView.swift +++ b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/Write/CreatorCommunityWriteView.swift @@ -91,6 +91,7 @@ struct CreatorCommunityWriteView: View { .background(Color.bg) .cornerRadius(5.3) .frame(maxWidth: .infinity) + .contentShape(Rectangle()) .overlay( RoundedRectangle(cornerRadius: 5.3) .stroke(Color.button, lineWidth: 1)