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 09-05-2011, 11:48 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 2
KoryF is on a distinguished road
Default Repeat sound after delay

Hello. I have a problem with a music application I am working on enhancing by giving it the ability to adjust the timing of sounds which are repeated when a loop BOOL is true. I have implemented an NSTimer, which it is recognizing, but I am having trouble with the selector. After the given time, it just crashes instead of replaying the sound. My code looks something like this:


Code:
-(IBAction) playSound: (id) sender
{

	NSString *pathsoundFile;
	float nVolume;
	
	switch ([sender tag])
	{
		case 1:
			pathsoundFile = [[NSBundle mainBundle] pathForResource:@"soundA" ofType:@"wav"];
			break;
			
		case 2:
			pathsoundFile = [[NSBundle mainBundle] pathForResource:@"soundB" ofType:@"wav"];
			break;
if (bDoRecord)	
	{	
		//only allow up to 64 background sounds
		
		if([loopedSounds count]<=64)
		{
			
			[loopedSounds addObject:[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:pathsoundFile] error:NULL]];
			((AVAudioPlayer *)loopedSounds.lastObject).delegate=self;						
			((AVAudioPlayer *)loopedSounds.lastObject).volume = nVolume;
			((AVAudioPlayer *)loopedSounds.lastObject).numberOfLoops = 0;
			[((AVAudioPlayer *)loopedSounds.lastObject) prepareToPlay];
			pauseTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(playSound:) userInfo:nil repeats:YES];
			[((AVAudioPlayer *)loopedSounds.lastObject) play];
	
		}
		
	}
	else
	{
		sound = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:pathsoundFile] error:NULL];
		sound.delegate = self;
		sound.volume =nVolume;
		[sound play];
		
	}
	
	NSError *setCategoryError = nil;
	[[AVAudioSession sharedInstance]
	 setCategory: AVAudioSessionCategoryPlayback
	 error: &setCategoryError];
	
	if (setCategoryError) 
	{
		nil;
	}

}
I originally had the sound loop indefinitely and the .wav file is 6 seconds long. Thus, a six second loop. .. always... [yawn].
The problem is that I am not really a programmer. What am I missing? The app in its current state is called freesong and if you look at it you will notice the need to control the loop length! Help!
KoryF is offline   Reply With Quote
Old 09-06-2011, 09:54 AM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

First of all, you have some memory management issues, which make me want to cry. You should check out some articles on iOS memory management and perhaps properties.

Regarding your app crash, can you give more details about the crash. Specifically the error message that is printed in the debug console when the crash occurs.
smithdale87 is offline   Reply With Quote
Reply

Bookmarks

Tags
loop timing, looping, sound delay, timer

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: 377
7 members and 370 guests
apatsufas, JackReidy, jeroenkeij, Sami Gh, tim0504, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,671
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, JackReidy
Powered by vBadvanced CMPS v3.1.0

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