Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion today-s-sound/App/TodaySSoundApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDele

// 등록된 사용자인지 확인
guard let userId = Keychain.getString(for: KeychainKey.userId),
let deviceSecret = Keychain.getString(for: KeychainKey.deviceSecret) else {
let deviceSecret = Keychain.getString(for: KeychainKey.deviceSecret)
else {
// 미등록 사용자는 registerIfNeeded()에서 토큰과 함께 등록됨
print("ℹ️ [FCM] 미등록 사용자 - 서버 업데이트 생략 (추후 등록 시 전송)")
print("====================================\n")
Expand Down
12 changes: 9 additions & 3 deletions today-s-sound/Presentation/Features/Main/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@ struct HomeView: View {
Button(
action: {
if speechService.isSpeaking {
speechService.stop()
// 재생 중 → 일시정지
viewModel.pausePlayback()
} else if viewModel.isPaused {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

MainViewModel의 중복된 isPaused 상태 대신, SpeechService의 상태를 직접 사용하는 것이 상태 관리 측면에서 더 안전하고 명확합니다.

Suggested change
} else if viewModel.isPaused {
} else if speechService.isPaused {

// 일시정지 상태 → 이어서 재생
viewModel.resumePlayback()
} else {
// 홈 피드가 있으면 첫 번째 피드 아이템 재생
// 정지 상태 → 처음부터 재생
if !viewModel.homeFeedItems.isEmpty {
viewModel.playFirstFeedItem()
} else {
SpeechService.shared.speak(text: "아직 구독한 페이지가 없거나 새로운 글이 없습니다.")
}
}
},
Expand All @@ -50,7 +56,7 @@ struct HomeView: View {
.padding(20)
}
)
.accessibilityLabel(speechService.isSpeaking ? "재생 중단" : "재생 시작")
.accessibilityLabel(speechService.isSpeaking ? "일시정지" : viewModel.isPaused ? "이어서 재생" : "재생 시작")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

MainViewModel의 중복된 isPaused 상태 대신, SpeechService의 상태를 직접 사용하는 것이 상태 관리 측면에서 더 안전하고 명확합니다.

Suggested change
.accessibilityLabel(speechService.isSpeaking ? "일시정지" : viewModel.isPaused ? "이어서 재생" : "재생 시작")
.accessibilityLabel(speechService.isSpeaking ? "일시정지" : speechService.isPaused ? "이어서 재생" : "재생 시작")

.padding(.bottom, 60)

Spacer()
Expand Down
14 changes: 14 additions & 0 deletions today-s-sound/Presentation/Features/Main/MainViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class MainViewModel: ObservableObject {
@Published var recentAlerts: [Alert] = []
@Published var homeFeedItems: [HomeFeedItemResponse] = []
@Published var isLoading: Bool = false
@Published var isPaused: Bool = false

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

isPaused 상태가 SpeechServiceMainViewModel에 중복으로 정의되어 있습니다. 이로 인해 두 상태가 동기화되지 않을 경우 예기치 않은 동작이 발생할 수 있습니다.

SpeechService가 음성 재생 상태에 대한 단일 진실 공급원(Single Source of Truth) 역할을 하도록 구조를 개선하는 것이 좋습니다.

제안:

  1. MainViewModel에서 isPaused 속성을 제거합니다.
  2. pausePlayback, resumePlayback, stopPlayback 메서드에서 isPaused 상태를 직접 변경하는 코드를 제거합니다.
  3. HomeView에서는 viewModel.isPaused 대신 speechService.isPaused를 직접 사용하여 UI 상태를 결정합니다. (HomeView는 이미 speechService를 관찰하고 있으므로 쉽게 변경할 수 있습니다.)

이렇게 하면 상태 관리가 단순해지고 잠재적인 버그를 예방할 수 있습니다.

@Published var errorMessage: String?

private let apiService: APIService
Expand Down Expand Up @@ -163,12 +164,25 @@ class MainViewModel: ObservableObject {
playCurrentGroup()
}

/// 일시정지
func pausePlayback() {
SpeechService.shared.pause()
isPaused = true
}

/// 이어서 재생
func resumePlayback() {
SpeechService.shared.resume()
isPaused = false
}

/// 재생 중단 시 큐 초기화
func stopPlayback() {
SpeechService.shared.stop()
playbackQueue = []
currentGroupIndex = 0
currentItemIndex = 0
isPaused = false
}

/// 현재 그룹 재생 (카테고리명 먼저, 그 다음 summary들)
Expand Down
27 changes: 22 additions & 5 deletions today-s-sound/Services/SpeechService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class SpeechService: NSObject, ObservableObject, AVSpeechSynthesizerDelegate {
let didFinishSpeaking = PassthroughSubject<Void, Never>()

@Published var isSpeaking: Bool = false
@Published var isPaused: Bool = false

override private init() {
super.init()
Expand Down Expand Up @@ -39,21 +40,37 @@ class SpeechService: NSObject, ObservableObject, AVSpeechSynthesizerDelegate {
}

// Stop any speaking in progress before starting a new one
if synthesizer.isSpeaking {
if synthesizer.isSpeaking || isPaused {
synthesizer.stopSpeaking(at: .immediate)
// 중단 이벤트는 didFinishSpeaking으로 전달하지 않음
}

isPaused = false
isSpeaking = true
synthesizer.speak(utterance)
}

func stop() {
func pause() {
if synthesizer.isSpeaking {
synthesizer.stopSpeaking(at: .immediate)
isSpeaking = false
isPaused = true
synthesizer.pauseSpeaking(at: .immediate)
}
}

func resume() {
if isPaused {
isPaused = false
isSpeaking = true
synthesizer.continueSpeaking()
}
}

func stop() {
isSpeaking = false
// stop() 호출 시에는 didFinishSpeaking 이벤트를 보내지 않음 (의도적 중단)
isPaused = false
if synthesizer.isSpeaking || synthesizer.isPaused {
synthesizer.stopSpeaking(at: .immediate)
}
}

// MARK: - AVSpeechSynthesizerDelegate
Expand Down
Loading