Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7650319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:13:18+00:00 2026-05-31T11:13:18+00:00

I am developing an iOS audio player, and I want to implement a progress

  • 0

I am developing an iOS audio player, and I want to implement a progress bar that will indicate the progress of the current song which is playing.
In my ViewController class, I have 2 double instances – time and duration, and a AVAudioPlayer instance called background.

- (IBAction)play:(id)sender {
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"some_song" ofType:@"mp3"];
    NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
    background = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
    background.delegate = self;
    [background setNumberOfLoops:1];
    [background setVolume:0.5];
    [background play];
    time = 0;
    duration = [background duration];
    while(time < duration){
        [progressBar setProgress: (double) time/duration animated:YES];
        time += 1; 
    } 
}

Could anyone explain what I am doing wrong?
Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:13:20+00:00Added an answer on May 31, 2026 at 11:13 am

    you don’t update the progress of the progress bar during playback. When you start to play the sound you set the progress bar to 1, to 2, to 3, to 4, to 5… to 100%. All without leaving the current runloop. Which means you will only see the last step, a full progress bar.

    You should use a NSTimer to update the progress bar. Something like this:

    - (IBAction)play:(id)sender {
        /* ... */
        [self.player play];
        self.timer = [NSTimer scheduledTimerWithTimeInterval:0.23 target:self selector:@selector(updateProgressBar:) userInfo:nil repeats:YES];
    }
    
    - (void)updateProgressBar:(NSTimer *)timer {
        NSTimeInterval playTime = [self.player currentTime];
        NSTimeInterval duration = [self.player duration];
        float progress = playTime/duration;
        [self.progressView setProgress:progress];
    }
    

    when you stop playing invalidate the timer.

    [self.timer invalidate];
    self.timer = nil;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an iOS application , that will take a twits from twitter, I'm
I am developing an iOS app that must handle several stereo audio files (ranging
I have been developing an app that supports streaming video and audio, among other
We developing a iOS app that uses CoreData. To keep ourselves from going crazy
I'm developing an iOS app with latest SDK and XCode 4.2. I want to
I am developing an iOS application which resembles a musical instrument. I am trying
I am developing an iOS Application which loads its content from an XML-file over
I'm developing on iOS and I'm building my views programmatically. I noticed that when
I'm developing an iOS App and I want to make a table view, but
I'm developing an IOS app that creates files on the device, e.g. with NSKeyedArchiver

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.