iphone - Stopping the audio after playing with AVAudioPlayer -
hi guys hope can me issue.
what when user left view b view a, audio plays, when user left view view b, audio stops.
so when user left view b (removing viewb superview) main view view a, methods playit & hahaplay called. when user left view view b (view add subview b) stopplaying method called instead. here's problem, stopplaying method called, audio not stopped. realised alert shown reason statement> [audioplayer stop];
not functioning.
i've defined audio player in header file fyi.
all methods below in viewcontroller
called soundview.
sorry might doing whole thing in wrong way, maybe of can enlighten me , correct mistakes?
-(void)playit{ filepath = [[nsbundle mainbundle] pathforresource:@"6431" oftype:@"aiff"]; fileurl = [[nsurl alloc] initfileurlwithpath:filepath]; audioplayer = [[avaudioplayer alloc] initwithcontentsofurl:fileurl error:nil]; } -(void)hahaplay{ uialertview *alert = [[uialertview alloc] initwithtitle:@"playing" message:@" playing" delegate:nil cancelbuttontitle:@"yep, did." otherbuttontitles:nil]; [alert show]; [alert release]; [audioplayer preparetoplay]; if(![audioplayer isplaying]){ [audioplayer play]; } - (void)stopplaying{ uialertview *alert = [[uialertview alloc] initwithtitle:@"stop playing" message:@"stop playing" delegate:nil cancelbuttontitle:@"yep, did." otherbuttontitles:nil]; [alert show]; [alert release]; [audioplayer stop]; }
maybe you're losing reference somewhere mistake, try setting breakpoint near stop call, , checking audioplayer
in case audioplayer
nil
. saying because reason of these type of problems me...
also following work?
[audioplayer pause] audioplayer.currenttime = 0;
Comments
Post a Comment