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 05-12-2009, 08:24 AM   #1 (permalink)
Registered Member
 
Twimfy's Avatar
 
Join Date: Mar 2009
Location: UK
Posts: 36
Twimfy is on a distinguished road
Send a message via MSN to Twimfy Send a message via Skype™ to Twimfy
Default Multiple sounds, black screen after adding 3 sounds

Hi,

I followed the short sounds tutorial and then modified it to use buttons and multiple sounds.

All of my sounds are in wav format and less than 5 seconds.

I add the first sound, test it press the button, it works great.

Then I repeat the process for the second and third sound, great they work too.

However when I go to add a fourth sound, the app compiles and shows no errors but the screen just stays back and then after about two minutes the app closes with no errors.

I can only guess that it might be some kind of memory leak but I don't really know.

Could someone help me please?

Here is my code:

Main.h
Code:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@class SoundEffect;

@interface MainView : UIView {
	SoundEffect *soundEffect;
	SoundEffect *soundEffect2;
	SoundEffect *soundEffect3;
	SoundEffect *soundEffect4;
}
- (IBAction)sound1;
- (IBAction)sound2;
- (IBAction)sound3;
- (IBAction)sound4;
@end
Main.m
Code:
#import "MainView.h"
#import "SoundEffect.h"

@implementation MainView

-(void)awakeFromNib {
	NSBundle *mainBundle = [NSBundle mainBundle];
	soundEffect = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"absobloody" ofType:@"wav"]];
	soundEffect2 = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"fire" ofType:@"wav"]];
	soundEffect3 = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"butter" ofType:@"wav"]];
	soundEffect4 = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Cashback" ofType:@"wav"]];
	}	

- (IBAction)sound1 {
    [soundEffect play];
}

- (IBAction)sound2 {
    [soundEffect2 play];
}

- (IBAction)sound3 {
	[soundEffect3 play];
}

- (IBAction)sound4 {
	[soundEffect4 play];
}

@end
SoundEffect.m
Code:
//
//  SoundEffect.m
//  sound
//
//  Created by Tim Hugall on 11/05/2009.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "SoundEffect.h"


@implementation SoundEffect

- (id)initWithContentsOfFile:(NSString *)path
{
	self = [super init];
	if (self != nil) {
		NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
		AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
	}
	return self;
}

-(void)play {
	AudioServicesPlaySystemSound(soundID);
}


@end
SoundEffect.h
Code:
//
//  SoundEffect.h
//  sound
//
//  Created by Tim Hugall on 11/05/2009.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

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


@interface SoundEffect : NSObject {
	SystemSoundID soundID;


}

- (id)initWithContentsOfFile:(NSString *)path;
-(void)play;

@end
soundAppDelegate.h
Code:
//
//  soundAppDelegate.h
//  sound


#import <UIKit/UIKit.h>

@class soundViewController;

@interface soundAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    soundViewController *viewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet soundViewController *viewController;

@end
soundAppDelegate.m
Code:
//
//  soundAppDelegate.m
//  sound


#import "soundAppDelegate.h"
#import "soundViewController.h"

@implementation soundAppDelegate

@synthesize window;
@synthesize viewController;


- (void)applicationDidFinishLaunching:(UIApplication *)application {    
    
    // Override point for customization after app launch    
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
}


- (void)dealloc {
    [viewController release];
    [window release];
    [super dealloc];
}


@end
soundViewController.h
Code:
//
//  soundViewController.h
//  sound

#import <UIKit/UIKit.h>

@interface soundViewController : UIViewController {

}

@end
soundViewController.m
Code:
#import "soundViewController.h"

@implementation soundViewController



/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}


- (void)dealloc {
    [super dealloc];
}

@end
Please help. I am trying to make this app as a birthday present but it's not going well.

Last edited by Twimfy; 05-12-2009 at 08:46 AM.
Twimfy is offline   Reply With Quote
Old 05-12-2009, 11:45 AM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Put a breakpoint or NSLog inside initWithContentsOfFile and see if the path is nil for sound 4.

I'm betting that pathForResource is returning nil, either becuase sound4 is not in the target (not being copied to the bundle by xcode) or the filename does not match (Cashback vs cashback).
__________________

Free Games!
smasher is offline   Reply With Quote
Old 05-12-2009, 11:58 AM   #3 (permalink)
Registered Member
 
Twimfy's Avatar
 
Join Date: Mar 2009
Location: UK
Posts: 36
Twimfy is on a distinguished road
Send a message via MSN to Twimfy Send a message via Skype™ to Twimfy
Default

Quote:
Originally Posted by smasher View Post
Put a breakpoint or NSLog inside initWithContentsOfFile and see if the path is nil for sound 4.

I'm betting that pathForResource is returning nil, either becuase sound4 is not in the target (not being copied to the bundle by xcode) or the filename does not match (Cashback vs cashback).
I've been playing around with it and it seems it's certain wav/mp3 files that don't work.

I have no idea why, their files sizes/encoding are all of the same type and they're never any longer than 5 seconds long to break the system sound kit.

The names are spot on in all cases and I've reloaded and rebuilt over and over to make sure they're being pulled into the bundle.

Very mysterious.
Twimfy is offline   Reply With Quote
Old 08-30-2009, 09:59 PM   #4 (permalink)
Registered Apple Noob
 
Join Date: Aug 2009
Location: Canada
Posts: 2
ag82 is on a distinguished road
Default Could it be the sound file itself?

I was coding something similar to what you are doing and 2 buttons played the sound I wanted and 2 diudn't. After researching and burning a lot of cycles with no answer in site, I tried pointing the two other buttons to the sound files that were working, and surprise, surprise, it stared working. I chose other sound files and my code worked like a charm.

I used AVAudioPlayer instead of the framework you used.

Hope this helps.

PS, I used Wav files and iphones might be picky with those.
ag82 is offline   Reply With Quote
Old 08-30-2009, 11:26 PM   #5 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

FYI, System sound does not play mp3 files on the device, and doesn't play files over 4.9 seconds on the simulator. AVAudioPlayer doesn't have either problem, plus it obeys the sounds session.
__________________

Free Games!
smasher 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:51 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0