|
|
@@ -59,7 +59,8 @@ class LNEditVoicePanel: LNPopupView {
|
|
|
guard let self else { return }
|
|
|
LNVoicePlayer.shared.stop()
|
|
|
if LNVoiceRecorder.shared.isRecording {
|
|
|
- stopRecord()
|
|
|
+ let (url, duration) = LNVoiceRecorder.shared.stopRecord()
|
|
|
+ handleRecordResult(url: url, duration: duration)
|
|
|
} else if curState == .edit {
|
|
|
let alert = LNCommonAlertView()
|
|
|
alert.titleLabel.text = .init(key: "B00018")
|
|
|
@@ -96,8 +97,7 @@ extension LNEditVoicePanel {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private func stopRecord() {
|
|
|
- let (url, duration) = LNVoiceRecorder.shared.stopRecord()
|
|
|
+ private func handleRecordResult(url: URL?, duration: Double) {
|
|
|
guard let url else {
|
|
|
return
|
|
|
}
|
|
|
@@ -107,7 +107,7 @@ extension LNEditVoicePanel {
|
|
|
}
|
|
|
curUrl = url
|
|
|
curDuration = duration
|
|
|
- let intDuration = Int(duration)
|
|
|
+ let intDuration = duration.toDuration
|
|
|
editDurationLabel.text = String(format: "%02d:%02d", intDuration / 60, intDuration % 60)
|
|
|
curState = .edit
|
|
|
}
|
|
|
@@ -115,37 +115,39 @@ extension LNEditVoicePanel {
|
|
|
|
|
|
extension LNEditVoicePanel: LNVoicePlayerNotify {
|
|
|
func onAudioUpdateDuration(path: String, cur: TimeInterval, total: TimeInterval) {
|
|
|
- guard curUrl?.path == path else { return }
|
|
|
-
|
|
|
if !editView.isHidden {
|
|
|
+ guard curUrl?.path == path else { return }
|
|
|
let remain = Int(total - cur)
|
|
|
editDurationLabel.text = String(format: "%02d:%02d", remain / 60, remain % 60)
|
|
|
} else if !displayView.isHidden {
|
|
|
+ guard path == myUserInfo.voiceBar else { return }
|
|
|
playDurationLabel.text = (total - cur).durationDisplay
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func onAudioStopPlay(path: String) {
|
|
|
- guard curUrl?.path == path else { return }
|
|
|
-
|
|
|
- guard let curDuration else { return }
|
|
|
if !editView.isHidden {
|
|
|
- let intDuration = Int(curDuration)
|
|
|
+ guard curUrl?.path == path else { return }
|
|
|
+ guard let curDuration else { return }
|
|
|
+ let intDuration = curDuration.toDuration
|
|
|
editDurationLabel.text = String(format: "%02d:%02d", intDuration / 60, intDuration % 60)
|
|
|
editPlayButton.setImage(.icVoiceEditPlay, for: .normal)
|
|
|
} else if !displayView.isHidden {
|
|
|
- playDurationLabel.text = curDuration.durationDisplay
|
|
|
+ guard path == myUserInfo.voiceBar else { return }
|
|
|
+ playDurationLabel.text = "\(myVoiceBarInfo.voiceBarDuration)“"
|
|
|
playIcon.image = .icVoicePlay
|
|
|
+ voiceWaveView.stopAnimate()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func onAudioStartPlay(path: String) {
|
|
|
- guard curUrl?.path == path else { return }
|
|
|
-
|
|
|
- if !displayView.isHidden {
|
|
|
- playIcon.image = .icVoicePause
|
|
|
- } else if !editView.isHidden {
|
|
|
+ if !editView.isHidden {
|
|
|
+ guard curUrl?.path == path else { return }
|
|
|
editPlayButton.setImage(.icVoiceEditPause, for: .normal)
|
|
|
+ } else if !displayView.isHidden {
|
|
|
+ guard path == myUserInfo.voiceBar else { return }
|
|
|
+ playIcon.image = .icVoicePause
|
|
|
+ voiceWaveView.startAnimate()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -174,11 +176,7 @@ extension LNEditVoicePanel: LNVoiceRecorderNotify {
|
|
|
func onRecordTaskReachMaxDuration(taskId: String, fileUrl: URL?, duration: Double) {
|
|
|
guard recordTaskId == taskId else { return }
|
|
|
|
|
|
- curUrl = fileUrl
|
|
|
- curDuration = duration
|
|
|
- let intDuration = Int(duration)
|
|
|
- editDurationLabel.text = String(format: "%02d:%02d", intDuration / 60, intDuration % 60)
|
|
|
- curState = .edit
|
|
|
+ handleRecordResult(url: fileUrl, duration: duration)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -267,7 +265,8 @@ extension LNEditVoicePanel {
|
|
|
recordButton.addAction(UIAction(handler: { [weak self] _ in
|
|
|
guard let self else { return }
|
|
|
if LNVoiceRecorder.shared.isRecording {
|
|
|
- stopRecord()
|
|
|
+ let (url, duration) = LNVoiceRecorder.shared.stopRecord()
|
|
|
+ handleRecordResult(url: url, duration: duration)
|
|
|
} else {
|
|
|
recordTaskId = LNVoiceRecorder.shared.startRecord(maxDuration)
|
|
|
}
|
|
|
@@ -407,7 +406,7 @@ extension LNEditVoicePanel {
|
|
|
showToast(err)
|
|
|
return
|
|
|
}
|
|
|
- LNProfileManager.shared.setMyVoiceBar(url: url, duration: Int(curDuration))
|
|
|
+ LNProfileManager.shared.setMyVoiceBar(url: url, duration: curDuration.toDuration)
|
|
|
{ [weak self] success in
|
|
|
guard let self else { return }
|
|
|
guard success else { return }
|