Playing two QTMovie's synchronously
I have a Cocoa application that should play two different QTMovie objects completely synchronized. Both movies are equal in resolution, size etc. but might have a different length. The movies are compressed and it's necessary that they are multithreaded.
My current aproach is:
NSMutableDictionary *movieAttributes1 = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:NO], QTMovieOpenAsyncOKAttribute,
[NSNumber numberWithBool:YES], QTMovieOpenForPlaybackAttribute,
nil];
[movieAttributes1 setValue:pathOfFile1 forKey开发者_如何转开发:QTMovieFileNameAttribute];
NSMutableDictionary *movieAttributes2 = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:NO], QTMovieOpenAsyncOKAttribute,
[NSNumber numberWithBool:YES], QTMovieOpenForPlaybackAttribute,
nil];
[movieAttributes2 setValue:pathOfFile2 forKey:QTMovieFileNameAttribute];
QTMovie* leftMovie = [QTMovie movieWithAttributes:movieAttributes1 error:nil];
QTMovie* rightMovie = [QTMovie movieWithAttributes:movieAttributes2 error:nil];
....
[leftMovie play];
[rightMovie play];
Done in the play-buttons ClickHandler.
In 9 of 10 cases this works, but sometimes the movies are played asynchronously. I'm also sure they will become async in case of high cpu load.
Any ideas? Thanks a lot.
I don't believe there's any supported way to do this in the API. You might have to sync them periodically.
To do this, set up a timer that sets the precise time of the second movie to that of the first every second or half-second. If either goes over the other's max duration, stop the timer and let it run normally.
精彩评论