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 Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-02-2009, 11:44 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 140
jbullfrog is on a distinguished road
Default AVAudioPlayer stops responding?

I am using AVAudioPlayer for my background music loop, and for the in-game sound effects. The problem is that after playing the game for a while the background music loop keeps playing as it should which is set up in the AppDelegate, but the in-game sound effects stop which are set up in my ViewController. What I have done is set it up so that when the character gets hit by the enemy it plays one of 5 sound effects, and the same for the character picking up the good items. But for some reason after a while they stop playing and when I try to flip the view to the second view, its like there is too much going on and the app will crash. I'm not getting any errors or warnings, everything seems to work fine and this only happens occasionally, so I'm stumped.

Any thoughts?
jbullfrog is offline   Reply With Quote
Old 11-02-2009, 09:44 PM   #2 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 140
jbullfrog is on a distinguished road
Default Any help?

Has anyone seen this happen before? I don't quite get why it would just quit playing the sounds. Any help would be great.

Thanks
jbullfrog is offline   Reply With Quote
Old 11-02-2009, 10:32 PM   #3 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 140
jbullfrog is on a distinguished road
Default Here is what I have tried.

So this is what I have done.
I'm building to 2.2.1.

AppDelegate.h
Code:
AVAudioPlayer* sound1Player;
ViewController.m
Code:
- (IBAction)playAgain {

NSString *path = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"wav"];
	AVAudioPlayer* sound1Player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil];
	[sound1Player play];
	
}
This works but will stop responding after a while of game play.
Then if I try to flip the view, after the sound stops responding, I get this as the game crashes

terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
Data Formatters unavailable (0x100a25 "dlopen(/Developer/usr/lib/libXcodeDebuggerSupport.dylib, 10): no suitable image found. Did find:\n\t/Developer/usr/lib/libXcodeDebuggerSupport.dylib: open() failed with errno=24\n\t/Developer/usr/lib/lib"...)

Then I tried this, built to 2.2.1, and tried it with 3.1.2.

ViewController.h
Code:
AVAudioPlayer* sound1Player;
}
@property (nonatomic, retain) AVAudioPlayer *sound1Player;
ViewController.m
Code:
@synthesize sound1Player;

- (IBAction)playAgain {

NSString *path = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"wav"];
	sound1Player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil];
sound1Player.delegate = self;
	[sound1Player play];;
	
}
This works but will stop responding after a while of game play.
Then if I try to flip the view, after the sound stops responding, I get this again as the game crashes.

terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
Data Formatters unavailable (0x100a25 "dlopen(/Developer/usr/lib/libXcodeDebuggerSupport.dylib, 10): no suitable image found. Did find:\n\t/Developer/usr/lib/libXcodeDebuggerSupport.dylib: open() failed with errno=24\n\t/Developer/usr/lib/lib"...)
jbullfrog is offline   Reply With Quote
Old 11-02-2009, 10:46 PM   #4 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 140
jbullfrog is on a distinguished road
Default

Ohh, also note that the above code is reffering to a button that plays a sound when the game is over, which also becomes unresposive as do the random hit sounds that I have set up.
jbullfrog is offline   Reply With Quote
Old 11-04-2009, 01:36 PM   #5 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 140
jbullfrog is on a distinguished road
Default

Can anyone help me out?
jbullfrog is offline   Reply With Quote
Old 11-04-2009, 11:13 PM   #6 (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

This is probably a memory problem, not a sound problem. Every time you call playAgain you're creating a new player - and you're never releasing the old one when it's done. If you run your code with the "leaks" instrument you'll probably see the players getting leaked.

You should probably be keeping an array or dictionary of players, and calling [oldPlayer play] on an existing player instead of creating a new one.

In your second example, you forgot the "self." It doesn't use the property unless you use the "self."
Code:
//added "self." so you use the property
self.sound1Player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil];
be sure to
and you should release the player after you put it in the property.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 11-05-2009, 10:16 AM   #7 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 140
jbullfrog is on a distinguished road
Default

Quote:
Originally Posted by smasher View Post
This is probably a memory problem, not a sound problem. Every time you call playAgain you're creating a new player - and you're never releasing the old one when it's done. If you run your code with the "leaks" instrument you'll probably see the players getting leaked.

You should probably be keeping an array or dictionary of players, and calling [oldPlayer play] on an existing player instead of creating a new one.

In your second example, you forgot the "self." It doesn't use the property unless you use the "self."
Code:
//added "self." so you use the property
self.sound1Player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil];
be sure to
and you should release the player after you put it in the property.

Thanks Smasher for the help!

Are you saying that the second version of what I tried is the better way to go?

Also I tried this
Code:
NSString *path = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"wav"];
	self.sound1Player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil];
	[sound1Player release];
	sound1Player.delegate = self;
	[sound1Player play];
	sound1Player.volume = 1;
And it builds fine, just crashes after a bit of playing now with,
"Program received signal: “EXC_BAD_ACCESS” message in console

I also ran "leaks" instrument, and it basically ran the game so slow I couldnt really play it, and after a minute I got this in the Leaks

Leaked Object # Address Size Responsible Library Responsible Frame
NSCFString 2 < multiple > 64 Foundation -[NSPlaceholderString initWithFormat:locale:arguments:]


# Category Event Type Timestamp RefCt Address Size Responsible Library Responsible Caller
0 CFString Malloc 00:42.526 1 0x18b780 32 Foundation -[NSPlaceholderString initWithFormat:locale:arguments:]

Im wondering if the leak is caused when im saving the game, and not the audio stop playing.


When I remove the
Code:
[sound1Player release];
I get this error in console as the game crashes after a few minutes of playing.
Program received signal: “0”.
warning: check_safe_call: could not restore current frame
jbullfrog is offline   Reply With Quote
Old 11-05-2009, 11:13 AM   #8 (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

What you wrote should work and not crash - your crash may be elsewhere now. EXC_BAD_ACCESS usually means you accessed a bad pointer, or tried to use an object that was already destroyed. Signal 0 probaly means you ran out of memory.

I changed it a little to they typical style, but it's functionally equivalent to what you wrote in most cases.

Code:
NSString *path = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"wav"];
	AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil];
	newPlayer.delegate = self;
	newPlayer.volume = 1;
	[newPlayer play];
	self.sound1Player = newPlayer;
	[newPlayer release];
__________________

Free Games!
smasher is offline   Reply With Quote
Old 04-29-2010, 09:04 PM   #9 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 3
neillritchie is on a distinguished road
Default SMASHER is right

Quote:
Originally Posted by smasher View Post
What you wrote should work and not crash - your crash may be elsewhere now. EXC_BAD_ACCESS usually means you accessed a bad pointer, or tried to use an object that was already destroyed. Signal 0 probaly means you ran out of memory.

I changed it a little to they typical style, but it's functionally equivalent to what you wrote in most cases.

Code:
NSString *path = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"wav"];
	AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil];
	newPlayer.delegate = self;
	newPlayer.volume = 1;
	[newPlayer play];
	self.sound1Player = newPlayer;
	[newPlayer release];
SMASHER you are a cracker, thats it, I have been toiling with this trying various solutions, transfer the object to keep it live and then release it for next time the sound is called.

Remember to declare sound1Player in the .h and @sysnthesise in the .m file of course.
neillritchie is offline   Reply With Quote
Reply

Bookmarks

Tags
avaudioplayer, avaudioplayer stops, responding, stops

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
» Online Users: 346
10 members and 336 guests
alexP, ClerurcifeDer, Duncan C, givensur, glenn_sayers, guusleijsten, JmayLive, Punkjumper, whitey99, yys
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,114
Posts: 402,883
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

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