2012-12-24 23 views
5

私は、画面を記録する私のアプリで機能を実装しようとしています。私はいくつかのサンプルコードとWWDC 2012ビデオで見つけたコードを持っています。CGDisplayStreamで画面をキャプチャ

これまでのところ私はこれを持っています。

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { 

    // Get a list of displays. Copied from working apple source code. 
    [self getDisplayList]; 

    DisplayRegistrationCallBackSuccessful = NO; 

    // Register the event for modifying displays. 
    CGError err = CGDisplayRegisterReconfigurationCallback(DisplayRegisterReconfigurationCallback, NULL); 
    if (err == kCGErrorSuccess) { 
     DisplayRegistrationCallBackSuccessful = YES; 
    } 

    // Insert code here to initialize your application 

    const void *keys[1] = { kCGDisplayStreamSourceRect }; 
    const void *values[1] = { CGRectCreateDictionaryRepresentation(CGRectMake(0, 0, 100, 100)) }; 
    CFDictionaryRef properties = CFDictionaryCreate(NULL, keys, values, 1, NULL, NULL); 

    stream = CGDisplayStreamCreate(displays[0], 100, 100, '420f', properties, 
                ^(CGDisplayStreamFrameStatus status, uint64_t displayTime, IOSurfaceRef frameSurface, CGDisplayStreamUpdateRef updateRef) { 
                 NSLog(@"Next Frame"); // This line is never called. 
                }); 

    runLoop = CGDisplayStreamGetRunLoopSource(stream); 

    CGError err = CGDisplayStreamStart(stream); 
    if (err == CGDisplayNoErr) { 
     NSLog(@"Works"); 
    } else { 
     NSLog(@"Error: %d", err); 
    } 
} 

私が遭遇している問題は、DisplayStreamのコールバックブロックが呼び出されていないことです。エラーや警告が表示されません。私が紛失しているか、間違っていたことはありますか?

+2

は、あなたが参照として使用したサンプルやビデオを示していただけますか? –

答えて

1

CGDisplayStreamCreateWithDispatchQueueを使用し、dispatch_queue_create("queue for dispatch", NULL);をキューとして使用して問題を解決しました。何が価値がある、それはあなたが実行ループのソースを取得しているように見えますが、その後、現在の実行ループに追加しないために

関連する問題