tags:

views:

121

answers:

1

Hi there , iam using AVFoundation Framework to play mp3 file ,everything works great ، i have 2 buttons and i put they together , [Play and resume with .hidden function],when user play music [play button going to hide and resume button un hide], so if the user change view , (music is playing) and back to previews view, the buttons don't work normally it means just play music and resume doesn't work , i put my codes to the viewDidLoad , and i know it's because of that but how can i solve this problem ?

   NSString * musicSonati = [[NSBundle mainBundle] pathForResource:@"music"      ofType:@"mp3"];
myMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:musicSonati] error:NULL];
myMusic.delegate = self;
myMusic.numberOfLoops = -1; 
pauseM.hidden = YES;
play.hidden = NO;
+1  A: 

My guess is that a big part of your problem is that your "previews view" is handling all the responsibility for playing the sounds through the AVAudioPlayer framework. What you want to do instead is redesign your app, so there is a proxy object handling AVAudioPlayer. Create and initalize this proxy object in your app delegate, and then pass it along to the root view controller, and through to any other view controllers that need to handle sound playing.

With that redesigned, your "previews view" merely has to ask (in viewDidLoad) your sound proxy object if it's playing a sound (whether by interrogation, or by registering to receive NSNotifications from the object) and set its own state (i.e. buttons) accordingly.

Shaggy Frog
i switch views with pagecurl , but with [self presentModalViewController:qazal animated:YES]; i don't have that problem
Momeks