From 247fcf0eb38c550f55883a8e46388201cf73b94a Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Mon, 26 Sep 2022 20:46:28 +0800 Subject: [PATCH] Dont display loading indicator if audio is not playing when voice is changed --- .../App/Views/Profile/TextToSpeechLanguageView.swift | 2 +- .../App/Views/Profile/TextToSpeechVoiceSelectionView.swift | 2 +- .../Sources/Services/AudioSession/AudioController.swift | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/Profile/TextToSpeechLanguageView.swift b/apple/OmnivoreKit/Sources/App/Views/Profile/TextToSpeechLanguageView.swift index 75da7c582..2b35325b7 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Profile/TextToSpeechLanguageView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Profile/TextToSpeechLanguageView.swift @@ -32,7 +32,7 @@ struct TextToSpeechLanguageView: View { Spacer() if audioController.defaultLanguage == language.key { - if audioController.isLoading { + if audioController.isPlaying, audioController.isLoading { ProgressView() } else { Image(systemName: "checkmark") diff --git a/apple/OmnivoreKit/Sources/App/Views/Profile/TextToSpeechVoiceSelectionView.swift b/apple/OmnivoreKit/Sources/App/Views/Profile/TextToSpeechVoiceSelectionView.swift index ea4639cb5..1d6e3e11c 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Profile/TextToSpeechVoiceSelectionView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Profile/TextToSpeechVoiceSelectionView.swift @@ -54,7 +54,7 @@ struct TextToSpeechVoiceSelectionView: View { Spacer() if voice.selected { - if audioController.isLoading { + if audioController.isPlaying, audioController.isLoading { ProgressView() } else { Image(systemName: "checkmark") diff --git a/apple/OmnivoreKit/Sources/Services/AudioSession/AudioController.swift b/apple/OmnivoreKit/Sources/Services/AudioSession/AudioController.swift index fd238c27b..61cd7133a 100644 --- a/apple/OmnivoreKit/Sources/Services/AudioSession/AudioController.swift +++ b/apple/OmnivoreKit/Sources/Services/AudioSession/AudioController.swift @@ -525,6 +525,10 @@ public class AudioController: NSObject, ObservableObject, AVAudioPlayerDelegate return (state == .loading || player?.currentItem == nil || player?.currentItem?.status == .unknown) } + public var isPlaying: Bool { + state == .playing + } + public func isLoadingItem(itemID: String) -> Bool { if state == .reachedEnd { return false @@ -533,7 +537,7 @@ public class AudioController: NSObject, ObservableObject, AVAudioPlayerDelegate } public func isPlayingItem(itemID: String) -> Bool { - state == .playing && itemAudioProperties?.itemID == itemID + itemAudioProperties?.itemID == itemID && isPlaying } public func skipForward(seconds: Double) {