mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Better handling of loading state when playing back audio
This commit is contained in:
parent
cdd5ba7417
commit
4ea42161b3
2 changed files with 41 additions and 27 deletions
|
|
@ -56,6 +56,41 @@ struct WebReaderContainerView: View {
|
|||
}
|
||||
}
|
||||
|
||||
var audioNavbarItem: some View {
|
||||
if audioSession.isLoadingItem(item: item) {
|
||||
return AnyView(ProgressView()
|
||||
.padding(.horizontal)
|
||||
.scaleEffect(navBarVisibilityRatio))
|
||||
} else {
|
||||
return AnyView(Button(
|
||||
action: {
|
||||
switch audioSession.state {
|
||||
case .playing:
|
||||
if audioSession.item == self.item {
|
||||
audioSession.pause()
|
||||
return
|
||||
}
|
||||
fallthrough
|
||||
case .paused:
|
||||
if audioSession.item == self.item {
|
||||
audioSession.unpause()
|
||||
return
|
||||
}
|
||||
fallthrough
|
||||
default:
|
||||
audioSession.play(item: self.item)
|
||||
}
|
||||
},
|
||||
label: {
|
||||
Image(systemName: audioSession.isPlayingItem(item: item) ? "pause.circle" : "play.circle")
|
||||
.font(.appTitleTwo)
|
||||
}
|
||||
)
|
||||
.padding(.horizontal)
|
||||
.scaleEffect(navBarVisibilityRatio))
|
||||
}
|
||||
}
|
||||
|
||||
var navBar: some View {
|
||||
HStack(alignment: .center) {
|
||||
#if os(iOS)
|
||||
|
|
@ -72,32 +107,7 @@ struct WebReaderContainerView: View {
|
|||
Spacer()
|
||||
#endif
|
||||
if FeatureFlag.enableTextToSpeechButton {
|
||||
Button(
|
||||
action: {
|
||||
switch audioSession.state {
|
||||
case .playing:
|
||||
if audioSession.item == self.item {
|
||||
audioSession.pause()
|
||||
return
|
||||
}
|
||||
fallthrough
|
||||
case .paused:
|
||||
if audioSession.item == self.item {
|
||||
audioSession.unpause()
|
||||
return
|
||||
}
|
||||
fallthrough
|
||||
default:
|
||||
audioSession.play(item: self.item)
|
||||
}
|
||||
},
|
||||
label: {
|
||||
Image(systemName: audioSession.isPlayingItem(item: item) ? "pause.circle" : "play.circle")
|
||||
.font(.appTitleTwo)
|
||||
}
|
||||
)
|
||||
.padding(.horizontal)
|
||||
.scaleEffect(navBarVisibilityRatio)
|
||||
audioNavbarItem
|
||||
}
|
||||
Button(
|
||||
action: { showPreferencesPopover.toggle() },
|
||||
|
|
|
|||
|
|
@ -47,6 +47,10 @@ public class AudioSession: ObservableObject {
|
|||
item = nil
|
||||
}
|
||||
|
||||
public func isLoadingItem(item: LinkedItem) -> Bool {
|
||||
state == .loading && self.item == item
|
||||
}
|
||||
|
||||
public func isPlayingItem(item: LinkedItem) -> Bool {
|
||||
state == .playing && self.item == item
|
||||
}
|
||||
|
|
@ -55,7 +59,7 @@ public class AudioSession: ObservableObject {
|
|||
state = .loading
|
||||
|
||||
// Just simulating some loading delay here
|
||||
DispatchQueue.main.asyncAfter(deadline: .now()) {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(1000)) {
|
||||
self.audioUrl = Bundle.main.url(forResource: "speech-sample", withExtension: "mp3")!
|
||||
if let url = self.audioUrl {
|
||||
do {
|
||||
|
|
|
|||
Loading…
Reference in a new issue