Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Simple iPhone App (iOS7) Animating and Intercepting Events Adding Sound

Hi, I got the video tutorial and not sound in the app

Hi, I got the video tutorial and not sound in the app, what is the problem?, please i need help for this question. thank you

12 Answers

And make sure it's the AudioToolBox.framework and not the AudioUnit.framework, which I am sure you did or it would have error'ed out. Also you can set a breakpoint before and after the

''' AudioServicesPlaySystemSound(soundEffect); '''

and see if it errors in the console

Zachary Canter
Zachary Canter
20,530 Points

Good to know it's Xcode6 beta problem. Been trying to figure it out also.

Hi, right now I'm tested the sample app that downloading from the lesson, this file is made for Mr. Amit and the result is the same not get sound, but I tried in the older Xcode 5 and this file it's OK!!, I really thought the xcode beta would go well but it's only a BETA x), otherwise thank you very much for response my questions!!

どもありがとうございました!!

remember to set the code

    NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"crystal_ball" ofType:@"mp3"];
    NSURL *soundURL = [NSURL fileURLWithPath:soundPath];
    AudioServicesCreateSystemSoundID(CFBridgingRetain(soundURL), &soundEffect);


    self.crystalball = [[THCrystalBall alloc]init];
    self.backgroundImageView.animationImages = [[NSArray alloc]initWithObjects:
                                                [UIImage imageNamed:@"CB00001"],
                                                [UIImage imageNamed:@"CB00002"],
                                                [UIImage imageNamed:@"CB00003"],
                                                [UIImage imageNamed:@"CB00004"],
                                                [UIImage imageNamed:@"CB00005"],
                                                [UIImage imageNamed:@"CB00006"],
                                                [UIImage imageNamed:@"CB00007"],
                                                [UIImage imageNamed:@"CB00008"],
                                                [UIImage imageNamed:@"CB00009"],
                                                [UIImage imageNamed:@"CB00010"],
                                                [UIImage imageNamed:@"CB00011"],
                                                [UIImage imageNamed:@"CB00012"],
                                                [UIImage imageNamed:@"CB00013"],
                                                [UIImage imageNamed:@"CB00014"],
                                                [UIImage imageNamed:@"CB00015"],
                                                [UIImage imageNamed:@"CB00016"],
                                                [UIImage imageNamed:@"CB00017"],
                                                [UIImage imageNamed:@"CB00018"],
                                                [UIImage imageNamed:@"CB00019"],
                                                [UIImage imageNamed:@"CB00021"],
                                                [UIImage imageNamed:@"CB00022"],
                                                [UIImage imageNamed:@"CB00023"],
                                                [UIImage imageNamed:@"CB00024"],
                                                [UIImage imageNamed:@"CB00025"],
                                                [UIImage imageNamed:@"CB00026"],
                                                [UIImage imageNamed:@"CB00027"],
                                                [UIImage imageNamed:@"CB00028"],
                                                [UIImage imageNamed:@"CB00029"],
                                                [UIImage imageNamed:@"CB00030"],
                                                [UIImage imageNamed:@"CB00031"],
                                                [UIImage imageNamed:@"CB00032"],
                                                [UIImage imageNamed:@"CB00033"],
                                                [UIImage imageNamed:@"CB00034"],
                                                [UIImage imageNamed:@"CB00035"],
                                                [UIImage imageNamed:@"CB00036"],
                                                [UIImage imageNamed:@"CB00037"],
                                                [UIImage imageNamed:@"CB00038"],
                                                [UIImage imageNamed:@"CB00039"],
                                                [UIImage imageNamed:@"CB00040"],
                                                [UIImage imageNamed:@"CB00041"],
                                                [UIImage imageNamed:@"CB00042"],
                                                [UIImage imageNamed:@"CB00043"],
                                                [UIImage imageNamed:@"CB00044"],
                                                [UIImage imageNamed:@"CB00045"],
                                                [UIImage imageNamed:@"CB00046"],
                                                [UIImage imageNamed:@"CB00047"],
                                                [UIImage imageNamed:@"CB00048"],
                                                [UIImage imageNamed:@"CB00049"],
                                                [UIImage imageNamed:@"CB00050"],
                                                [UIImage imageNamed:@"CB00051"],
                                                [UIImage imageNamed:@"CB00052"],
                                                [UIImage imageNamed:@"CB00053"],
                                                [UIImage imageNamed:@"CB00054"],
                                                [UIImage imageNamed:@"CB00055"],
                                                [UIImage imageNamed:@"CB00056"],
                                                [UIImage imageNamed:@"CB00057"],
                                                [UIImage imageNamed:@"CB00058"],
                                                [UIImage imageNamed:@"CB00059"],
                                                [UIImage imageNamed:@"CB00060"],nil];

    self.backgroundImageView.animationDuration = 2.5f;
    self.backgroundImageView.animationRepeatCount = 1;


 // ...   

#pragma mark - Prediction

- (void) makePrediction {

    [self.backgroundImageView startAnimating];
    self.predictionLabel.text = [self.crystalball randomPrediction];
    AudioServicesPlaySystemSound(soundEffect);

    [UIView animateWithDuration:4.0 animations:^{
        self.predictionLabel.alpha = 1.0f;
    }];



}

If you get sound in the simulator but not on the phone itself, make sure your phone is not set on vibrate.. I had the same issue and looked for issues but it was just my phone was on silent.

Thanks for responding!! I not get the sound in the simulator... any idea?

Code looks ok I think from a quick glance over, you've made sure the mp3 is in the left hand folder view as well?

I continued with all steps in the video 5 times but not found the problem, thank you for response!

right now I'm using xcode bets 6 and note that he had added the Framework folder, I included it by hand, along with sound framework and the other by default, maybe is a bug in xcode, I don't know...

My simulators do not have sound in Xcode as well, but sound works on the phone. I have tried the system sound settings and that didn't work for me.

Xcode version is beta?

Hi guys, I figured out a workaround for the sound effect. I am also using Xcode 6 beta:

1: add the AVFoundation.framework (same way that we added the AudioToolbox Framework in the video).

2: Import the AVFoundation/AVFoundation.h header, by adding it to the top of the ViewController.m file

3: Create an instance variable in the view controller to hold an AVAudioPlayer object. I called mine _soundFX

@interface ViewController() {
AVAudioPlayer *_soundFX;
}

4: We've already constructed the URL to the sound file. Comment out or delete the AudioServicesCreateSystemSoundID(CFBridgingRetain(soundURL), &soundEffect); line. Below it, add:

 _soundFX = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:nil];

5: Then, in the makePrediction method that we added in a previous video, you can simply call the play method on _soundFX

 [_soundFX play];

Hope this helps!

Best, Ogechi

P.S. Is there any way to ask Amit whether there's any kind of backend performance issue when using the AVFoundation rather than the AudioToolKit framework to implement this task?

Dan Paschevici
Dan Paschevici
4,013 Points

And I tried this way and work but when I'm debugging and add an Exception Breakpoint it gives me an error when I'm trying in simulator. Why?????