2016-03-21 24 views
1

Aslında Ses Kaydetmek ve Dokümana Kaydetmek, Dosya Aktarım var, ve Ses Dosyalarını Eklemek istiyorum, Ama Gerçek Ses'i o Yola eklemek istiyorum, Çalışmıyor, Bu Kodu Yazıyorum Bu gibi DidFinish içinde.AVAudioRecorderDelegate'in Delegeleri Aramıyor

-(IBAction)onClickSave:(id)sender 
{ 
    [audioRecorder stop]; 
    AVAudioSession *audioSession = [AVAudioSession sharedInstance]; 
    [audioSession setActive:NO error:nil]; 


} 

Ve Ses

Kaydedilmiş O Tasarruf İçin
- (void)viewDidLoad { 
     [super viewDidLoad]; 
     self.navigationItem.title = @"Recording Area"; 
     [btnRecord setBackgroundImage:[UIImage imageNamed:@"Record.png"] forState:UIControlStateNormal]; 

     session = [AVAudioSession sharedInstance]; 
     [session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil]; 

     audioRecorder.delegate = self; 


     NSDate *today = [[NSDate alloc]init]; 
     NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; 
     [dateFormatter setDateFormat:@"hh:mm:ss"]; 

     NSString *currentTime = [dateFormatter stringFromDate:today]; 

     NSString *outputPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0]; 

     outputPath = [outputPath stringByAppendingString:[NSString stringWithFormat:@"%@.m4a",currentTime]]; 

     NSMutableDictionary *recordDictionary = [[NSMutableDictionary alloc] init]; 

     [recordDictionary setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey]; 
     [recordDictionary setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; 
     [recordDictionary setValue:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey]; 


     audioRecorder = [[AVAudioRecorder alloc]initWithURL:[NSURL fileURLWithPath:outputPath] settings:recordDictionary error:nil]; 

     audioRecorder.meteringEnabled = YES; 
     [audioRecorder prepareToRecord]; 

    } 

and For Recording Audio 

    -(IBAction)onClickRecord:(id)sender 
{ 

    if(player.playing) 
    { 
     [player stop]; 
    } 


    if([[btnRecord backgroundImageForState:UIControlStateNormal]isEqual:[UIImage imageNamed:@"Record.png"]]) 
    { 

     if (!audioRecorder.recording) 

     { 
      AVAudioSession *session = [AVAudioSession sharedInstance]; 
      [session setActive:YES error:nil]; 


      [audioRecorder record]; 
      [btnRecord setBackgroundImage:[UIImage imageNamed:@"Pause.png"] forState:UIControlStateNormal]; 
     } 



    } 

    else if([[btnRecord backgroundImageForState:UIControlStateNormal]isEqual:[UIImage imageNamed:@"Pause.png"]]) 
    { 
     [audioRecorder pause]; 

     [btnRecord setBackgroundImage:[UIImage imageNamed:@"Record.png"] forState:UIControlStateNormal]; 
    } 




} 

Nihayet o Kodum aslında çalışma edilmedi Delegeler i

- (void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag 
{ 


    [btnRecord setBackgroundImage:[UIImage imageNamed:@"Record.png"] forState:UIControlStateNormal]; 
    [arrayFiles addObject:recorder.url.absoluteString]; 
    NSLog(@"Array %@",arrayFiles); 

} 

Yani belirtin lütfen bu yöntemi çağırmak için mümkün değil duyuyorum mı Yanlış olduğum yerdeyim. Sen AVAudioRecorder

Taşı initialising önce temsilci ayarlarken

+0

senin Sesli kayıt 'strong' referans –

+1

Daha önce ses kayıt cihazına temsilci ayarladığımız sahip olduğundan emin olun aslında – dan

+0

@property (güçlü, nonatomic) AVAudioRecorder * audioRecorder oluşturmak Bu dosyayı oluşturduk .. –

cevap

2

audioRecorder.delegate = self; init sonra

audioRecorder = [[AVAudioRecorder alloc]initWithURL:[NSURL fileURLWithPath:outputPath] settings:recordDictionary error:nil]; 
audioRecorder.meteringEnabled = YES; 
audioRecorder.delegate = self; 

[audioRecorder prepareToRecord]; 
+0

Teşekkür ederim! Çok zaman kaydettiniz ... –

+0

Teşekkürler @dan, ilk önce bunu gözlemleyen oydu) –

İlgili konular