私のアプリには再コーディングがあります。
再コーディングを行うためのカスタム ScreenCapture ビューを作成しました。
メインビュー用のビデオを録画したいと思います。(つまり、self.view で)、しかし機能していません。
次のコードを使用して、カスタム ビューの記録を行いました。
- (IBAction)btnRecording_Pressed:(id)sender {
if (Isrecording ==YES)
{
//
// imgDustbin.hidden=YES;
// [[NSUserDefaults standardUserDefaults ] setValue:@"NO" forKey:@"DUSTBIN"];
//---
[voiceRecorder stop];
[captureview stopRecording];
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;
[audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
if(err)
{
NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
return;
}
[audioSession setActive:YES error:&err];
err = nil;
if(err){
NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
return;
}
recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
[recordSetting setValue :[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
// NSString *recorderFilePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];//26
NSString *recorderFilePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
recorderFilePath = [recorderFilePath stringByAppendingPathComponent:@"tempRecording.caf"];
NSURL *urls = [NSURL fileURLWithPath:recorderFilePath];
err = nil;
voiceRecorder = [[ AVAudioRecorder alloc] initWithURL:urls settings:recordSetting error:&err];
//[recorder setMeteringEnabled:YES];
if(!voiceRecorder){
NSLog(@"recorder: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle: @"Warning"
message: [err localizedDescription]
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
return;
}
//prepare to record
[voiceRecorder setDelegate:self];
[voiceRecorder prepareToRecord];
//scrren short of screen
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(self.view.bounds.size);
[captureview.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * imageData = UIImageJPEGRepresentation(viewImage, 1.0);
// NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);//26
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
documentsDirectory = [documentsDirectory stringByAppendingPathComponent:@"VideoScreen.jpg"];
[imageData writeToFile:documentsDirectory atomically:YES];
//--------------------
[voiceRecorder record];
[captureview performSelector:@selector(startRecording) withObject:nil afterDelay:0];
Isrecording =NO;
[btnRecord setTitle:@"Stop" forState:UIControlStateNormal];
}
else if (!Isrecording)
{
//
imgDustbin.hidden =NO;
[[NSUserDefaults standardUserDefaults ] setValue:@"YES" forKey:@"DUSTBIN"];
//------
[voiceRecorder stop];
[captureview stopRecording];
[self createVideo];
Isrecording=YES;
[btnRecord setTitle:@"Record" forState:UIControlStateNormal];
}
}
これを行う方法 ?
ありがとう..