iphoneobjective-cavplayerhppleavqueueplayer

Design choice with AVQueuePlayer and hpple


I'm designing an iPhone app that plays 3 files in sequence, using the AVQueuePlayer class.

The 3 urls that I need to play in sequence must be extracted first from an .htm file, using the http:// protocol. For that purpose I'm using the TFHpple class, from here hpple git project

My problem is that my AVQueuePlayer player must run on the Main Thread, and when I try to parse the .htm file the screen doesn't respond to any touch.

I need the urls first, that are contained on these .htm files to be parsed, and then feed the urls to the AVQueuePlayer player.

I was reading the Apple documentation that says that multi threading is a poor choice for Networking applications, but I need to use hpple to parse the .htm content.

How to solve this problem?


Solution

  • If using AVQueuePlayer on the main-thread but triggered from a different thread is the only issue, simply wrap its startup using a method that is invoked from the other thread using performSelectorOnMainThread.


    From the NSObject reference;

    - (void)performSelectorOnMainThread:(SEL)aSelector 
                             withObject:(id)arg 
                          waitUntilDone:(BOOL)wait
    

    Invokes a method of the receiver on the main thread using the default mode.

    Discussion

    You can use this method to deliver messages to the main thread of your application. The main thread encompasses the application’s main run loop, and is where the NSApplication object receives events. The message in this case is a method of the current object that you want to execute on the thread.

    This method queues the message on the run loop of the main thread using the common run loop modes—that is, the modes associated with the NSRunLoopCommonModes constant. As part of its normal run loop processing, the main thread dequeues the message (assuming it is running in one of the common run loop modes) and invokes the desired method. Multiple calls to this method from the same thread cause the corresponding selectors to be queued and performed in the same same order in which the calls were made.

    You cannot cancel messages queued using this method. If you want the option of canceling a message on the current thread, you must use either the performSelector:withObject:afterDelay: or performSelector:withObject:afterDelay:inModes: method.


    Additionally, I would recommend looking into RaptureXML for parsing xHTML as it is lean, fast and convenient.