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{}