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 trialJustin Black
24,793 Points[ Solution ] Xcode 6.1 no sound in simulator
I did this video yesterday, the sound didn't work and I just couldn't move on. After being frustrated for hours, playing with my system settings, and looking at the code I turned to my good friend google.
These videos are for iOS 7, but if you are new ( like me ), you are using xcode for iOS 8 and there are subtle nuances between the two versions.
The reason your code does NOT work, is because the AudioToolbox
framework does NOT support mp3 files. It only supports CAF, AIF, or WAV
Instead, if we use the AVFoundation
framework, it supports the use of AAC or MP3
My code here is not pretty, and it can be fixed to be prettier. Once you add the AVFoundation framework to your project. Open your THViewController and add the lines: ( i've shortened the code to JUST the necessary items )
#import "THViewcontroller.h"
#import "THCrystalBall.h"
@import AVFoundation;
@interface THViewController () <AVAudioPlayerDelegate>
@property (strong, nonatomic) AVAudioPlayer *backgroundMusicPlayer;
@implementation THViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSString *backgroundMusicPath = [[NSBundle mainBundle] pathForResource:@"crystal_ball" ofType:@"mp3"];
NSURL *backgroundMusicURL = [NSURL fileURLWithPath:backgroundMusicPath];
self.backgroundMusicPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:backgroundMusicURL error:nil];
self.backgroundMusicPlayer.delegate = self; // We need this so we can restart after interruptions
self.backgroundMusicPlayer.numberOfLoops = 0;
}
-(void) makePrediction {
// ... your other code here
[self.backgroundMusicPlayer play];
// ... the rest of your code here..
}
@end
I only added this, in an effort to help stop the confusion as to why the audio file in this video does not play. There are more options you can use for this method, this is just a simple basic example.
Yury Aykin
18,115 PointsThanks, Justin!)
1 Answer
Deep Ashok
1,717 PointsThank you!
Brandon Johnson
5,245 PointsBrandon Johnson
5,245 PointsHey Justin, Thank you for posting a solution to this issue. I was just working through the videos myself and ran into this issue. Your posting of the solution saved me a lot of time, Thanks!