#4094 - Added voice messages locked mode playback.

This commit is contained in:
Stefan Ceriu
2021-06-22 13:19:39 +03:00
parent 4910066fa5
commit 172f197b4d
7 changed files with 206 additions and 52 deletions
@@ -33,7 +33,6 @@ enum VoiceMessageAudioPlayerError: Error {
class VoiceMessageAudioPlayer: NSObject {
private var contentURL: URL!
private var playerItem: AVPlayerItem?
private var audioPlayer: AVPlayer?
@@ -44,6 +43,8 @@ class VoiceMessageAudioPlayer: NSObject {
weak var delegate: VoiceMessageAudioPlayerDelegate?
private(set) var url: URL?
var isPlaying: Bool {
guard let audioPlayer = audioPlayer else {
return false
@@ -57,7 +58,9 @@ class VoiceMessageAudioPlayer: NSObject {
return 0
}
return CMTimeGetSeconds(item.duration)
let duration = CMTimeGetSeconds(item.duration)
return duration.isNaN ? 0.0 : duration
}
var currentTime: TimeInterval {
@@ -76,21 +79,18 @@ class VoiceMessageAudioPlayer: NSObject {
removeObservers()
}
override init() {
audioPlayer = AVPlayer()
}
func loadContentFromURL(_ url: URL) {
if contentURL == url {
if self.url == url {
return
}
self.url = url
removeObservers()
delegate?.audioPlayerDidStartLoading(self)
contentURL = url
playerItem = AVPlayerItem(url: contentURL)
playerItem = AVPlayerItem(url: url)
audioPlayer = AVPlayer(playerItem: playerItem)
addObservers()