Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Tutorials > Tutorial Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 02-10-2009, 11:41 AM   #1 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 19
insomniak is on a distinguished road
Default Sound with pic tutorial by Nitrex88 question

Hello All,

Just so you know...i've never programmed.

I've been tinkering around with Nitrex88's cat sound tutorial and i've learned alot but i can't seem to get it working.

i don't get any error's or warnings but here are my debugger results

2009-02-10 11:30:00.234 meow[10110:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:isDirectory:]: nil string parameter'

MainView.h

Code:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

@class SoundEffect;

@interface MainView : UIView {
    IBOutlet UIImageView *catImage;
	SoundEffect *soundEffect;
}

@end
MainView.m

Code:
#import "MainView.h"
#import "SoundEffect.h"

@implementation MainView

-(void)awakeFromNib {
	NSBundle *mainBundle = [NSBundle mainBundle];
	soundEffect = [[SoundEffect alloc] initWithContentsOfFile: [mainBundle pathForResource:@"cat" ofType:@"wav"]];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	[soundEffect play];	
}

	
@end
SoundEffect.h

Code:
#import "MainView.h"
#import "SoundEffect.h"

@implementation MainView

-(void)awakeFromNib {
	NSBundle *mainBundle = [NSBundle mainBundle];
	soundEffect = [[SoundEffect alloc] initWithContentsOfFile: [mainBundle pathForResource:@"cat" ofType:@"wav"]];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	[soundEffect play];	
}

	
@end
SoundEffect.m

Code:
#import "SoundEffect.h";


@implementation SoundEffect

// Creates a sound effect object from the specified sound file
+ (id)soundEffectWithContentsOfFile:(NSString *)aPath {
    if (aPath) {
        return [[[SoundEffect alloc] initWithContentsOfFile:aPath] autorelease];
    }
    return nil;
}

// Initializes a sound effect object with the contents of the specified sound file
- (id)initWithContentsOfFile:(NSString *)path {
    self = [super init];
    
	// Gets the file located at the specified path.
    if (self != nil) {
        NSURL *aFileURL = [NSURL fileURLWithPath:path isDirectory:NO];
        
		// If the file exists, calls Core Audio to create a system sound ID.
        if (aFileURL != nil)  {
            SystemSoundID aSoundID;
            OSStatus error = AudioServicesCreateSystemSoundID((CFURLRef)aFileURL, &aSoundID);
            
            if (error == kAudioServicesNoError) { // success
                _soundID = aSoundID;
            } else {
                NSLog(@"Error %d loading sound at path: %@", error, path);
                [self release], self = nil;
            }
        } else {
            NSLog(@"NSURL is nil for path: %@", path);
            [self release], self = nil;
        }
    }
    return self;
}

// Releases resouces when no longer needed.
-(void)dealloc {
    AudioServicesDisposeSystemSoundID(_soundID);
    [super dealloc];
}

// Plays the sound associated with a sound effect object.
-(void)play {
	// Calls Core Audio to play the sound for the specified sound ID.
    AudioServicesPlaySystemSound(_soundID);
}

@end
any help would be appreciated.

Thanks in advance!
insomniak is offline   Reply With Quote
Old 02-10-2009, 11:48 AM   #2 (permalink)
1026 Development
 
Join Date: Jul 2008
Age: 23
Posts: 1,094
Jeremy1026 is on a distinguished road
Send a message via AIM to Jeremy1026
Default

Do you have a file called "cat.wav" (case sensitive) in your project bundle?
Jeremy1026 is offline   Reply With Quote
Old 02-10-2009, 12:40 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 19
insomniak is on a distinguished road
Default

Quote:
Originally Posted by Jeremy1026 View Post
Do you have a file called "cat.wav" (case sensitive) in your project bundle?
Thanks Jeremy! the first time around i the file was cat.wav and this time i forgot i named it catmeow.wav.

it's so much to learn, i feel like i'm learning a foreign language.

What do i do if i want to add multiple sounds with a tableview?

like a list of items and upon clicking the sound plays.
insomniak is offline   Reply With Quote
Old 02-10-2009, 12:48 PM   #4 (permalink)
1026 Development
 
Join Date: Jul 2008
Age: 23
Posts: 1,094
Jeremy1026 is on a distinguished road
Send a message via AIM to Jeremy1026
Default

In your initialization code
Code:
soundEffect2 = [[SoundEffect alloc] initWithContentsOfFile: [mainBundle pathForResource:@"secondsound" ofType:@"wav"]];
in your header
Code:
SoundEffect *soundEffect2;
to play the sound

Code:
[soundEffect2 play];
Obviously, keep adding for how ever many sounds you need. As for the table view, check out myers' tutorial on them on this site. They are very good and will get you started.
Jeremy1026 is offline   Reply With Quote
Old 02-10-2009, 01:19 PM   #5 (permalink)
Registered Member
 
Join Date: Dec 2008
Posts: 429
lbendlin is on a distinguished road
Default

What's the cost of a sound effect? how many can you add before the app crashes? on the other hand, is there a measurable performance impact when you destroy and recreate the same object for reuse?
lbendlin is offline   Reply With Quote
Old 02-10-2009, 01:56 PM   #6 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 19
insomniak is on a distinguished road
Default

Quote:
Originally Posted by Jeremy1026 View Post
Obviously, keep adding for how ever many sounds you need. As for the table view, check out myers' tutorial on them on this site. They are very good and will get you started.
Will do sir! thanks again
insomniak is offline   Reply With Quote
Old 02-24-2009, 08:22 AM   #7 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 2
jxmccall is on a distinguished road
Default

I have been looking for this tutorial.. I cannot seem to find it. Any help would be appreciated.
jxmccall is offline   Reply With Quote
Old 06-24-2009, 10:02 PM   #8 (permalink)
Junior Bacon Cheeseburger
 
Join Date: Mar 2009
Location: maryland
Age: 28
Posts: 48
yujean is on a distinguished road
Send a message via AIM to yujean Send a message via MSN to yujean Send a message via Skype™ to yujean
Default

I followed the tutorial and created SoundEffect.h and SoundEffect.m

is it me or can nobody else play sound files that are >10 seconds?



Shorter sounds all work fine... I can't implement music or long soundeffects, for some reason. Is there a fix?
yujean is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 175,696
Threads: 94,138
Posts: 402,957
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jasper_muc
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:50 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0