]> git.sesse.net Git - vlc/blob - mozilla/control/npovlc.cpp
Qt4 - Audio/Video order fix in menus. Changes MediaInformation shortcut to Ctrl+I...
[vlc] / mozilla / control / npovlc.cpp
1 /*****************************************************************************\r
2  * npovlc.cpp: deprecated VLC apis implemented in late XPCOM interface\r
3  *****************************************************************************\r
4  * Copyright (C) 2002-2006 the VideoLAN team\r
5  *\r
6  * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>\r
7  *\r
8  * This program is free software; you can redistribute it and/or modify\r
9  * it under the terms of the GNU General Public License as published by\r
10  * the Free Software Foundation; either version 2 of the License, or\r
11  * (at your option) any later version.\r
12  *\r
13  * This program is distributed in the hope that it will be useful,\r
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
16  * GNU General Public License for more details.\r
17  *\r
18  * You should have received a copy of the GNU General Public License\r
19  * along with this program; if not, write to the Free Software\r
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.\r
21  *****************************************************************************/\r
22 \r
23 #include "config.h"\r
24 \r
25 #include <stdio.h>\r
26 #include <string.h>\r
27 #include <stdlib.h>\r
28 \r
29 #include <vlc/vlc.h>\r
30 \r
31 /* Mozilla stuff */\r
32 #ifdef HAVE_MOZILLA_CONFIG_H\r
33 #   include <mozilla-config.h>\r
34 #endif\r
35 \r
36 #include "npovlc.h"\r
37 #include "vlcplugin.h"\r
38 \r
39 /*\r
40 ** implementation of vlc root object\r
41 */\r
42 \r
43 const NPUTF8 * const VlcNPObject::propertyNames[] =\r
44 {\r
45     /* no properties */\r
46 };\r
47 \r
48 const int VlcNPObject::propertyCount = sizeof(VlcNPObject::propertyNames)/sizeof(NPUTF8 *);\r
49 \r
50 const NPUTF8 * const VlcNPObject::methodNames[] =\r
51 {\r
52     "play",                 /* deprecated */\r
53     "pause",                /* deprecated */\r
54     "stop",                 /* deprecated */\r
55     "fullscreen",           /* deprecated */\r
56     "set_volume",           /* deprecated */\r
57     "get_volume",           /* deprecated */\r
58     "mute",                 /* deprecated */\r
59     "get_int_variable",     /* deprecated */\r
60     "set_int_variable",     /* deprecated */\r
61     "get_bool_variable",    /* deprecated */\r
62     "set_bool_variable",    /* deprecated */\r
63     "get_str_variable",     /* deprecated */\r
64     "set_str_variable",     /* deprecated */\r
65     "clear_playlist",       /* deprecated */\r
66     "add_item",             /* deprecated */\r
67     "next",                 /* deprecated */\r
68     "previous",             /* deprecated */\r
69     "isplaying",            /* deprecated */\r
70     "get_length",           /* deprecated */\r
71     "get_position",         /* deprecated */\r
72     "get_time",             /* deprecated */\r
73     "seek",                 /* deprecated */\r
74 };\r
75 \r
76 enum VlcNPObjectMethodIds\r
77 {\r
78     ID_play = 0,\r
79     ID_pause,\r
80     ID_stop,\r
81     ID_fullscreen,\r
82     ID_set_volume,\r
83     ID_get_volume,\r
84     ID_mute,\r
85     ID_get_int_variable,\r
86     ID_set_int_variable,\r
87     ID_get_bool_variable,\r
88     ID_set_bool_variable,\r
89     ID_get_str_variable,\r
90     ID_set_str_variable,\r
91     ID_clear_playlist,\r
92     ID_add_item,\r
93     ID_next,\r
94     ID_previous,\r
95     ID_isplaying,\r
96     ID_get_length,\r
97     ID_get_position,\r
98     ID_get_time,\r
99     ID_seek,\r
100 };\r
101 \r
102 const int VlcNPObject::methodCount = sizeof(VlcNPObject::methodNames)/sizeof(NPUTF8 *);\r
103 \r
104 RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
105 {\r
106     VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
107     if( p_plugin )\r
108     {\r
109         libvlc_exception_t ex;\r
110         libvlc_exception_init(&ex);\r
111 \r
112         switch( index )\r
113         {\r
114             case ID_play: /* deprecated */\r
115                 if( argCount == 0 )\r
116                 {\r
117                     libvlc_playlist_play(p_plugin->getVLC(), -1, 0, NULL, &ex);\r
118                     if( libvlc_exception_raised(&ex) )\r
119                     {\r
120                         NPN_SetException(this, libvlc_exception_get_message(&ex));\r
121                         libvlc_exception_clear(&ex);\r
122                         return INVOKERESULT_GENERIC_ERROR;\r
123                     }\r
124                     else\r
125                     {\r
126                         VOID_TO_NPVARIANT(result);\r
127                         return INVOKERESULT_NO_ERROR;\r
128                     }\r
129                 }\r
130                 return INVOKERESULT_NO_SUCH_METHOD;\r
131             case ID_pause: /* deprecated */\r
132                 if( argCount == 0 )\r
133                 {\r
134                     libvlc_playlist_pause(p_plugin->getVLC(), &ex);\r
135                     if( libvlc_exception_raised(&ex) )\r
136                     {\r
137                         NPN_SetException(this, libvlc_exception_get_message(&ex));\r
138                         libvlc_exception_clear(&ex);\r
139                         return INVOKERESULT_GENERIC_ERROR;\r
140                     }\r
141                     else\r
142                     {\r
143                         VOID_TO_NPVARIANT(result);\r
144                         return INVOKERESULT_NO_ERROR;\r
145                     }\r
146                 }\r
147                 return INVOKERESULT_NO_SUCH_METHOD;\r
148             case ID_stop: /* deprecated */\r
149                 if( argCount == 0 )\r
150                 {\r
151                     libvlc_playlist_stop(p_plugin->getVLC(), &ex);\r
152                     if( libvlc_exception_raised(&ex) )\r
153                     {\r
154                         NPN_SetException(this, libvlc_exception_get_message(&ex));\r
155                         libvlc_exception_clear(&ex);\r
156                         return INVOKERESULT_GENERIC_ERROR;\r
157                     }\r
158                     else\r
159                     {\r
160                         VOID_TO_NPVARIANT(result);\r
161                         return INVOKERESULT_NO_ERROR;\r
162                     }\r
163                 }\r
164                 return INVOKERESULT_NO_SUCH_METHOD;\r
165             case ID_fullscreen: /* deprecated */\r
166                 if( argCount == 0 )\r
167                 {\r
168                     libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_plugin->getVLC(), &ex);\r
169                     if( p_md )\r
170                     {\r
171                         libvlc_toggle_fullscreen(p_md, &ex);\r
172                         libvlc_media_instance_release(p_md);\r
173                         if( libvlc_exception_raised(&ex) )\r
174                         {\r
175                             NPN_SetException(this, libvlc_exception_get_message(&ex));\r
176                             libvlc_exception_clear(&ex);\r
177                             return INVOKERESULT_GENERIC_ERROR;\r
178                         }\r
179                         else\r
180                         {\r
181                             VOID_TO_NPVARIANT(result);\r
182                             return INVOKERESULT_NO_ERROR;\r
183                         }\r
184                     }\r
185                     else\r
186                     {\r
187                         /* cannot get input, probably not playing */\r
188                         if( libvlc_exception_raised(&ex) )\r
189                         {\r
190                             NPN_SetException(this, libvlc_exception_get_message(&ex));\r
191                             libvlc_exception_clear(&ex);\r
192                         }\r
193                         return INVOKERESULT_GENERIC_ERROR;\r
194                     }\r
195                 }\r
196                 return INVOKERESULT_NO_SUCH_METHOD;\r
197             case ID_set_volume: /* deprecated */\r
198                 if( (argCount == 1) && isNumberValue(args[0]) )\r
199                 {\r
200                     libvlc_audio_set_volume(p_plugin->getVLC(), numberValue(args[0]), &ex);\r
201                     if( libvlc_exception_raised(&ex) )\r
202                     {\r
203                         NPN_SetException(this, libvlc_exception_get_message(&ex));\r
204                         libvlc_exception_clear(&ex);\r
205                         return INVOKERESULT_GENERIC_ERROR;\r
206                     }\r
207                     else\r
208                     {\r
209                         VOID_TO_NPVARIANT(result);\r
210                         return INVOKERESULT_NO_ERROR;\r
211                     }\r
212                 }\r
213                 return INVOKERESULT_NO_SUCH_METHOD;\r
214             case ID_get_volume: /* deprecated */\r
215                 if( argCount == 0 )\r
216                 {\r
217                     int val = libvlc_audio_get_volume(p_plugin->getVLC(), &ex);\r
218                     if( libvlc_exception_raised(&ex) )\r
219                     {\r
220                         NPN_SetException(this, libvlc_exception_get_message(&ex));\r
221                         libvlc_exception_clear(&ex);\r
222                         return INVOKERESULT_GENERIC_ERROR;\r
223                     }\r
224                     else\r
225                     {\r
226                         INT32_TO_NPVARIANT(val, result);\r
227                         return INVOKERESULT_NO_ERROR;\r
228                     }\r
229                 }\r
230                 return INVOKERESULT_NO_SUCH_METHOD;\r
231             case ID_mute: /* deprecated */\r
232                 if( argCount == 0 )\r
233                 {\r
234                     libvlc_audio_toggle_mute(p_plugin->getVLC(), &ex);\r
235                     if( libvlc_exception_raised(&ex) )\r
236                     {\r
237                         NPN_SetException(this, libvlc_exception_get_message(&ex));\r
238                         libvlc_exception_clear(&ex);\r
239                         return INVOKERESULT_GENERIC_ERROR;\r
240                     }\r
241                     else\r
242                     {\r
243                         VOID_TO_NPVARIANT(result);\r
244                         return INVOKERESULT_NO_ERROR;\r
245                     }\r
246                 }\r
247                 return INVOKERESULT_NO_SUCH_METHOD;\r
248             case ID_get_int_variable: /* deprecated */\r
249                 if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) )\r
250                 {\r
251                     char *s = stringValue(NPVARIANT_TO_STRING(args[0]));\r
252                     if( s )\r
253                     {\r
254                         int vlc_id = libvlc_get_vlc_id(p_plugin->getVLC());\r
255                         vlc_value_t val;\r
256                         if( VLC_SUCCESS == VLC_VariableGet(vlc_id, s, &val) )\r
257                         {\r
258                             delete s;\r
259                             INT32_TO_NPVARIANT(val.i_int, result);\r
260                             return INVOKERESULT_NO_ERROR;\r
261                         }\r
262                         else\r
263                         {\r
264                             delete s;\r
265                             return INVOKERESULT_INVALID_ARGS;\r
266                         }\r
267                     }\r
268                     else\r
269                         return INVOKERESULT_OUT_OF_MEMORY;\r
270                 }\r
271                 return INVOKERESULT_NO_SUCH_METHOD;\r
272             case ID_set_int_variable: /* deprecated */\r
273                 if( (argCount == 2)\r
274                     && NPVARIANT_IS_STRING(args[0])\r
275                     && isNumberValue(args[1]) )\r
276                 {\r
277                     char *s = stringValue(NPVARIANT_TO_STRING(args[0]));\r
278                     if( s )\r
279                     {\r
280                         int vlc_id = libvlc_get_vlc_id(p_plugin->getVLC());\r
281                         vlc_value_t val;\r
282                         val.i_int = numberValue(args[1]);\r
283                         if( VLC_SUCCESS == VLC_VariableSet(vlc_id, s, val) )\r
284                         {\r
285                             delete s;\r
286                             VOID_TO_NPVARIANT(result);\r
287                             return INVOKERESULT_NO_ERROR;\r
288                         }\r
289                         else\r
290                         {\r
291                             delete s;\r
292                             return INVOKERESULT_INVALID_ARGS;\r
293                         }\r
294                     }\r
295                     else\r
296                         return INVOKERESULT_OUT_OF_MEMORY;\r
297                 }\r
298                 return INVOKERESULT_NO_SUCH_METHOD;\r
299             case ID_get_bool_variable: /* deprecated */\r
300                 if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) )\r
301                 {\r
302                     char *s = stringValue(NPVARIANT_TO_STRING(args[0]));\r
303                     if( s )\r
304                     {\r
305                         int vlc_id = libvlc_get_vlc_id(p_plugin->getVLC());\r
306                         vlc_value_t val;\r
307                         if( VLC_SUCCESS == VLC_VariableGet(vlc_id, s, &val) )\r
308                         {\r
309                             delete s;\r
310                             BOOLEAN_TO_NPVARIANT(val.b_bool, result);\r
311                             return INVOKERESULT_NO_ERROR;\r
312                         }\r
313                         else\r
314                         {\r
315                             delete s;\r
316                             return INVOKERESULT_INVALID_ARGS;\r
317                         }\r
318                     }\r
319                     else\r
320                         return INVOKERESULT_OUT_OF_MEMORY;\r
321                 }\r
322                 return INVOKERESULT_NO_SUCH_METHOD;\r
323             case ID_set_bool_variable: /* deprecated */\r
324                 if( (argCount == 2)\r
325                     && NPVARIANT_IS_STRING(args[0])\r
326                     && NPVARIANT_IS_BOOLEAN(args[1]) )\r
327                 {\r
328                     char *s = stringValue(NPVARIANT_TO_STRING(args[0]));\r
329                     if( s )\r
330                     {\r
331                         int vlc_id = libvlc_get_vlc_id(p_plugin->getVLC());\r
332                         vlc_value_t val;\r
333                         val.b_bool = NPVARIANT_TO_BOOLEAN(args[1]);\r
334                         if( VLC_SUCCESS == VLC_VariableSet(vlc_id, s, val) )\r
335                         {\r
336                             delete s;\r
337                             VOID_TO_NPVARIANT(result);\r
338                             return INVOKERESULT_NO_ERROR;\r
339                         }\r
340                         else\r
341                         {\r
342                             delete s;\r
343                             return INVOKERESULT_INVALID_ARGS;\r
344                         }\r
345                     }\r
346                     else\r
347                         return INVOKERESULT_OUT_OF_MEMORY;\r
348                 }\r
349                 return INVOKERESULT_NO_SUCH_METHOD;\r
350             case ID_get_str_variable: /* deprecated */\r
351                 if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) )\r
352                 {\r
353                     char *s = stringValue(NPVARIANT_TO_STRING(args[0]));\r
354                     if( s )\r
355                     {\r
356                         int vlc_id = libvlc_get_vlc_id(p_plugin->getVLC());\r
357                         vlc_value_t val;\r
358                         if( VLC_SUCCESS == VLC_VariableGet(vlc_id, s, &val) )\r
359                         {\r
360                             delete s;\r
361                             if( val.psz_string )\r
362                             {\r
363                                 int len = strlen(val.psz_string);\r
364                                 NPUTF8 *retval = (NPUTF8 *)NPN_MemAlloc(len);\r
365                                 if( retval )\r
366                                 {\r
367                                     memcpy(retval, val.psz_string, len);\r
368                                     STRINGN_TO_NPVARIANT(retval, len, result);\r
369                                     free(val.psz_string);\r
370                                     return INVOKERESULT_NO_ERROR;\r
371                                 }\r
372                                 else\r
373                                 {\r
374                                     return INVOKERESULT_OUT_OF_MEMORY;\r
375                                 }\r
376                             }\r
377                             else\r
378                             {\r
379                                 /* null string */\r
380                                 NULL_TO_NPVARIANT(result);\r
381                                 return INVOKERESULT_NO_ERROR;\r
382                             }\r
383                         }\r
384                         else\r
385                         {\r
386                             delete s;\r
387                             return INVOKERESULT_INVALID_ARGS;\r
388                         }\r
389                     }\r
390                     else\r
391                         return INVOKERESULT_OUT_OF_MEMORY;\r
392                 }\r
393                 return INVOKERESULT_NO_SUCH_METHOD;\r
394             case ID_set_str_variable: /* deprecated */\r
395                 if( (argCount == 2)\r
396                     && NPVARIANT_IS_STRING(args[0])\r
397                     && NPVARIANT_IS_STRING(args[1]) )\r
398                 {\r
399                     char *s = stringValue(NPVARIANT_TO_STRING(args[0]));\r
400                     if( s )\r
401                     {\r
402                         int vlc_id = libvlc_get_vlc_id(p_plugin->getVLC());\r
403                         vlc_value_t val;\r
404                         val.psz_string = stringValue(NPVARIANT_TO_STRING(args[1]));\r
405                         if( val.psz_string )\r
406                         {\r
407                             if( VLC_SUCCESS == VLC_VariableSet(vlc_id, s, val) )\r
408                             {\r
409                                 delete s;\r
410                                 delete val.psz_string;\r
411                                 VOID_TO_NPVARIANT(result);\r
412                                 return INVOKERESULT_NO_ERROR;\r
413                             }\r
414                             else\r
415                             {\r
416                                 delete s;\r
417                                 delete val.psz_string;\r
418                                 return INVOKERESULT_INVALID_ARGS;\r
419                             }\r
420                         }\r
421                         else\r
422                         {\r
423                             delete s;\r
424                             return INVOKERESULT_OUT_OF_MEMORY;\r
425                         }\r
426                     }\r
427                     else\r
428                         return INVOKERESULT_OUT_OF_MEMORY;\r
429                 }\r
430                 return INVOKERESULT_NO_SUCH_METHOD;\r
431             case ID_clear_playlist: /* deprecated */\r
432                 if( argCount == 0 )\r
433                 {\r
434                     libvlc_playlist_clear(p_plugin->getVLC(), &ex);\r
435                     if( libvlc_exception_raised(&ex) )\r
436                     {\r
437                         NPN_SetException(this, libvlc_exception_get_message(&ex));\r
438                         libvlc_exception_clear(&ex);\r
439                         return INVOKERESULT_GENERIC_ERROR;\r
440                     }\r
441                     else\r
442                     {\r
443                         VOID_TO_NPVARIANT(result);\r
444                         return INVOKERESULT_NO_ERROR;\r
445                     }\r
446                 }\r
447                 return INVOKERESULT_NO_SUCH_METHOD;\r
448             case ID_add_item: /* deprecated */\r
449                 if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) )\r
450                 {\r
451                     char *s = stringValue(NPVARIANT_TO_STRING(args[0]));\r
452                     if( s )\r
453                     {\r
454                         char *url = p_plugin->getAbsoluteURL(s);\r
455                         delete s;\r
456                         if( ! url )\r
457                             // what happened ?\r
458                             return INVOKERESULT_GENERIC_ERROR;\r
459                              \r
460                         int item = libvlc_playlist_add(p_plugin->getVLC(), url, NULL, &ex);\r
461                         free(url);\r
462                         if( libvlc_exception_raised(&ex) )\r
463                         {\r
464                             NPN_SetException(this, libvlc_exception_get_message(&ex));\r
465                             libvlc_exception_clear(&ex);\r
466                             return INVOKERESULT_GENERIC_ERROR;\r
467                         }\r
468                         else\r
469                         {\r
470                             INT32_TO_NPVARIANT(item, result);\r
471                             return INVOKERESULT_NO_ERROR;\r
472                         }\r
473                     }\r
474                     else\r
475                         return INVOKERESULT_OUT_OF_MEMORY;\r
476                 }\r
477                 return INVOKERESULT_NO_SUCH_METHOD;\r
478             case ID_next: /* deprecated */\r
479                 if( argCount == 0 )\r
480                 {\r
481                     libvlc_playlist_next(p_plugin->getVLC(), &ex);\r
482                     if( libvlc_exception_raised(&ex) )\r
483                     {\r
484                         NPN_SetException(this, libvlc_exception_get_message(&ex));\r
485                         libvlc_exception_clear(&ex);\r
486                         return INVOKERESULT_GENERIC_ERROR;\r
487                     }\r
488                     else\r
489                     {\r
490                         VOID_TO_NPVARIANT(result);\r
491                         return INVOKERESULT_NO_ERROR;\r
492                     }\r
493                 }\r
494                 return INVOKERESULT_NO_SUCH_METHOD;\r
495             case ID_previous: /* deprecated */\r
496                 if( argCount == 0 )\r
497                 {\r
498                     libvlc_playlist_prev(p_plugin->getVLC(), &ex);\r
499                     if( libvlc_exception_raised(&ex) )\r
500                     {\r
501                         NPN_SetException(this, libvlc_exception_get_message(&ex));\r
502                         libvlc_exception_clear(&ex);\r
503                         return INVOKERESULT_GENERIC_ERROR;\r
504                     }\r
505                     else\r
506                     {\r
507                         VOID_TO_NPVARIANT(result);\r
508                         return INVOKERESULT_NO_ERROR;\r
509                     }\r
510                 }\r
511                 return INVOKERESULT_NO_SUCH_METHOD;\r
512             case ID_isplaying: /* deprecated */\r
513                 if( argCount == 0 )\r
514                 {\r
515                     int isplaying = libvlc_playlist_isplaying(p_plugin->getVLC(), &ex);\r
516                     if( libvlc_exception_raised(&ex) )\r
517                     {\r
518                         NPN_SetException(this, libvlc_exception_get_message(&ex));\r
519                         libvlc_exception_clear(&ex);\r
520                         return INVOKERESULT_GENERIC_ERROR;\r
521                     }\r
522                     else\r
523                     {\r
524                         BOOLEAN_TO_NPVARIANT(isplaying, result);\r
525                         return INVOKERESULT_NO_ERROR;\r
526                     }\r
527                 }\r
528                 return INVOKERESULT_NO_SUCH_METHOD;\r
529             case ID_get_length: /* deprecated */\r
530                 if( argCount == 0 )\r
531                 {\r
532                     libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_plugin->getVLC(), &ex);\r
533                     if( p_md )\r
534                     {\r
535                         vlc_int64_t val = libvlc_media_instance_get_length(p_md, &ex);\r
536                         libvlc_media_instance_release(p_md);\r
537                         if( libvlc_exception_raised(&ex) )\r
538                         {\r
539                             NPN_SetException(this, libvlc_exception_get_message(&ex));\r
540                             libvlc_exception_clear(&ex);\r
541                             return INVOKERESULT_GENERIC_ERROR;\r
542                         }\r
543                         else\r
544                         {\r
545                             INT32_TO_NPVARIANT((uint32_t)(val/1000LL), result);\r
546                             return INVOKERESULT_NO_ERROR;\r
547                         }\r
548                     }\r
549                     else\r
550                     {\r
551                         /* cannot get input, probably not playing */\r
552                         if( libvlc_exception_raised(&ex) )\r
553                         {\r
554                             NPN_SetException(this, libvlc_exception_get_message(&ex));\r
555                             libvlc_exception_clear(&ex);\r
556                         }\r
557                         return INVOKERESULT_GENERIC_ERROR;\r
558                     }\r
559                 }\r
560                 return INVOKERESULT_NO_SUCH_METHOD;\r
561             case ID_get_position: /* deprecated */\r
562                 if( argCount == 0 )\r
563                 {\r
564                     libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_plugin->getVLC(), &ex);\r
565                     if( p_md )\r
566                     {\r
567                         float val = libvlc_media_instance_get_position(p_md, &ex);\r
568                         libvlc_media_instance_release(p_md);\r
569                         if( libvlc_exception_raised(&ex) )\r
570                         {\r
571                             NPN_SetException(this, libvlc_exception_get_message(&ex));\r
572                             libvlc_exception_clear(&ex);\r
573                             return INVOKERESULT_GENERIC_ERROR;\r
574                         }\r
575                         else\r
576                         {\r
577                             DOUBLE_TO_NPVARIANT((double)val, result);\r
578                             return INVOKERESULT_NO_ERROR;\r
579                         }\r
580                     }\r
581                     else\r
582                     {\r
583                         /* cannot get input, probably not playing */\r
584                         if( libvlc_exception_raised(&ex) )\r
585                         {\r
586                             NPN_SetException(this, libvlc_exception_get_message(&ex));\r
587                             libvlc_exception_clear(&ex);\r
588                         }\r
589                         return INVOKERESULT_GENERIC_ERROR;\r
590                     }\r
591                 }\r
592                 return INVOKERESULT_NO_SUCH_METHOD;\r
593             case ID_get_time: /* deprecated */\r
594                 if( argCount == 0 )\r
595                 {\r
596                     libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_plugin->getVLC(), &ex);\r
597                     if( p_md )\r
598                     {\r
599                         vlc_int64_t val = libvlc_media_instance_get_time(p_md, &ex);\r
600                         libvlc_media_instance_release(p_md);\r
601                         if( libvlc_exception_raised(&ex) )\r
602                         {\r
603                             NPN_SetException(this, libvlc_exception_get_message(&ex));\r
604                             libvlc_exception_clear(&ex);\r
605                             return INVOKERESULT_GENERIC_ERROR;\r
606                         }\r
607                         else\r
608                         {\r
609                             DOUBLE_TO_NPVARIANT((uint32_t)(val/1000LL), result);\r
610                             return INVOKERESULT_NO_ERROR;\r
611                         }\r
612                     }\r
613                     else\r
614                     {\r
615                         /* cannot get input, probably not playing */\r
616                         if( libvlc_exception_raised(&ex) )\r
617                         {\r
618                             NPN_SetException(this, libvlc_exception_get_message(&ex));\r
619                             libvlc_exception_clear(&ex);\r
620                         }\r
621                         return INVOKERESULT_GENERIC_ERROR;\r
622                     }\r
623                 }\r
624                 return INVOKERESULT_NO_SUCH_METHOD;\r
625             case ID_seek: /* deprecated */\r
626                 if( (argCount == 2)\r
627                   && isNumberValue(args[0])\r
628                   && NPVARIANT_IS_BOOLEAN(args[1]) )\r
629                 {\r
630                     libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(p_plugin->getVLC(), &ex);\r
631                     if( p_md )\r
632                     {\r
633                         vlc_int64_t pos = 0;\r
634                         if( NPVARIANT_IS_INT32(args[0]) )\r
635                             pos = (vlc_int64_t)NPVARIANT_TO_INT32(args[0]);\r
636                         else\r
637                             pos = (vlc_int64_t)NPVARIANT_TO_DOUBLE(args[0]);\r
638 \r
639                         if( NPVARIANT_TO_BOOLEAN(args[1]) )\r
640                         {\r
641                             /* relative seek */\r
642                             vlc_int64_t from = libvlc_media_instance_get_time(p_md, &ex);\r
643                             if( libvlc_exception_raised(&ex) )\r
644                             {\r
645                                 libvlc_media_instance_release(p_md);\r
646                                 NPN_SetException(this, libvlc_exception_get_message(&ex));\r
647                                 libvlc_exception_clear(&ex);\r
648                                 return INVOKERESULT_GENERIC_ERROR;\r
649                             }\r
650                             pos += from;\r
651                         }\r
652                         /* jump to time */\r
653                         libvlc_media_instance_set_time(p_md, pos, &ex);\r
654                         libvlc_media_instance_release(p_md);\r
655                         if( libvlc_exception_raised(&ex) )\r
656                         {\r
657                             NPN_SetException(this, libvlc_exception_get_message(&ex));\r
658                             libvlc_exception_clear(&ex);\r
659                             return INVOKERESULT_GENERIC_ERROR;\r
660                         }\r
661                         VOID_TO_NPVARIANT(result);\r
662                         return INVOKERESULT_NO_ERROR;\r
663                     }\r
664                     else\r
665                     {\r
666                         /* cannot get input, probably not playing */\r
667                         if( libvlc_exception_raised(&ex) )\r
668                         {\r
669                             NPN_SetException(this, libvlc_exception_get_message(&ex));\r
670                             libvlc_exception_clear(&ex);\r
671                         }\r
672                         return INVOKERESULT_GENERIC_ERROR;\r
673                     }\r
674                 }\r
675                 return INVOKERESULT_NO_SUCH_METHOD;\r
676             default:\r
677                 return INVOKERESULT_NO_SUCH_METHOD;\r
678         }\r
679     }\r
680     return INVOKERESULT_GENERIC_ERROR;\r
681 }\r
682 \r