ios - Issue with play music -
ios - Issue with play music -
i having problem games background music. when initial view controller loads plays song , loops fine. want create when alter different view controller stops song.
at moment have made ibaction button on main view controller stops music when press if load initial view twice before pressing it, not stop music.
code initial view controller implementation file:
- (void)viewdidload { nsstring *music = [[nsbundle mainbundle] pathforresource:@"beat" oftype:@"wav"]; musicplay=[[avaudioplayer alloc]initwithcontentsofurl:[nsurl fileurlwithpath:music] error:null]; musicplay.delegate=self; musicplay.numberofloops=-1; musicsituation = musicsituation + 1; if(musicsituation == 1) [musicplay play]; }
code ibaction:
- (ibaction)startgame:(id)sender { [musicplay stop]; }
well, need more info such "how navigating controllers?".
and asked in comment: mean "if load initial view twice"?
but way set player fine , leave code , create changes following:
remove [music play];
viewdidload
, instead place in viewdidappear
.
then, add together [music stop];
in viewwilldisappear
.
if mentioned above, think remove musicsituation
well, because assume, check set post-implementation create sure sound goes off want to. above method, wouldn't need anymore.
hope helps.
ios objective-c
Comments
Post a Comment