如何将AVCaptureMovieFileOutput对象保存到NSSavePanel中

时间:2013-12-12 11:12:00

标签: ios objective-c cocoa-touch avcapturemoviefileoutput

您好我必须将保存电影文件实现到自定义文件夹中,为此我使用的是NSSavepanel。 我是NSSavepanel的新手,所以我不知道如何将AVCaptureMovieFileOutput对象添加到NSSavePanel

我的代码是

-(void)doSaveDocument
{

    NSSavePanel *savePanel = [NSSavePanel savePanel];

    [savePanel setTitle:@"Save image"];
    [savePanel setNameFieldStringValue:@"AnnotatedImage.mov"];
    if([savePanel runModal] == NSFileHandlingPanelOKButton)
    {
        [self takeScreenRecording:rect saveAtPath:[savePanel URL]];
        [[NSWorkspace sharedWorkspace] openURL:[savePanel URL]];

        [mMovieFileOutput startRecordingToOutputFileURL:[savePanel URL] recordingDelegate:self];
    }


}

1 个答案:

答案 0 :(得分:0)

NSArray *paths1 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory1 = [paths1 objectAtIndex:0]; // Get documents folder
        NSString *dataPath = [documentsDirectory1 stringByAppendingPathComponent:@"MyVideo"];
        NSError *error;
        if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
            [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error];

    NSString *stryourfilename=@"Video1";

    dataPath=[NSString stringWithFormat:@"%@/%@.mp4",dataPath,stryourfilename];
    NSData *dat=[NSData dataWithContentsOfURL:videoURL];

    BOOL ok = [[NSFileManager defaultManager] createFileAtPath:dataPath
                                                      contents:nil attributes:nil];

    if (!ok) {

    } else {
        NSFileHandle* myFileHandle = [NSFileHandle fileHandleForWritingAtPath:dataPath];

        [myFileHandle writeData:dat];

        [myFileHandle closeFile];


    }