How can I stop this music playing from another class file?
eg:
The music starts playing in the menu.h/.m
menu.h
---------
Code:
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface Menu : UIViewController {
AVAudioPlayer* backgroundMusic;
}
@end
menu.m
---------
Code:
- (void)viewDidLoad {
NSString *pathToMusicFile = [[NSBundle mainBundle] pathForResource:@"background" ofType:@"mp3"];
backgroundMusic = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:pathToMusicFile] error:NULL];
backgroundMusic.numberOfLoops = -1;
backgroundMusic.volume = 0.2;
[backgroundMusic play];
[super viewDidLoad];
}
Now that the song is playing, how can I stop it from this class?
options.h
-----------
Code:
@interface Options : UIViewController {
IBOutlet UISwitch *musicSwitch;
IBOutlet UISwitch *soundSwitch;
}
@property (nonatomic, retain) UISwitch *musicSwitch;
@property (nonatomic, retain) UISwitch *soundSwitch;
options.m
-----------
Code:
@synthesize musicSwitch;
@synthesize soundSwitch;
-(IBAction)musicSwitchChange:(id)sender
{
if(musicSwitch.on)
{
}
else
{
}
}
-(IBAction)soundSwitchChange:(id)sender
{
if(soundSwitch.on)
{
}
else
{
}
}
Thanks