I'm looking for a post/link/guide that'll programmatically help me add a UIProgressView
over UITableViewCell
. Currently, each cell I hold down plays audio streamed from Firebase and when I let go, the audio stops. I would like to add a ProgressView that covers the entire frame of the cell with a clear tint at first but turns light blue or some other color depicting it's progress from left to right. The duration of the audio will determine the rate of speed of the progress view. I have searched through SO and can only find similar posts written in Obj C years ago; looking for something written in the latest Swift language. Below is a random gif I Googled that shows what I'm looking for. Any help is greatly appreciated.
UPDATE 1:
I mananged to get the duration and apply to the progress. The UIProgressView
registers the duration the progress goes left to right accordingly. The only problem is now that when I press onto a any cell to play its respective audio, the progress bar for the first cell plays. Below is the code I'm using.
@objc func updateProgress(){
let duration = Float((player.currentItem?.duration.seconds)!)
let currentTime = Float((player.currentItem?.currentTime().seconds)!)
let progressTotal = currentTime/duration
let indexPath = IndexPath(row: self.tag, section: 0)
if progressTotal > 0 {
if let cell = tableView.cellForRow(at: indexPath) as? PostTableViewCell {
if currentTime != duration || currentTime/duration != 1 {
cell.progressBar.progress = progressTotal
cell.progressBar.progressTintColor = UIColor.blue
} else {
timer?.invalidate()
if timer != nil {
timer?.invalidate()
timer = nil
print("Timer Stopped")
}
}
}
}
}