我正在爲iPad構建一個多線程應用程序。我有這個類從影片剪輯中提取幀,我有一個UIScrollView來顯示我提取的東西。框架提取器運行在不同的線程中,我只想在提取一定數量的框架後纔開始構建滾動視圖。因此,我創建了這個名爲buffering的BOOL屬性,它通過線程進行更新。我的視圖控制器觀察這個屬性,並且只有在這個屬性等於NO NO開始構建ScrollView之後。iPad GUI僅在觸摸後更新
問題是,在構建方法被調用後,我沒有看到GUI中的任何更改。我只能看到滾動視圖後,我觸摸屏幕
下面有什麼即時通訊做:
要創建線程:
[NSThread detachNewThreadSelector:@selector(startReading) toTarget:self withObject:nil];
在線程中運行的代碼:
-(void) startReadingWithTimeRange:(STimeRange *) timeRange;
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // Top-level pool
//setting the time range for reading the file
[assetReader setTimeRange:timeRange.timeRange];
//start reading
[assetReader startReading];
//declearing about the buffer
CMSampleBufferRef buffer;
int z = 0;
while ([assetReader status]==AVAssetReaderStatusReading)
{
z++;
//reading buffer
buffer = [assetReaderTrackOutput copyNextSampleBuffer];
if (buffer == NULL) break;
//converting the buffer to UIImage
UIImage *frameImage = imageFromSampleBuffer(buffer);
CMTime time = CMSampleBufferGetOutputPresentationTimeStamp(buffer);
NSLog(@"###duration %lld",time.value/time.timescale);
SFrame *frame = [[SFrame alloc] initWithImage:frameImage andTime:time];
//add it to the frame array
[framesArray addObject:frame];
[frame release];
//check if buffer is not null and needed release
//release the buffer
CFRelease(buffer);
if ([framesArray count] > 100 && self.buffering) {
[self willChangeValueForKey:@"buffering"];
self.buffering = NO;
[self didChangeValueForKey:@"buffering"];
}
}
[pool release];
}
我真的很無知我真的很感謝任何幫助
您的選擇器與方法名稱不匹配... – jakev
'startReading'只能調用'startReadingWithTimeRange:'正確範圍 –
有趣的部分可能是您實際「構建滾動視圖」的代碼。我的猜測是你需要一個'setNeedsDisplay'調用。 – mrueg