Stepping through frames of an NSMovie
Stepping through frames of an NSMovie
- Subject: Stepping through frames of an NSMovie
- From: Ken Tabb <email@hidden>
- Date: Wed, 30 May 2001 10:54:58 +0100
Hi,
I have some code which aims to (!) step through an NSMovie frame by
frame, via its parent NSMovieView's stepForward method. At each frame it
makes an NSImage and then I'm off doing my own thing to those NSImages.
I'm having a bit of grief reliably getting a given frame. Basically the
code is the following... please excuse some of the hardwiring (eg. parent
view)... I was getting desperate!
- (void)playToEnd
{
long int i;
GoToBeginningOfMovie([self qtMovie]);
[_parentNSMovieView start:nil]; //this line is a bone of contention
[self setCurrentFrame:0];
for(i=0; i<([self numberOfFrames] / 3); i++, _currentFrame++) //steps
through first third of the movie
{
[_parentNSMovieView stepForward:nil]; //gets next frame
[self getFramePictIntoNSImage]; //and puts it in an NSImage
}
[self displayInNSImageView:nil]; //displays the last frame of the loop
printf("Currently showing frame #%d\n", i+1);
}
- (void)getFramePictIntoNSImage //from Vince deMarco
{
PicHandle picHandle;
int imageSize;
void *picBytes;
NSData *data;
NSPICTImageRep *pictImageRep;
picHandle = GetMoviePict([self qtMovie], GetMovieTime([self qtMovie],
nil));
if(picHandle)
{
imageSize = GetHandleSize((Handle)picHandle);
picBytes = (*picHandle);
data = [NSData dataWithBytes:picBytes length:imageSize];
pictImageRep = [NSPICTImageRep imageRepWith
Data:data];
_theNSImage = [[NSImage alloc] initWithSize:[pictImageRep size]];
//convert to TIFF before NSBitmapImageRep... poss not necessary, but
seems to be
[_theNSImage lockFocus];
[pictImageRep drawAtPoint:NSMakePoint(0,0)];
[_theNSImage unlockFocus];
KillPicture(picHandle);
}
}
... basically what I get is:
[1] If I remove the "[_parentNSMovieView start:nil];", it only ever grabs
& shows the first frame of the movie, no matter which frame I advance to.
[2] If I leave the "[_parentNSMovieView start:nil];" in, it shows me a
frame far further ahead than the one I should be seeing. I get a
different frame every time I run it (as if it's playing the movie and
grabbing a frame from the playing movie).
Also if I move the "[_parentNSMovieView start:nil];" to the start of the
loop and finish it off with a similar "[_parentNSMovieView stop:nil];",
thus:
[_parentNSMovieView start:nil];
[_parentNSMovieView stepForward:nil]; //gets next frame
[self getFramePictIntoNSImage]; //and puts it in an NSImage
[_parentNSMovieView stop:nil];
Again I get frames far ahead of what I'm expecting. Calling
"[_parentNSMovieView setPlaysEveryFrame:YES];" seems to make no
difference at all. Maybe I'm wrong to be using "nil" on the parameters in
the calls to 'start' & 'stop', but the docs (even the online ones) don't
make it clear what these should be set to.
So what am I doing wrong? Answers on a postcard please...
Thanks in advance,
the boy Ken
---------
Ken Tabb.
Mac & UNIX C/C++/Java developer (Health & Human Sciences),
Machine Vision researcher/programmer (Computer Science),
University of Hertfordshire, England
http://www.health.herts.ac.uk/ken/
Certified non-Microsoft Solution Provider