Hello All,
I have been having problems with stopping the AVAudioPlayer from another class of witch it was initiated in. For example, if I go to "class 1" I can start and stop the audio but if I go to "class 2" Nothing will happen. Also I have [audioPlayer stop]; in class 1 viewWillDissapear and that doesnt work either.
...
else if(segmentedControl.selectedSegmentIndex == 2){
//Audio
if(audioIsPlaying){
audioPlayer = FALSE;
[self stopAudio];
//move controls off bool
[segmentedControl removeSegmentAtIndex:2 animated:NO];
[segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"speaker_on.png"] atIndex:2 animated:NO];
stopButton.hidden = YES;
}
else{
//start audio
audioIsPlaying = TRUE;
[self playAudio];
PP2 *pp2 = [[PP2 alloc] init]; //Class 2
pp2.audioIsPlaying = FALSE;
stopButton.hidden = NO;
[segmentedControl removeSegmentAtIndex:2 animated:NO];
}
...
-(IBAction)stopAudioButton:(id)sender{
[self stopAudio];
[segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"speaker_on.png"] atIndex:2 animated:NO];
stopButton.hidden = YES;
}
-(void)playAudio{
//AVAudioSession session = [AVAudioSession sharedInstance];
//session.delegate=self;
//[session setCategory:AVAudioSessionCategorySoloAmbient error:nil];
//[session setActive:YES error: nil];
audioPlayer.numberOfLoops = 0;
audioPlayer.currentTime =0;
volumeBar.hidden = NO;
[audioPlayer setVolume:volumeBar.value];
[self.audioPlayer prepareToPlay];
[self.audioPlayer play];
self.audioPlayer.meteringEnabled = YES;
[audioPlayer updateMeters];
audioPlayer.volume = .5;
//double avgPwrLeft = [audioPlayer averagePowerForChannel:0];
//double avgPwrRight = [audioPlayer averagePowerForChannel:1];
}
-(void)stopAudio{
[audioPlayer stop];
volumeBar.hidden = YES;
}
-(IBAction)setSound:(id)sender{
[audioPlayer setVolume:volumeBar.value];
}
*/
#pragma mark -
#pragma mark viewWillAppear
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[segmentedControl removeAllSegments];
[segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"reload.png"] atIndex:0 animated:YES];
[segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"index.png"] atIndex:1 animated:YES];
[segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"info.png"] atIndex:3 animated:YES];
//these only determine leaving the "doing" the each meathod seperatly
if(slideshowActive == TRUE){
[segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"pause.png"] atIndex:4 animated:YES];
//stop button visible hide start
timer = [NSTimer scheduledTimerWithTimeInterval: 4.0
target: self
selector: @selector(handleTimer:)
userInfo: nil
repeats: NO];
}
else{
[segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"play.png"] atIndex:4 animated:YES];
}
if(audioIsPlaying){
//stop audio visible
[segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"speaker_off.png"] atIndex:2 animated:YES];
volumeBar.hidden = NO;
stopButton.hidden = NO;
}
else {
//start audio visible
[segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"speaker_on.png"] atIndex:2 animated:YES];
volumeBar.hidden = YES;
stopButton.hidden = YES;
}
}
...
Class 2 is very similar in that it registers the BOOL audioIsPlaying as TRUE if the button is tapped and is supposed to stop the audio. NSLog confirms that it is seeing the method and it is TRUE but nothing happens. No matter what I do I cant seem to stop at all. Any help would be very appreciated.
Thanks.