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 4109782
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:50:44+00:00 2026-05-20T21:50:44+00:00

I am using AVAudioPlayer to play a 15 audio files. The audio files need

  • 0

I am using AVAudioPlayer to play a 15 audio files. The audio files need to be played in sets of 5 with each set having three files. The three files within a set do not change. The order that the sets are played may change.

I tried using a while loop with isPlaying like this:

while ([backgroundSound isPlaying]) {
    NSLog(@"First while loop");
}
backgroundSoundPath = [[NSBundle mainBundle] pathForResource:@"Set0File1" ofType:@"mp3"]; // *Music filename* 
backgroundSound =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:backgroundSoundPath] error:nil];
[backgroundSound prepareToPlay];
[backgroundSound play];
while ([backgroundSound isPlaying]) {
    NSLog(@"Second while loop");
}
backgroundSoundPath = [[NSBundle mainBundle] pathForResource:@"Set0File2" ofType:@"mp3"]; // *Music filename* 
backgroundSound =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:backgroundSoundPath] error:nil];
[backgroundSound prepareToPlay];
[backgroundSound play];
while ([backgroundSound isPlaying]) {
    NSLog(@"Third while loop");
} 

I now realize that this is wrong with the side effect being that the entire UI is locked up for the duration of the file being played.

I know I should be using:

  • (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag

But I do not know how audioPlayerDidFinishPlaying is supposed to know exactly which file has finished playing.

I thought it might be like – (void)animationDidStop where you can use a valueForKeyPath to figure out which file was finished playing.

Does it have to be tracked manually?

Any suggestions to point me in the right direction would be appreciated.

Thank you.

  • 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-20T21:50:45+00:00Added an answer on May 20, 2026 at 9:50 pm

    When an AVAudioPlayer calls the audioPlayerDidFinishPlaying method, it supplies itself as an argument. So what you should do is check the URL to figure out which file just finished playing.

    -(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
    {
         if ([player.url isEqual:url1])
         {
             // file which is in url1 stopped playing
         }
         else if ([player.url isEqual:url2])
         {
             // file which is in url2 stopped playing
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using multiple instances of AVAudioPlayer to play multiple audio files simultaneously. I
I'm trying to play sequence of audio files in the background using AVAudioPlayer. When
I am using AVAudioplayer to play some audio files. I have some controls like
I am using the AVAudioPlayer class to play .mp3 files in my App. Is
I am using AVAudioPlayer object to play an audio. I created an audioPlayer object
Alright I have two problems. I'm using AVAudioPlayer to play a simple audio file
I am using AVFoundation to play wav files. But i could not make it
Im using the AVFoundation framework to play sound files. The problem im having is
i tried to play an audio file from internet using AVAudioplayer but there is
I am trying to play an audio clip (using AVAudioPlayer) and a video clip

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.