Created
August 26, 2014 06:18
-
-
Save harshad1242/3749f713aa7229fa7cd1 to your computer and use it in GitHub Desktop.
first time it is working, then go back and come again, play pause not working.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidLoad | |
{ | |
NSURL *urlmusic=[[NSURL alloc]initFileURLWithPath:[[NSBundle mainBundle]pathForResource:@"music" ofType:@".mp3"]]; | |
player = [[AVAudioPlayer alloc] initWithContentsOfURL:urlmusic error:nil]; | |
player.numberOfLoops = -1; | |
[player setVolume:1.0]; | |
[player prepareToPlay]; | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view, typically from a nib. | |
} | |
-(void)music:(UIButton *)close | |
{ | |
if ([[NSUserDefaults standardUserDefaults]stringForKey:@"musicbutton"] == nil) | |
{ | |
[player stop]; | |
[musicbutton setImage:[UIImage imageNamed:@"off_button"] forState:UIControlStateNormal]; | |
[[NSUserDefaults standardUserDefaults] setObject:@"on" forKey:@"musicbutton"]; | |
[[NSUserDefaults standardUserDefaults] synchronize]; | |
NSLog(@"off"); | |
NSLog(@"player value%@",player.description | |
); | |
} | |
else | |
{ | |
[musicbutton setImage:[UIImage imageNamed:@"on_button"] forState:UIControlStateNormal]; | |
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:@"musicbutton"]; | |
[[NSUserDefaults standardUserDefaults] synchronize]; | |
[player play]; | |
NSLog(@"on"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment