Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No Sound Suddenly After Using AVAudioPlayer a lot -- Please Aid ["AppleAudioQueue.39.189049" (25) flags=0x2 errno=24]

I am a newbie and I am probably doing many things wrong, therefore, I really need your expertise and help!

I am creating an music app that uses the AVFoundation Framework. As I test it on my Macbook and iOS Devices, it actually works pretty well in the beginning. But after I press 50-100 times of different audio-playing-buttons, at a random times, it will randomly stop working. The app does not crash, but it just won't play any sound. I really could not figure out why, please kindly assist me.

Update (07-Jun-2013): Here, now i figure out what the problem is, but i dont understand it... it says this in the debugger: shm_open failed: "AppleAudioQueue.39.189049" (25) flags=0x2 errno=24 Please kindly 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];

A potential reason of this problem is because I am using [array retain/release] and using the array retainCount to refer to many different objects. Would this cause a memory leak or something like that?

Hello bbum, thanks for your help. For your reference, here is a part of my stupid code.. i know it is kinda a mess, please let me know if you need my explanation or further 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];

   //(16-May-2013) Refering to SA&CC and use the right scles play different chords for progression (refer to
//(22-May-2013) adding scales (13-120)

    if ((((ScaleArray.retainCount==1)||(ScaleArray.retainCount==2)||(ScaleArray.retainCount==14)||(ScaleArray.retainCount==25)||(ScaleArray.retainCount==26)||(ScaleArray.retainCount==38)||(ScaleArray.retainCount==49)||(ScaleArray.retainCount==50)||(ScaleArray.retainCount==62)||(ScaleArray.retainCount==73)||(ScaleArray.retainCount==74)||(ScaleArray.retainCount==85)||(ScaleArray.retainCount==86)||(ScaleArray.retainCount==98)||(ScaleArray.retainCount==110)||(ScaleArray.retainCount==111))&&(ChordCount.retainCount==1))||
        (((ScaleArray.retainCount==3)||(ScaleArray.retainCount==4)||(ScaleArray.retainCount==15)||(ScaleArray.retainCount==16)||(ScaleArray.retainCount==27)||(ScaleArray.retainCount==28)||(ScaleArray.retainCount==39)||(ScaleArray.retainCount==40)||(ScaleArray.retainCount==51)||(ScaleArray.retainCount==52)||(ScaleArray.retainCount==63)||(ScaleArray.retainCount==64)||(ScaleArray.retainCount==75)||(ScaleArray.retainCount==76)||(ScaleArray.retainCount==87)||(ScaleArray.retainCount==88)||(ScaleArray.retainCount==99)||(ScaleArray.retainCount==100)||(ScaleArray.retainCount==112))&&(ChordCount.retainCount==7))||
        (((ScaleArray.retainCount==5)||(ScaleArray.retainCount==17)||(ScaleArray.retainCount==18)||(ScaleArray.retainCount==29)||(ScaleArray.retainCount==30)||(ScaleArray.retainCount==41)||(ScaleArray.retainCount==42)||(ScaleArray.retainCount==53)||(ScaleArray.retainCount==54)||(ScaleArray.retainCount==65)||(ScaleArray.retainCount==66)||(ScaleArray.retainCount==77)||(ScaleArray.retainCount==89)||(ScaleArray.retainCount==101)||(ScaleArray.retainCount==102)||(ScaleArray.retainCount==113)||(ScaleArray.retainCount==114))&&(ChordCount.retainCount==6))||
        (((ScaleArray.retainCount==6)||(ScaleArray.retainCount==7)||(ScaleArray.retainCount==19)||(ScaleArray.retainCount==31)||(ScaleArray.retainCount==43)||(ScaleArray.retainCount==55)||(ScaleArray.retainCount==67)||(ScaleArray.retainCount==68)||(ScaleArray.retainCount==78)||(ScaleArray.retainCount==79)||(ScaleArray.retainCount==90)||(ScaleArray.retainCount==91)||(ScaleArray.retainCount==103)||(ScaleArray.retainCount==115)||(ScaleArray.retainCount==116))&&(ChordCount.retainCount==5))||
        (((ScaleArray.retainCount==8)||(ScaleArray.retainCount==9)||
          (ScaleArray.retainCount==20)||(ScaleArray.retainCount==21)||(ScaleArray.retainCount==32)||(ScaleArray.retainCount==33)||(ScaleArray.retainCount==44)||(ScaleArray.retainCount==45)||(ScaleArray.retainCount==56)||(ScaleArray.retainCount==57)||(ScaleArray.retainCount==69)||(ScaleArray.retainCount==80)||(ScaleArray.retainCount==81)||(ScaleArray.retainCount==92)||(ScaleArray.retainCount==93)||(ScaleArray.retainCount==104)||(ScaleArray.retainCount==105)||(ScaleArray.retainCount==117))&&(ChordCount.retainCount==4))||
        (((ScaleArray.retainCount==10)||(ScaleArray.retainCount==22)||(ScaleArray.retainCount==34)||(ScaleArray.retainCount==46)||(ScaleArray.retainCount==47)||(ScaleArray.retainCount==58)||(ScaleArray.retainCount==59)||(ScaleArray.retainCount==70)||(ScaleArray.retainCount==71)||(ScaleArray.retainCount==82)||(ScaleArray.retainCount==94)||(ScaleArray.retainCount==95)||(ScaleArray.retainCount==106)||(ScaleArray.retainCount==107)||(ScaleArray.retainCount==118)||(ScaleArray.retainCount==119))&&(ChordCount.retainCount==3))||
        (((ScaleArray.retainCount==11)||(ScaleArray.retainCount==12)||(ScaleArray.retainCount==13)||(ScaleArray.retainCount==23)||(ScaleArray.retainCount==24)||(ScaleArray.retainCount==35)||(ScaleArray.retainCount==36)||(ScaleArray.retainCount==37)||(ScaleArray.retainCount==48)||(ScaleArray.retainCount==60)||(ScaleArray.retainCount==61)||(ScaleArray.retainCount==72)||(ScaleArray.retainCount==83)||(ScaleArray.retainCount==84)||(ScaleArray.retainCount==96)||(ScaleArray.retainCount==97)||(ScaleArray.retainCount==108)||(ScaleArray.retainCount==109)||(ScaleArray.retainCount==120))&&(ChordCount.retainCount==2))) {

    if ([KeyCountA2 containsObject:[NSString stringWithFormat:@"%d",array1.retainCount]])//A2
    {if(array1.retainCount+1>Max){[S1S sendActionsForControlEvents:UIControlEventTouchDown];}else{[array1 retain];}}

    else if ([KeyCountA1 containsObject:[NSString stringWithFormat:@"%d",array1.retainCount]])//A1
    {if(array1.retainCount+2>Max){[S1S sendActionsForControlEvents:UIControlEventTouchDown];}else{[array1 retain];[array1 retain];}}

    else if ([KeyCountC7 containsObject:[NSString stringWithFormat:@"%d",array1.retainCount]])
    {if(array1.retainCount+3>Max){[S1S sendActionsForControlEvents:UIControlEventTouchDown];}else{[array1 retain];[array1 retain];[array1 retain];}}//C7
}//Phase#1

if ((((ScaleArray.retainCount==1)||(ScaleArray.retainCount==2)||(ScaleArray.retainCount==14)||(ScaleArray.retainCount==25)||(ScaleArray.retainCount==26)||(ScaleArray.retainCount==38)||(ScaleArray.retainCount==49)||(ScaleArray.retainCount==50)||(ScaleArray.retainCount==62)||(ScaleArray.retainCount==73)||(ScaleArray.retainCount==74)||(ScaleArray.retainCount==85)||(ScaleArray.retainCount==86)||(ScaleArray.retainCount==98)||(ScaleArray.retainCount==110)||(ScaleArray.retainCount==111))&&(ChordCount.retainCount==2))||
    (((ScaleArray.retainCount==3)||(ScaleArray.retainCount==4)||(ScaleArray.retainCount==15)||(ScaleArray.retainCount==16)||(ScaleArray.retainCount==27)||(ScaleArray.retainCount==28)||(ScaleArray.retainCount==39)||(ScaleArray.retainCount==40)||(ScaleArray.retainCount==51)||(ScaleArray.retainCount==52)||(ScaleArray.retainCount==63)||(ScaleArray.retainCount==64)||(ScaleArray.retainCount==75)||(ScaleArray.retainCount==76)||(ScaleArray.retainCount==87)||(ScaleArray.retainCount==88)||(ScaleArray.retainCount==99)||(ScaleArray.retainCount==100)||(ScaleArray.retainCount==112))&&(ChordCount.retainCount==1))||
    (((ScaleArray.retainCount==5)||(ScaleArray.retainCount==17)||(ScaleArray.retainCount==18)||(ScaleArray.retainCount==29)||(ScaleArray.retainCount==30)||(ScaleArray.retainCount==41)||(ScaleArray.retainCount==42)||(ScaleArray.retainCount==53)||(ScaleArray.retainCount==54)||(ScaleArray.retainCount==65)||(ScaleArray.retainCount==66)||(ScaleArray.retainCount==77)||(ScaleArray.retainCount==89)||(ScaleArray.retainCount==101)||(ScaleArray.retainCount==102)||(ScaleArray.retainCount==113)||(ScaleArray.retainCount==114))&&(ChordCount.retainCount==7))||
    (((ScaleArray.retainCount==6)||(ScaleArray.retainCount==7)||(ScaleArray.retainCount==19)||(ScaleArray.retainCount==31)||(ScaleArray.retainCount==43)||(ScaleArray.retainCount==55)||(ScaleArray.retainCount==67)||(ScaleArray.retainCount==68)||(ScaleArray.retainCount==78)||(ScaleArray.retainCount==79)||(ScaleArray.retainCount==90)||(ScaleArray.retainCount==91)||(ScaleArray.retainCount==103)||(ScaleArray.retainCount==115)||(ScaleArray.retainCount==116))&&(ChordCount.retainCount==6))||
    (((ScaleArray.retainCount==8)||(ScaleArray.retainCount==9)||(ScaleArray.retainCount==20)||(ScaleArray.retainCount==21)||(ScaleArray.retainCount==32)||(ScaleArray.retainCount==33)||(ScaleArray.retainCount==44)||(ScaleArray.retainCount==45)||(ScaleArray.retainCount==56)||(ScaleArray.retainCount==57)||(ScaleArray.retainCount==69)||(ScaleArray.retainCount==80)||(ScaleArray.retainCount==81)||(ScaleArray.retainCount==92)||(ScaleArray.retainCount==93)||(ScaleArray.retainCount==104)||(ScaleArray.retainCount==105)||(ScaleArray.retainCount==117))&&(ChordCount.retainCount==5))||
    (((ScaleArray.retainCount==10)||(ScaleArray.retainCount==22)||(ScaleArray.retainCount==34)||(ScaleArray.retainCount==46)||(ScaleArray.retainCount==47)||(ScaleArray.retainCount==58)||(ScaleArray.retainCount==59)||(ScaleArray.retainCount==70)||(ScaleArray.retainCount==71)||(ScaleArray.retainCount==82)||(ScaleArray.retainCount==94)||(ScaleArray.retainCount==95)||(ScaleArray.retainCount==106)||(ScaleArray.retainCount==107)||(ScaleArray.retainCount==118)||(ScaleArray.retainCount==119))&&(ChordCount.retainCount==4))||
    (((ScaleArray.retainCount==11)||(ScaleArray.retainCount==12)||(ScaleArray.retainCount==13)||(ScaleArray.retainCount==23)||(ScaleArray.retainCount==24)||(ScaleArray.retainCount==35)||(ScaleArray.retainCount==36)||(ScaleArray.retainCount==37)||(ScaleArray.retainCount==48)||(ScaleArray.retainCount==60)||(ScaleArray.retainCount==61)||(ScaleArray.retainCount==72)||(ScaleArray.retainCount==83)||(ScaleArray.retainCount==84)||(ScaleArray.retainCount==96)||(ScaleArray.retainCount==97)||(ScaleArray.retainCount==108)||(ScaleArray.retainCount==109)||(ScaleArray.retainCount==120))&&(ChordCount.retainCount==3))) {

    if ([KeyCountA3 containsObject:[NSString stringWithFormat:@"%d",array1.retainCount]])
    {if(array1.retainCount+1>Max){[S1S sendActionsForControlEvents:UIControlEventTouchDown];}else{[array1 retain];}}

    else if ([KeyCountA2 containsObject:[NSString stringWithFormat:@"%d",array1.retainCount]])//A1
    {if(array1.retainCount+2>Max){[S1S sendActionsForControlEvents:UIControlEventTouchDown];}else{[array1 retain];[array1 retain];}}

    else if ([KeyCountC1 containsObject:[NSString stringWithFormat:@"%d",array1.retainCount]])
    {if(array1.retainCount+3>Max){[S1S sendActionsForControlEvents:UIControlEventTouchDown];}else{[array1 retain];[array1 retain];[array1 retain];}}//C7
}//Phase#2

//skipped 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.
like image 334
002boy Avatar asked Dec 11 '22 14:12

002boy


1 Answers

There isn't enough code there to say what might be happening other than to say that you really need to revisit the basics of memory management.

Three retains in a row? Doesn't make sense and is indicative of guessing about what is going on.

retainCount is useless; don't call it. http://www.whentouseretaincount.com/

Have you tried running the static analyzer on your code?


From your comment I can tell I am really doing everything wrong. In my code, I am using different retainCount number to represent different keys on the piano keyboard... Because I don't know how to use a int or a integer value that run across all my IBAction

My apologies -- that wasn't meant to be harsh!

We all did everything wrong at one time. The use of retainCount to store UI state is actually one of the most creative abuses of that API I've seen! So, no, you definitely aren't stupid, just deep along the wrong path!

It sounds like you need to take a step back and have a look at how an application is put together. In this case, you have N individual buttons, each of which triggers a nearly identical action. So, you need to attach some data to those buttons.

If the buttons are created in Interface Builder, you could assign a tag to each. If they are created programmatically, you could do the same. Both NSButton and UIButton have tags, so you could use the same solution on both platforms.

Without knowing more about how the buttons are implemented, it is hard to be more specific.

like image 171
bbum Avatar answered Dec 28 '22 23:12

bbum