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