Problem with wav loops that stop working after awhile.
So, my problem is that after turning on and off my sound looping button several times, it eventually stops producing sound. I'm kind of at a dead end with this. So, if theres any new terms that you could sugest I look up or anything that could help me find my way would be greatly appreciated. Thanks again and I'll post my code below.
///MainView.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
@interface MainView : UIView {
IBOutlet UIButton *soundbutton1;
IBOutlet UIButton *soundbutton2;
AVAudioPlayer*sound1;
}
-(IBAction)start;
-(IBAction)stop;
@end
///MainView.m
@implementation MainView
-(IBAction)start{
soundbutton1.hidden = TRUE;
soundbutton2.hidden = FALSE;
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/sound1.wav", [[NSBundle mainBundle] resourcePath]]];
NSError *error;
sound1 = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
sound1.numberOfLoops = -1;
if (sound1 == nil)
NSLog([error description]);
else
[sound1 play];
}
-(IBAction)stop{
soundbutton1.hidden = FALSE;
soundbutton2.hidden = TRUE;
[sound1 stop];
}
@end
|