2012-04-11 1 views
0

Talking Tom과 같은 앱을 개발 중입니다. 아이폰 화면을 터치하면 사운드가있는 개 애니메이션이 생성됩니다. iphone 화면의 동영상 녹화 이외에는 모든 것을 구현했습니다. here에 기반한 아이폰 화면. 사운드없이 강아지 애니메이션을 녹음했습니다. 비디오 파일에 오디오를 포함하려면 어떻게해야합니까? 샘플 코드가 있습니까?Talk app처럼 동영상을 녹음

cocos2D를 사용하여 응용 프로그램을 개발하는 경우 샘플 코드 here이 유용 할 것입니다!

답변

1

AVFoundation 프레임 워크에서 AVAudioRecorder를 사용하십시오.

[audioSession setCategory:AVAudioSessionCategoryRecord error:nil]; // assign it to recording session 
    [audioSession setActive:YES error:nil]; // activate it! 
     NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init]; 
     [recordSetting setValue: [NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey]; // assign this special hardware component as the function to record 
    [recordSetting setValue:[NSNumber numberWithFloat:44100.0] 
    forKey:AVSampleRateKey]; //44100 is the sample rate 
    [recordSetting setValue:[NSNumber numberWithInt: 2] 
    forKey:AVNumberOfChannelsKey]; // same thing 
    tmpFile = [NSURL fileURLWithPath: 
     [NSTemporaryDirectory() stringByAppendingPathComponent: 
    [NSString stringWithFormat: @"%.0f.%@", 
    [NSDate timeIntervalSinceReferenceDate] * 1000.0, 
     @"caf"]]]; // how we identify the audio written to the file to play later 
     recorder = [[AVAudioRecorder alloc] initWithURL:tmpFile settings:recordSetting 
    [recorder setDelegate:self]; 
    [recorder prepareToRecord]; 
    [recorder record]; 

PLAYING :

AVAudioSession * audioSession = [AVAudioSession sharedInstance]; 
    [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil]; 
     [audioSession setActive:YES error:nil]; 
     AVAudioPlayer * player = 
     [[AVAudioPlayer alloc] initWithContentsOfURL:tmpFile error:nil]; // takes recording data from tmpFile where we wrote the recording in 
     [player prepareToPlay]; 
    [player play]; 

그게 좀 AVAudioRecorder 인스턴스와 ** 샘플 코드

녹음 NSURL 인스턴스를 작성 AVFoundation 프레임 워크를 가져 오기 및 는 AVAudioRecorderDelegate 을 준수 샘플 코드 .... 당신을 도울 수는 있지만 문서를 읽으십시오. 입을 움직일 수있는 방법이나 확실하지 않은 경우 Im 당신은 피치를 바꾸고 싶었지만 이것은 녹음의 시작입니다

+0

니스 ... 아프다 시도하고 알려주세요 .. –

+0

@BalanPrabhu 이것이 도움이된다고 생각한다면 ... – MCKapur