Forum > Cocoa



I'm not 100% sure if this is the correct place to ask, but does anyone have experience with using NSView?

I have the impression it's Cocoa specific and would need it to be able to embed VLClib on my LCL form.
(see my other post in the Carbon section - I apologize for potential cross posting)

This is the code where I get stuck by lack of experience and knowledge of NSView:

--- Code: ---libvlc_media_player_set_nsobject_t =  procedure(
    p_mi: libvlc_media_player_t_ptr;
    drawable: Pointer
--- End code ---

The drawable pointer seems to be an NSView or something following the VLCOpenGLVideoViewEmbedding protocol (of which I know even less).

This is the "source" of my information (PasLibVlc source):

--- Code: ---(**
 * Set the NSView handler where the media player should render its video output.
 * Use the vout called "macosx".
 * The drawable is an NSObject that follow the VLCOpenGLVideoViewEmbedding
 * protocol:

 // \@protocol VLCOpenGLVideoViewEmbedding <NSObject>
 // - (void)addVoutSubview:(NSView *)view;
 // - (void)removeVoutSubview:(NSView *)view;
 // \@end

 * Or it can be an NSView object.
 * If you want to use it along with Qt4 see the QMacCocoaViewContainer. Then
 * the following code should work:
 * @begincode
 * {
 *     NSView *video = [[NSView alloc] init];
 *     QMacCocoaViewContainer *container = new QMacCocoaViewContainer(video, parent);
 *     libvlc_media_player_set_nsobject(mp, video);
 *     [video release];
 * }
 * @endcode
 * You can find a live example in VLCVideoView in VLCKit.framework.
 * \param p_mi the Media Player
 * \param drawable the drawable that is either an NSView or an object following
 * the VLCOpenGLVideoViewEmbedding protocol.
--- End code ---

hehhe, this is very old, but I will answer in case another person needs.

To get a NSView to place a control, you need to place in your form some kind of empty windowed control (which means a TWinControl descendent, which has a handle property). The best would be writing your own TCustomControl in code, and search the wiki for instructions for that. But if you are more lazy, just use a TPanel or TPaintBox or maybe TImage.

Then to obtain the NSView from a particular control:
1> Make sure you are using the LCL-Cocoa widgetset
2> use this function from unit CocoaUtils:

function GetNSObjectView(obj: NSObject): NSView;

Like this:

uses CocoaAll, CocoaUtils;

  MyControl: TCustomControl;
  MyControlNSView: NSView;
  MyControlNSView := CocoaUtils.GetNSObjectView(NSObject(MyControl.Handle));

and ready to use the NSView! =D


[0] Message Index

Go to full version