0

私のアプリには再コーディングがあります。

再コーディングを行うためのカスタム 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];
    }
}

これを行う方法 ?

ありがとう..

4

1 に答える 1

0

セットアップ用のプロジェクト固有のコードをいくつか削除しましたが、入力と出力のセットアップがある場合は、プレビュー/プレビュー レイヤー コードが探しているものです。どのビデオが記録されるかを示すサブレイヤーを追加します。

 - (void)setupSession{
        // create a capture session set session preset
        // get a camera, front facing if possible
        // check to see if camera is available
        // create input
        // create output


        // add output
        [session beginConfiguration];
        [session addInput:input];
        [session addOutput:output];
        [session commitConfiguration];

        // configure orientation
        connection = [output connectionWithMediaType:AVMediaTypeVideo];
        //check to make sure you can record

        // Important for you, the preview layer
        // add preview layer
        captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
        if ([captureVideoPreviewLayer isOrientationSupported])
        {
            [captureVideoPreviewLayer setOrientation:[[UIDevice currentDevice] orientation]];
        } else {
            NSLog(@"Cannot set preview orientation");
        }
        [captureVideoPreviewLayer setFrame:[_previewView bounds]];

        //add sublayer to mainview where you are setting your recording from
        [[self.view layer] addSublayer:captureVideoPreviewLayer];

        // start session
        [session startRunning];
    }
于 2013-01-03T14:59:44.857 に答える