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