视频录制就像会说话的汤姆应用程序

时间:2012-04-11 14:47:02

标签: ios xcode cocos2d-iphone video-recording

我正在开发像Talking Tom这样的应用程序。当我们触摸Iphone屏幕时会产生一些带声音的狗动画。为此我实现了除了iphone屏幕的视频录制之外的一切。我实现了基于{{iphone屏幕的视频录制3}} ..它记录了没有声音的狗动画。我需要做什么才能将音频包含在视频文件中?是否有可用的示例代码?

如果您使用cocos2D开发应用程序,示例代码here将非常有用!

1 个答案:

答案 0 :(得分:1)

在AVFoundation框架中使用AVAudioRecorder。导入AVFoundation框架和 符合AVAudioRecorderDelegate 创建AVAudioRecorder实例和NSURL实例 **样本代码

录音:

    [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];

这只是一些示例代码....来帮助你,但否则阅读文档 我不知道你怎么能动画嘴巴,或者如果你想改变音高,但这是录音的开始