on the WEB

Entries in AVPlayer (1)

Friday
Feb042011

NTAVManager Class

I was working on a simple project where I needed to track a large number of AVPlayer resources. I decided to create a class Manager/Factory to keep track of the resources and avoid duplicates. The class implements the Factory and Singleton patterns.

Both of these patterns are pretty simple; the singleton guarantees only on instance of the manager class preventing duplicates of AVPlayer objects. The manager class uses the file name descriptor to reference the object. If the object does not exists the manager will create the object and store a copy. I recommend placing the filenames inside of constant definitions, this way the compiler can catch any type-o's.

In order to help with memory management I've included two function tidyUpMemory and flushMemory. Flush will remove all the objects in the store. TidyUpMemory will iterate through each object and check the last access time. If the last access time is greater than the defined interval it will remove the object, leaving behind objects that are being used. The access time on the objects are updated every time you use an object.

You can find the project with a simple demo here:iOS-AVManager-Class

Let me know what you think.