fix: play audio between two toots
This commit is contained in:
parent
04d960c890
commit
2b02b8deb6
@ -20,18 +20,18 @@ class AudioContainerViewModel {
|
|||||||
|
|
||||||
audioView.playButton.publisher(for: .touchUpInside)
|
audioView.playButton.publisher(for: .touchUpInside)
|
||||||
.sink { _ in
|
.sink { _ in
|
||||||
if AudioPlayer.shared.isPlaying() {
|
|
||||||
AudioPlayer.shared.pause()
|
if audioAttachment === AudioPlayer.shared.attachment {
|
||||||
} else {
|
if AudioPlayer.shared.isPlaying() {
|
||||||
if audioAttachment === AudioPlayer.shared.attachment {
|
AudioPlayer.shared.pause()
|
||||||
if AudioPlayer.shared.currentTimeSubject.value == 0 {
|
|
||||||
AudioPlayer.shared.playAudio(audioAttachment: audioAttachment)
|
|
||||||
} else {
|
|
||||||
AudioPlayer.shared.resume()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
|
AudioPlayer.shared.resume()
|
||||||
|
}
|
||||||
|
if AudioPlayer.shared.currentTimeSubject.value == 0 {
|
||||||
AudioPlayer.shared.playAudio(audioAttachment: audioAttachment)
|
AudioPlayer.shared.playAudio(audioAttachment: audioAttachment)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
AudioPlayer.shared.playAudio(audioAttachment: audioAttachment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.store(in: &cell.disposeBag)
|
.store(in: &cell.disposeBag)
|
||||||
@ -44,7 +44,7 @@ class AudioContainerViewModel {
|
|||||||
.store(in: &cell.disposeBag)
|
.store(in: &cell.disposeBag)
|
||||||
self.observePlayer(cell: cell, audioAttachment: audioAttachment)
|
self.observePlayer(cell: cell, audioAttachment: audioAttachment)
|
||||||
if audioAttachment != AudioPlayer.shared.attachment {
|
if audioAttachment != AudioPlayer.shared.attachment {
|
||||||
self.resetAudioView(audioView: audioView)
|
self.resetAudioView(audioView: audioView, audioAttachment: audioAttachment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,18 +73,23 @@ class AudioContainerViewModel {
|
|||||||
audioView.playButton.isSelected = isPlaying
|
audioView.playButton.isSelected = isPlaying
|
||||||
audioView.slider.isEnabled = isPlaying
|
audioView.slider.isEnabled = isPlaying
|
||||||
if playbackState == .stopped {
|
if playbackState == .stopped {
|
||||||
self.resetAudioView(audioView: audioView)
|
self.resetAudioView(audioView: audioView, audioAttachment: audioAttachment)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.resetAudioView(audioView: audioView)
|
self.resetAudioView(audioView: audioView, audioAttachment: audioAttachment)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.store(in: &cell.disposeBag)
|
.store(in: &cell.disposeBag)
|
||||||
}
|
}
|
||||||
|
|
||||||
static func resetAudioView(audioView: AudioContainerView) {
|
static func resetAudioView(
|
||||||
|
audioView: AudioContainerView,
|
||||||
|
audioAttachment: Attachment
|
||||||
|
) {
|
||||||
audioView.playButton.isSelected = false
|
audioView.playButton.isSelected = false
|
||||||
audioView.slider.setValue(0, animated: false)
|
audioView.slider.setValue(0, animated: false)
|
||||||
audioView.slider.isEnabled = false
|
audioView.slider.isEnabled = false
|
||||||
|
guard let duration = audioAttachment.meta?.original?.duration else { return }
|
||||||
|
audioView.timeLabel.text = duration.asString(style: .positional)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ extension AudioPlayer {
|
|||||||
self.playbackState.value = .playing
|
self.playbackState.value = .playing
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
player.pause()
|
||||||
let playerItem = AVPlayerItem(url: url)
|
let playerItem = AVPlayerItem(url: url)
|
||||||
player.replaceCurrentItem(with: playerItem)
|
player.replaceCurrentItem(with: playerItem)
|
||||||
attachment = audioAttachment
|
attachment = audioAttachment
|
||||||
|
Loading…
x
Reference in New Issue
Block a user