PDA

View Full Version : Controlling music playback when loaded in another class




JavaWizKid
Aug 26, 2009, 06:49 PM
How can I start and stop music in a different nib when the sound file was loaded and starts playing in another nib?

Menu.h Code
#import <AVFoundation/AVFoundation.h>


@interface Menu : UIViewController {

AVAudioPlayer* backgroundMusic;

}

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];
}

The class I want to control it from is options. How do I do this?