Hi,
I have a view based application in which the viewDidLoad method of my initial view controller (FirstViewController) is being called while the other view is being shown. The reason this is an issue is because I am playing music in the viewDidLoad of my first view and it reloads randomly as I'm in my second view (GameViewController).
I've tried playing the sound on launch from the app delegate but I want to be able to control the AVAudioPlayer variable from my FirstViewController.h since it is playing the first track of a playlist.
Any thoughts?
Thanks,
Nick
Edit: I put the code in - (void) awakeFromNib { } and that did the trick
I have a view based application in which the viewDidLoad method of my initial view controller (FirstViewController) is being called while the other view is being shown. The reason this is an issue is because I am playing music in the viewDidLoad of my first view and it reloads randomly as I'm in my second view (GameViewController).
Code:
// in my FirstViewController.m
-(IBAction) press1{
[theAudio stop];
GameViewController *views = [[GameViewController alloc] initWithNibName:Nil bundle:nil];
[self presentModalViewController:views animated:YES];
}
- (void)viewDidLoad {
NSString *path = [[NSBundle mainBundle] pathForResource:@"Song1" ofType:@"wav"];
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];
}
I've tried playing the sound on launch from the app delegate but I want to be able to control the AVAudioPlayer variable from my FirstViewController.h since it is playing the first track of a playlist.
Any thoughts?
Thanks,
Nick
Edit: I put the code in - (void) awakeFromNib { } and that did the trick
Last edited: