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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:32:28+00:00 2026-05-25T15:32:28+00:00

Hi there I have an a UIView named HomeViewController that use UINavigationController. On a

  • 0

Hi there I have an a UIView named HomeViewController that use UINavigationController. On a click of a button, I push another view using the following code:

gameView = [[GameViewControler alloc] init];
    [[self navigationController] pushViewController:gameView animated:YES];
    [gameView release];

In GameViewController’s viewDidLoad, I use the following code to play two audio file one after another:

//handle sound stuff

if([[GameStore defaultStore] currentIndex] == 0)
{
    if(![audioPlayer isPlaying])
    {
        NSString *findPath = [[NSBundle mainBundle] pathForResource:@"findtheword" ofType:@"aiff"];
        if(findPath)
        {
            NSURL *findURL = [NSURL fileURLWithPath:findPath];
            NSError *findError;
            audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:findURL error:&findError];

            if(audioPlayer == nil)
            {
                NSLog([findError description]);
            }
            else{
                [audioPlayer play];
            }
        }
    }
}

while ([audioPlayer isPlaying]) {
    //do nothing and wait so the sound is not overlap
}


if(![audioPlayer isPlaying] || ([audioPlayer isPlaying] && override)){
    Word *currentWord = [[GameStore defaultStore] currentWord];
    NSString *soundPath = [[NSBundle mainBundle] pathForResource:[currentWord fileName]
                                                      ofType:[currentWord fileType]];
    // If this file is actually in the bundle...
    if (soundPath) {
        // Create a file URL with this path
        NSURL *soundURL = [NSURL fileURLWithPath:soundPath];

        NSError *error;
        audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:&error];

        if (audioPlayer == nil)
            NSLog([error description]);
        else
            [audioPlayer play];
    }
    [FlurryAnalytics logEvent:@"GameViewController - playSound"];
}
else{
    [FlurryAnalytics logEvent:@"GameViewController - playSound is still playing"];
}

I can’t figure out why the first audio file started to play while the screen is still on HomeViewController even though it is being called from GameViewController’s viewDidLoad.

If I remove the following code:

while ([audioPlayer isPlaying]) {
    //do nothing and wait so the sound is not overlap
}

The first audio file started to play when GameViewController is loaded but the 2nd audio file overlap.

Thank you very much.

  • 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-25T15:32:28+00:00Added an answer on May 25, 2026 at 3:32 pm

    Does the audio file start to play after you click some button or table view cell in HomeViewController? As in, it starts to play while the GameViewController‘s view is being animated from right to left? If so, then that’s because -viewDidLoad is called before the view is actually presented. What you need to do is instead place your view logic in -viewDidAppear:. That will only be called when the view is finished animating and is completely visible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UIView in a table view section header that I would like
I have a UIView that contains a drawing that I've made using CALayers added
I have created a custom UIView that I would like to use on multiple
I have a UIView and there are 5 subViews on it with index 0,1,2,3,4,5
There are three UIView *view1,view2 , view3; Now, view1 have to be shown at
I have a UIView that has several UIImageViews as subviews. Each of these subviews
There have been a couple of questions that sort of dealt with this but
I have a view with a custom slider. We are using a subclass of
I have a UIView in a UITabController . And there is a UITableView in
I have a UIView that I wish to alter the size and position of

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.