Search code examples
objective-ccocoaquicktime

How do I load multiple QTMovie objects and then choose which to play?


I am new to working with Objective-C and Cocoa.

I have followed the sample code for playing a movie with Quicktime that is on here. I am wondering how to expand it so that I can load multiple QTMovies at the beginning of the program, and then play each of them when requested with minimal latency.

My initial strategy was to create a class that holds a QTMovie object and the methods for loading and playing it. Then in my main class I'd have a list of these MovieContainer objects.

When I try implementing this, I get a QTMovieLoadStateError during the loading of each QTMovie with the error message

Domain=NSOSStatusErrorDomain Code=-2098 "The operation couldn’t be completed.
(OSStatus error -2098.)" (component is not thread-safe)

Am I going in completely the wrong direction, or am I merely missing a few lines of code that would make this "thread-safe"?

Thanks for any help.


Solution

  • Before working with QTMovie objects in a background (non-main) thread you need to call:

    [QTMovie enterQTKitOnThread]
    

    or

    [QTMovie enterQTKitOnThreadDisablingThreadSafetyProtection]
    

    Which one to choose would depend on the codec of your movie file. The second variant will allow non-thread-safe components; for some rare codecs this would be the only way.

    The call must be paired with:

    [QTMovie exitQTKitOnThread]