NPAPI插件编写学习记录01

本文详细介绍了如何使用Apple的插件技术开发基于Safari的电影播放器插件,包括初始化过程、实例结构、对象创建及方法实现等关键步骤,并提供了中文参考资料,帮助开发者快速上手。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Apple官网示例:https://developer.apple.com/library/safari/samplecode/NPAPI_Core_Animation_Movie_Plugin/Introduction/Intro.html

项目名称:NetscapeCoreAnimationMoviePlugin

 相关中文资料地址:http://www.tanhao.me/pieces/1084.html

一,main.m:

  //通过此方法将浏览器的对象返回给插件

  NPError NP_Initialize(NPNetscapeFuncs* browserFuncs)
  {
      browser = browserFuncs;
      return NPERR_NO_ERROR;
  }
 
  // 每个实例存储结构
typedef struct PluginObject
{

  NPP npp;

    NPWindow window;

    CALayer *rootLayer;

    MovieControllerLayer *controllerLayer;

    QTMovieLayer *movieLayer;

    CALayer *mouseDownLayer;

    NSURL *movieURL;

    QTMovie *movie;

    // The NPObject for this scriptable object.

    NPObject *movieNPObject;

} PluginObject;
=============================
=============================

  NP_GetEntryPoints{

    ...

    pluginFuncs->getvalue = NPP_GetValue;

    ...

    }

    ||

    ||

  NPP_GetValue(NPP instance, NPPVariable variable, void *value)

{

......

  obj->movieNPObject = createMovieNPObject(instance, obj->movie);  <=== 【MovieNPObject.m:

NPObject *createMovieNPObject(NPP npp, QTMovie *movie) 】

......

}

  ||

  ||

二,MovieNPObject.m:

  NPObject *createMovieNPObject(NPP npp, QTMovie *movie)

{

......

  (MovieNPObject *)browser->createobject(npp, &movieNPClass);

......

}

  ||

  ||

static NPClass movieNPClass = {

    NP_CLASS_STRUCT_VERSION,

    movieNPObjectAllocate, // NP_Allocate

    movieNPObjectDeallocate, // NP_Deallocate

    0, // NP_Invalidate

    movieNPObjectHasMethod, // NP_HasMethod

    movieNPObjectInvoke, // NP_Invoke

    0, // NP_InvokeDefault

    0, // NP_HasProperty

    0, // NP_GetProperty

    0, // NP_SetProperty

    0, // NP_RemoveProperty

    0, // NP_Enumerate

    0, // NP_Construct

};

  ||

  ||

static bool movieNPObjectHasMethod(NPObject *obj, NPIdentifier name)

{......}

static bool movieNPObjectInvoke(NPObject *npObject, NPIdentifier name, const NPVariant* args, uint32_t argCount, NPVariant* result)

{......}

 

===============

===============

===============

关于MovieControllerLayer

一,main.m:

typedef struct PluginObject

{

......

MovieControllerLayer *controllerLayer;

......

}

对controllerLayer的使用:

handleMouseDown{} ==> MovieControllerLayer类:MovieControllerLayer.m

handleMouseUp{}

handleMouseDragged{}

handleMouseEntered{}

handleMouseExited{}

setupLayerHierarchy{}

 

 ==============

================

MovieNPObject.m:
  

static NPClass movieNPClass = {

    NP_CLASS_STRUCT_VERSION,

    movieNPObjectAllocate, // NP_Al

 }

  ||

  

static NPObject *movieNPObjectAllocate(NPP npp, NPClass* theClass)

{

    initializeIdentifiers();

 

    MovieNPObject *movieNPObject = malloc(sizeof(MovieNPObject));

    movieNPObject->movie = 0;

 

    return (NPObject *)movieNPObject;

}

  ||

static void initializeIdentifiers(void)

{

    static bool identifiersInitialized;

    if (identifiersInitialized)

        return;

 

    // Take all method identifier names and convert them to NPIdentifiers.

    browser->getstringidentifiers(methodIdentifierNames, NUM_METHOD_IDENTIFIERS, methodIdentifiers);

    identifiersInitialized = true;

}

    ||

static NPIdentifier methodIdentifiers[NUM_METHOD_IDENTIFIERS];

static const NPUTF8 *methodIdentifierNames[NUM_METHOD_IDENTIFIERS] = {

    "play",

    "pause",

};

  ||

使用的地方:

movieNPObjectHasMethod{}

movieNPObjectInvoke{}

 

 

 

 

转载于:https://www.cnblogs.com/Miami/p/3315509.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值