0

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.

flutillie
  • 554
  • 1
  • 7
  • 19

1 Answers1

0

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]
Regexident
  • 29,441
  • 10
  • 93
  • 100
Davyd Geyl
  • 4,578
  • 1
  • 28
  • 35
  • Thanks for your help! That did eliminate the thread error, but now I get `A necessary data reference could not be resolved.`. – flutillie Jun 05 '12 at 13:40
  • I found http://stackoverflow.com/questions/5582274/qtkit-strange-error with the same error, but the solution does not help. I only see these errors when I check the value of `QTMovieLoadStateAttribute` for `QTMovieLoadStateError`. – flutillie Jun 05 '12 at 13:50
  • The movie may take some time to load. You need to check attributeForKey:`QTMovieLoadStateAttribute` and wait until it equals `QTMovieLoadStateComplete`. For example `while ([[movie attributeForKey:QTMovieLoadStateAttribute] longValue] != QTMovieLoadStateComplete) { [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; }` – Davyd Geyl Jun 05 '12 at 23:16