I have a requirement to display a UIProgressBar
in UITableviewCell
while streaming an audio clip.
I tried running a NSTimer
and then trying to update the progress view, but its not working. This is my code. Please let me know whats wrong with this approach.
Run the timer
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.25
target:self
selector:@selector(updatePlayProgress)
userInfo:nil
repeats:YES];
Update UIProgressView in TableviewCell
- (void)updatePlayProgress {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSLog(@"Duration %f", appDelegate.moviePlayer.duration);
NSLog(@"Current time %f", appDelegate.moviePlayer.currentPlaybackTime);
float timeLeft = appDelegate.moviePlayer.currentPlaybackTime/appDelegate.moviePlayer.duration;
// upate the UIProgress
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:playingIndex inSection:0];
FeedCell *cell = (FeedCell*)[self tableView:self.tblView cellForRowAtIndexPath:indexPath];
NSLog(@"Time left %f", timeLeft);
cell.progressPlay.progress = 0.5;
[cell.progressPlay setNeedsDisplay];
}
CellForRowAtIndexPath
fCell.progressPlay.alpha = 0.5;
fCell.progressPlay.tintColor = navigationBarColor;
[fCell.progressPlay setTransform:CGAffineTransformMakeScale(fCell.frame.size.width, fCell.frame.size.height)];
[fCell.progressPlay setHidden:NO];
return fCell;
Output should be something similar to this
Eventually found the issue after almost 2 days :( :( Error was in this line
Wrong
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:playingIndex inSection:0];
FeedCell *cell = (FeedCell*)[self tableView:self.tblView cellForRowAtIndexPath:indexPath];
Corrected
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:playingIndex inSection:0];
FeedCell *cell = (FeedCell*)[self.tblView cellForRowAtIndexPath:indexPath];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With