iphone,android,web,wp7同时录音及播放-m4a格式 (3)

self.navigationItem.leftBarButtonItem = SYSBARBUTTON(UIBarButtonSystemItemPause, self, @selector(pauseRecording));

}

- (void) pauseRecording

{

// pause an ongoing recording

[self.recorderpause];

self.navigationItem.leftBarButtonItem = BARBUTTON(@"Continue", @selector(continueRecording));

self.navigationItem.rightBarButtonItem = nil;

}

- (BOOL) record

{

    NSMutableDictionary *recordSetting = [[NSMutableDictionaryalloc] init];

    [recordSetting setValue:[NSNumbernumberWithInt:kAudioFormatAppleLossless] forKey:AVFormatIDKey];

    [recordSetting setValue:[NSNumbernumberWithFloat:22100.0] forKey:AVSampleRateKey];

[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];

    [recordSetting setValue:[NSNumbernumberWithInt:16] forKey:AVLinearPCMBitDepthKey];

    [recordSetting setValue:[NSNumbernumberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];

    [recordSetting setValue:[NSNumbernumberWithBool:NO] forKey:AVLinearPCMIsFloatKey];

    // File URL

NSURL *url = [NSURLfileURLWithPath:FILEPATH];

    NSLog(@"Path : %@", [url absoluteString]);

NSError *err = nil;

    if([self.recorderisRecording])

{

[self.recorder stop];

self.recorder = nil;

}

self.recorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:&err];

    [self.recordersetDelegate:self];

if(err)

NSLog(@"ERROR : %@", err);

BOOL st = [self.recorder prepareToRecord];

if(!st){

        NSLog(@"222Failed");

}

    self.recorder.meteringEnabled = YES;

BOOL status = [self.recorder record];

if(!status)

        NSLog(@"1111Failed");

// Set a timer to monitor levels, current time

timer = [NSTimerscheduledTimerWithTimeInterval:0.1ftarget:selfselector:@selector(updateMeters) userInfo:nilrepeats:YES];

// Update the navigation bar

self.navigationItem.rightBarButtonItem = BARBUTTON(@"Done", @selector(stopRecording));

self.navigationItem.leftBarButtonItem = SYSBARBUTTON(UIBarButtonSystemItemPause, self, @selector(pauseRecording));

returnYES;

}

- (BOOL) startAudioSession

{

// Prepare the audio session

NSError *error;

self.session = [AVAudioSession sharedInstance];

if (![self.session setCategory:AVAudioSessionCategoryPlayAndRecord error:&error])

{

NSLog(@"Error: %@", [error localizedDescription]);

returnNO;

}

if (![self.session setActive:YES error:&error])

{

NSLog(@"Error: %@", [error localizedDescription]);

returnNO;

}

return self.session.inputIsAvailable;

}

- (void) viewDidLoad

{

self.navigationController.navigationBar.tintColor = COOKBOOK_PURPLE_COLOR;

self.title = @"Audio Recorder";

if ([selfstartAudioSession])

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwpjws.html