Page 1 of 1 [ 2 posts ] 

Madbones
Veteran
Veteran

User avatar

Joined: 7 Mar 2010
Age: 29
Gender: Male
Posts: 777
Location: In the zone

20 Mar 2012, 5:46 pm

Hey!
It would mean one hell of allot if someone could help me out with this issue I have with my iOS app.
This is how it works. Its a simple game. When the app first launches, it launches into the ProjectNamesViewController.m and then the viewDidLoad method gets called.
In the viewDidLoad method, I call my configuration method which is a sender.
This is how my configuration method works:
-(void) configure:(id) sender{
NSString * pathToMusic = [[NSBundle mainBundle] pathForResource:@"MusicFile" ofType:@"m4a"];
backgroundMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:pathToMusic] error:NULL];
backgroundMusic.delegate = self;
backgroundMusic.numberOfLoops = -1; // (So this keeps playing and not stopping even though it as at the end of the track.)
}

Then in my viewDidLoad method, the playMusic method gets called:
-(void) playMusic{
[backgroundMusic play];
}
I have multiple views in my app. One is settings, about and new game.
I want the music that is currently playing on the starting view to keep playing when I go onto settings and about. When I press new game I want it to stop the track that is playing on the starting view and then play the music on the new game view. I have no problem with this bit.
Here is the problem:
I start the app. Music plays, great. I press new game, where new game uses the same method of playing music as the main view does. It stops the main views music and plays its own. I can go back to the main menu and it stops its current playing music, and starts main views music.
This is where my problem comes in:
If I go onto another view before going onto New Game, I cannot stop the music playing on the main view.
Help?
I know this isnt a good sign of me being a good programmer. Im crap at it if I am honest. But I am not going to let that stop me. Il keep learning. I have been learning for a year or 2 so far, going okish I guess.
Anyway, I would be very very very very very very very very grateful if some one could help me out.
Thanks!
:D
PS:
Wow, this is a little longer then I thought. Be warned: I do overcomplicate allot! :lol:


_________________
?Sometimes when you innovate, you make mistakes. It is best to admit them quickly, and get on with improving your other innovations.? -Steve Jobs.


MyFutureSelfnMe
Veteran
Veteran

User avatar

Joined: 26 Feb 2010
Age: 47
Gender: Male
Posts: 1,385

25 Mar 2012, 3:49 pm

Sorry to see nobody helped you with this. iOS and Objective C (not to mention Apple's tools) are a major pain in the ass, if I had the answer I'd help you but I don't. Hope you got it.