Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sheepsblood

macrumors newbie
Original poster
Aug 26, 2012
1
0
:confused:

Hi I am a NooB to Objective C and App building. I am familiar with .net, HTML, and Java. Video upon video has me being left stumped. I either receive -[NSURL initFileURLWithPath:]: nil string parameter, or now with this new line of script I get no sound.

My APP has a UIButton which is supposed to make a sound when pressed.
I changed the button to custom so it has a picture of SpongeBob and the Title is named "spongelaugh".

my soundfile I have is named "laugh.wav" I also have a "laugh.mp3" if that helps resolve this issue.

My APP compiles with no errors or warnings. Though when I click on the UIButton, no sound is heard.

Thank you for reviewing my code and criticism is always welcome!


////////////////////////////////////////////////////////////////////////////////////////
.h file
////////////////////////////////////////////////////////////////////////////////////////
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>

@interface learnsoundViewController : UIViewController
@property (nonatomic, retain) AVAudioPlayer *player;
- (IBAction)spongelaugh:(id)sender;

@end


////////////////////////////////////////////////////////////////////////////////////////
.m file
////////////////////////////////////////////////////////////////////////////////////////

#import "learnsoundViewController.h"

@interface learnsoundViewController ()

@end

@implementation learnsoundViewController


- (IBAction)spongelaugh:(id)sender {
CFURLRef soundFileURLRef;


// Get the main bundle for the app
CFBundleRef mainBundle = CFBundleGetMainBundle ();

// Get the URL to the sound file to play.
soundFileURLRef = CFBundleCopyResourceURL (mainBundle, CFSTR ("laugh"),CFSTR ("wav"),NULL);

UInt32 soundID;
AudioServicesCreateSystemSoundID (soundFileURLRef, &soundID);
AudioServicesPlaySystemSound (soundID);


All my files are stored locally in the project so I don't get why it won't play the actual sound. Yes, my volume is up on my laptop.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.