Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //play music button method
- - (IBAction)playMusicButtonPressed:(id)sender {
- NSLog(@"playing");
- [audioPlayer stop];
- //get path of audio file
- NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat: @"Documents/%@",song.songTitle, @"mp3"]];
- //error
- NSError *error;
- //check whether file is exist or not
- NSFileManager *filemanager = [NSFileManager defaultManager];
- if (![filemanager fileExistsAtPath:path]) {
- UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"File Has Been deleted" message:@"Remove it from Database also" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
- [alertView show];
- [alertView release];
- }
- else
- {
- soundFileURL = [NSURL fileURLWithPath:[NSHomeDirectory() stringByAppendingPathComponent: [NSString stringWithFormat: @"Documents/%@",song.songTitle, @"mp3"]]];
- audioPlayer =[[AVAudioPlayer alloc]initWithContentsOfURL:soundFileURL error:&error];
- audioPlayer.delegate = self;
- NSLog(@"Sound File path %@",soundFileURL);
- }
- // NSLog(@"Sound File path %@",soundFileURL);
- NSLog(@"Stopped");
- //prepare audio player
- [audioPlayer prepareToPlay];
- [audioPlayer play];
- if (audioPlayer) {
- NSTimeInterval duration = [audioPlayer currentTime];
- [self setCurrentAudioProgress:0.0 duration:duration];
- // [playMusic setTitle:@"Pause" forState:UIControlStateNormal];
- // [playMusic addTarget:self action:@selector(pause) forControlEvents:UIControlEventTouchUpInside];
- }
- ///start timer
- [NSTimer scheduledTimerWithTimeInterval:1
- target:self
- selector:@selector(updatePreviewingProgress:)
- userInfo:nil
- repeats:YES];
- }
Advertisement
Add Comment
Please, Sign In to add comment