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

Adding sound to the Crystal Ball App

I managed to get my crystal ball animation working but thought it would be so much better if the animation had a sound to go with. Managed to download this wav file from the internet but how do l get it to play and stop when my animation start and finish respectively. Any ideas? codes? :)

Unfortunately I have not worked through this problem yet. One suggestion for Forum practices though, please refrain from using full capital titles. ;)

@Jonathan thanks for the advice. It's my first time of doing forums so haven't got no idea what and can't write

5 Answers

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

The Octave sound library is the easiest way for you to add sounds to the crystal ball project. Or you can play your own custom sound: http://stackoverflow.com/questions/9791491/best-way-to-play-simple-sound-effect-in-ios

@Amit thank you very much. What codes and properties would I need to set and syntgesize for the sound to play on my application? Please

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

hackey james The code is there in the links I provided above. Not sure if that's what you are asking.

@Amit sorry I didn't look into the link. Thanks

@Amit, my app is ready, animation done, sound files added, no errors, but sound doesn't play!

@implementation KGViewController { SystemSoundID soundEffect; }

  • (void)viewDidLoad { [super viewDidLoad];

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

My sound doesn't play too! App ready, animation done, sound files added and no errors during runtime. The sound plays on the iPhone simulator on my back but not on my iPhone. Thanks for the help!

@Michele, so i closed my laptop and went to sleep and came this morning and tried again, it worked! Well thats all i know for now!

Anthony Ho
Anthony Ho
10,228 Points

it worked with

AudioServicesPlayAlertSound(soundEffect)