Search code examples
macoscocoacalayernsviewavplayer

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!


Solution

  • 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;