Eugene Gordin
Eugene Gordin

Reputation: 4107

How can I draw something on top of AVPlayer video in Cocoa?

In my app I want to be able to draw rectangles on top of the playing video. I already implemented the drawing canvas which is a NSView, and I have a player implemented as well.

However, when I place my drawing canvas on top of my player view, player view is still showing up on top.

I was thinking that my drawing canvas wasn't on top of the player view, but it is. When I change the size of the window, I can see that on the area of the window that is not covered by the video I can draw. However, magically my drawing is not showing up on top of the playing video.

I really don't know where to find the problem.

Any help is highly appreciated!

Upvotes: 4

Views: 1561

Answers (2)

Spencer Williams
Spencer Williams

Reputation: 922

There's a solution for iOS, as answered here, and it works in OS X too (I tested on OS X 10.10.2).

Basically, set the zPosition of the view you want on top:

 topView.layer.zPosition = 1;

Upvotes: 2

TheFuquan
TheFuquan

Reputation: 1797

i also had a problem where one NSView that i add to a superView was layer backed and the last NSView wasn't, and always the layer backed NSView would be on top, so i'd recommend you to enable the layer for any NSView that would come on top of the AVPlayer, [yourCanvasView setWantsLayer : YES];

... i think this would do the job,

Upvotes: 3

Related Questions