I'm a newbie, and I'm probably wrong, so I really need your experience and help!
I am creating a music application that uses the AVFoundation Framework. When I test it on my Macbook and iOS Devices, it really works very well in the beginning. But after I press 50-100 times on different sound buttons, at random time it will randomly stop working. The application does not crash, but it just does not play sound. I really could not understand why, please, kindly help me.
Update (07-Jun-2013): Now, Iβll find out what the problem is, but I donβt understand this ... it says this in the debugger: Error shm_open: "AppleAudioQueue.39.189049" (25) flags = 0x2 errno = 24 Please help if possible: o!
Here is my code:
[array1 retain];[array1 retain];[array1 retain];
NSBundle *bundle = [NSBundle mainBundle]; NSString *path = [bundle pathForResource:[NSString stringWithFormat:@"%@", [[Scale objectAtIndex:array1.retainCount]description]] ofType:@"mp3" inDirectory:@"Piano"]; NSURL *url = [NSURL fileURLWithPath: path]; player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; [player setNumberOfLoops:0]; [player play];
The potential cause of this problem is that I use [array retain/release] and using the retainCount array to denote many different objects. Can it cause a memory leak or something like that?
Hi, please, thanks for your help. For your reference, here is part of my stupid code .. I know this is a mess, please let me know if you need an explanation or details:
- (IBAction)P1C:(id)sender{ KeyCountA1 = [NSMutableArray arrayWithObjects:@"1",@"3",@"5",@"8",@"10",@"12",@"15",@"17",@"19",@"22",@"24",@"26",@"29",@"31",@"33",@"36",@"38",@"40",@"43",@"45",@"47",@"50",@"52",nil]; KeyCountA2 = [NSMutableArray arrayWithObjects:@"0",@"2",@"4",@"6",@"9",@"11",@"13",@"16",@"18",@"20",@"23",@"25",@"27",@"30",@"32",@"34",@"37",@"39",@"41",@"44",@"46",@"48",@"51",nil]; KeyCountA3 = [NSMutableArray arrayWithObjects:@"0",@"3",@"5",@"7",@"10",@"12",@"14",@"17",@"19",@"21",@"24",@"26",@"28",@"31",@"33",@"35",@"38",@"40",@"42",@"45",@"47",@"49",@"52",nil]; KeyCountA4 = [NSMutableArray arrayWithObjects:@"1",@"4",@"6",@"8",@"11",@"13",@"15",@"18",@"20",@"22",@"25",@"27",@"29",@"32",@"34",@"36",@"39",@"41",@"43",@"46",@"48",@"50",nil]; KeyCountA5 = [NSMutableArray arrayWithObjects:@"2",@"5",@"7",@"9",@"12",@"14",@"16",@"19",@"21",@"23",@"26",@"28",@"30",@"33",@"35",@"37",@"40",@"42",@"44",@"47",@"49",@"51",nil]; KeyCountA6 = [NSMutableArray arrayWithObjects:@"1",@"3",@"6",@"8",@"10",@"13",@"15",@"17",@"20",@"22",@"24",@"27",@"29",@"31",@"34",@"36",@"38",@"41",@"43",@"45",@"48",@"50",@"52",nil]; KeyCountA7 = [NSMutableArray arrayWithObjects:@"2",@"4",@"7",@"9",@"11",@"14",@"16",@"18",@"21",@"23",@"25",@"28",@"30",@"32",@"35",@"37",@"39",@"42",@"44",@"46",@"49",@"51",nil]; KeyCountC1 = [NSMutableArray arrayWithObjects:@"1",@"8",@"15",@"22",@"29",@"36",@"43",@"50",nil]; KeyCountC2 = [NSMutableArray arrayWithObjects:@"2",@"9",@"16",@"23",@"30",@"37",@"44",@"51",nil]; KeyCountC3 = [NSMutableArray arrayWithObjects:@"3",@"10",@"17",@"24",@"31",@"38",@"45",@"52",nil]; KeyCountC4 = [NSMutableArray arrayWithObjects:@"4",@"11",@"18",@"25",@"32",@"39",@"46",nil]; KeyCountC5 = [NSMutableArray arrayWithObjects:@"5",@"12",@"19",@"26",@"33",@"40",@"47",nil]; KeyCountC6 = [NSMutableArray arrayWithObjects:@"6",@"13",@"20",@"27",@"34",@"41",@"48",nil]; KeyCountC7 = [NSMutableArray arrayWithObjects:@"7",@"14",@"21",@"28",@"35",@"42",@"49",nil];
// missing phase # 3-7
[ChangeScale sendActionsForControlEvents:UIControlEventTouchUpInside]; [label1 setText:[NSString stringWithFormat:@"%d = %@", array1.retainCount, [[KeyName objectAtIndex:array1.retainCount]description]]]; NSBundle *bundle = [NSBundle mainBundle]; NSString *path = [bundle pathForResource:[NSString stringWithFormat:@"%@",[[Scale objectAtIndex:array1.retainCount]description]] ofType:@"mp3" inDirectory:@"Piano"]; NSURL *url = [NSURL fileURLWithPath: path]; player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; [player setNumberOfLoops:0]; [player play]; [EnableButton sendActionsForControlEvents:UIControlEventTouchUpInside]; [CCC sendActionsForControlEvents:UIControlEventTouchUpInside]; [EDCButtons sendActionsForControlEvents:UIControlEventTouchUpInside];
}
*note: "Scale" and "KeyName" are arrays** enabled differently according to ScaleArray.retainCount.