Guest User

Untitled

a guest
Nov 1st, 2011
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //play music button method
  2. - (IBAction)playMusicButtonPressed:(id)sender {
  3.    
  4.  
  5.        
  6.    
  7.     NSLog(@"playing");
  8.    
  9.     [audioPlayer stop];
  10.        
  11.  
  12.    
  13.    
  14.     //get path of audio file
  15.     NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat: @"Documents/%@",song.songTitle, @"mp3"]];
  16.    
  17.    
  18.    
  19.     //error
  20.     NSError *error;
  21.    
  22.     //check whether file is exist or not
  23.     NSFileManager *filemanager = [NSFileManager defaultManager];
  24.    
  25.     if (![filemanager fileExistsAtPath:path]) {
  26.        
  27.        
  28.         UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"File Has Been deleted" message:@"Remove it from Database also" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
  29.         [alertView show];
  30.         [alertView release];
  31.     }
  32.    
  33.     else
  34.     {
  35.         soundFileURL = [NSURL fileURLWithPath:[NSHomeDirectory() stringByAppendingPathComponent: [NSString stringWithFormat: @"Documents/%@",song.songTitle, @"mp3"]]];
  36.        
  37.         audioPlayer =[[AVAudioPlayer alloc]initWithContentsOfURL:soundFileURL error:&error];
  38.         audioPlayer.delegate = self;
  39.         NSLog(@"Sound File path %@",soundFileURL);
  40.        
  41.        
  42.     }
  43.    
  44.    
  45.        
  46.     // NSLog(@"Sound File path %@",soundFileURL);
  47.    
  48.    
  49.         NSLog(@"Stopped");
  50.    
  51.         //prepare audio player
  52.     [audioPlayer prepareToPlay];
  53.     [audioPlayer play];
  54.  
  55.    
  56.     if (audioPlayer) {
  57.        
  58.        
  59.         NSTimeInterval duration = [audioPlayer currentTime];
  60.         [self setCurrentAudioProgress:0.0 duration:duration];
  61.        
  62.         //   [playMusic setTitle:@"Pause" forState:UIControlStateNormal];
  63.        
  64.         //  [playMusic addTarget:self action:@selector(pause) forControlEvents:UIControlEventTouchUpInside];
  65.     }
  66.    
  67.     ///start timer
  68.     [NSTimer scheduledTimerWithTimeInterval:1
  69.                                      target:self
  70.                                    selector:@selector(updatePreviewingProgress:)
  71.                                    userInfo:nil
  72.                                     repeats:YES];
  73.        
  74.    
  75.    
  76.    
  77.  
  78.  
  79. }
  80.  
  81.  
Advertisement
Add Comment
Please, Sign In to add comment