On 20.12.2016 at 17:58 Kyle Sluder wrote:

> On Tue, Dec 20, 2016, at 08:59 AM, Andreas Falkenhahn wrote:
>> So everybody knows that all things relating to UIKit have to be done
>> on the main thread.

>> But what about AVFoundation functions which bear some resemblance to
>> UIKit APIs? Do these have to be called on the main thread too or can
>> they also be called from a worker thread?

>> For example, when adding an AVPlayerLayer to a view using addSubview()
>> I have to do this on the main thread of course.

>> But what about changing the frame size of an AVPlayerLayer using
>> setFrame()? AVPlayerLayer inherits from CALayer which is part of the
>> QuartzCore framework, not UIKit. But of course CALayer methods like
>> setFrame() bear a strong resemblance to their UIKit counterparts so
>> I'm wondering whether it is really allowed to call setFrame() from
>> a worker thread?

> Since AVPlayerLayer is a layer, not a view, it cannot be added with
> addSubview. It can either be added as a sublayer to your view’s layer,
> or it can be wrapped in a view and *that view* added as a subview.

Oops, sorry, of course I meant to add it as a sublayer to the view's
layer using

    [[view layer] addSublayer:videolayer];

> The distinction is important in many ways, but in this case the answer
> is the same for both: don’t do this from a background thread.

Ok, thanks. I'm now using dispatch_sync() to run this stuff on the
main thread.

But what about AVPlayer methods like "play", "pause", "seekToTime"
etc. Those are not directly related to the CALayer level. So are they
safe to call from a background thread?

-- 
Best regards,
 Andreas Falkenhahn                            mailto:andr...@falkenhahn.com


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to