Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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)