Hi all,
In case of interrest for someone, I've made a very little improvement to the mozilla plugin by adding ability to load playlist throught javascript.
Tell me if you are interrested by source code.
Code: Select all
/**BM
* Load a playlist file.
* \param p_instance the instance
* \param psz_filename the file to be loaded
* \param p_exception an initialized exception
* \return
*/
int libvlc_playlist_load( libvlc_instance_t *, const char *,
libvlc_exception_t * );
/** @}*/
Code: Select all
/**BM
* Load a playlist file.
* \param p_instance the instance
* \param psz_filename the file to be loaded
* \param p_exception an initialized exception
* \return
*/
int libvlc_playlist_load( libvlc_instance_t *p_instance, const char *psz_filename,
libvlc_exception_t *p_e )
{
assert( p_instance->p_playlist );
return playlist_Import( p_instance->p_playlist, psz_filename );
}
Code: Select all
const NPUTF8 * const LibvlcPlaylistNPObject::methodNames[] =
{
"add",
"play",
"playItem",
"togglePause",
"stop",
"next",
"prev",
"clear", /* deprecated */
"removeItem", /* deprecated */
"load",/*BM : ajout chargement playlist*/
};
Code: Select all
enum LibvlcPlaylistNPObjectMethodIds
{
ID_playlist_add,
ID_playlist_play,
ID_playlist_playItem,
ID_playlist_togglepause,
ID_playlist_stop,
ID_playlist_next,
ID_playlist_prev,
ID_playlist_clear,
ID_playlist_removeitem,
ID_playlist_load,/*BM : ajout chargement playlist*/
};
Code: Select all
RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
{
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
if( p_plugin )
{
libvlc_exception_t ex;
libvlc_exception_init(&ex);
switch( index )
{
case ID_playlist_add:
{
if( (argCount < 1) || (argCount > 3) )
return INVOKERESULT_NO_SUCH_METHOD;
char *url = NULL;
// grab URL
if( NPVARIANT_IS_STRING(args[0]) )
{
char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
if( s )
{
url = p_plugin->getAbsoluteURL(s);
if( url )
delete s;
else
// problem with combining url, use argument
url = s;
}
else
return INVOKERESULT_OUT_OF_MEMORY;
}
else
return INVOKERESULT_NO_SUCH_METHOD;
char *name = NULL;
// grab name if available
if( argCount > 1 )
{
if( NPVARIANT_IS_NULL(args[1]) )
{
// do nothing
}
else if( NPVARIANT_IS_STRING(args[1]) )
{
name = stringValue(NPVARIANT_TO_STRING(args[0]));
}
else
return INVOKERESULT_NO_SUCH_METHOD;
}
int i_options = 0;
char** ppsz_options = NULL;
// grab options if available
if( argCount > 2 )
{
if( NPVARIANT_IS_NULL(args[2]) )
{
// do nothing
}
else if( NPVARIANT_IS_STRING(args[2]) )
{
parseOptions(NPVARIANT_TO_STRING(args[2]), &i_options, &ppsz_options);
}
else if( NPVARIANT_IS_OBJECT(args[2]) )
{
parseOptions(NPVARIANT_TO_OBJECT(args[2]), &i_options, &ppsz_options);
}
}
int item = libvlc_playlist_add_extended(p_plugin->getVLC(),
url,
name,
i_options,
const_cast<const char **>(ppsz_options),
&ex);
delete url;
delete name;
for( int i=0; i< i_options; ++i )
{
if( ppsz_options[i] )
free(ppsz_options[i]);
}
if( ppsz_options )
free(ppsz_options);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
else
{
INT32_TO_NPVARIANT(item, result);
return INVOKERESULT_NO_ERROR;
}
}
case ID_playlist_play:
if( argCount == 0 )
{
libvlc_playlist_play(p_plugin->getVLC(), -1, 0, NULL, &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
else
{
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
return INVOKERESULT_NO_SUCH_METHOD;
case ID_playlist_playItem:
if( (argCount == 1) && isNumberValue(args[0]) )
{
libvlc_playlist_play(p_plugin->getVLC(), numberValue(args[0]), 0, NULL, &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
else
{
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
return INVOKERESULT_NO_SUCH_METHOD;
case ID_playlist_togglepause:
if( argCount == 0 )
{
libvlc_playlist_pause(p_plugin->getVLC(), &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
else
{
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
return INVOKERESULT_NO_SUCH_METHOD;
case ID_playlist_stop:
if( argCount == 0 )
{
libvlc_playlist_stop(p_plugin->getVLC(), &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
else
{
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
return INVOKERESULT_NO_SUCH_METHOD;
case ID_playlist_next:
if( argCount == 0 )
{
libvlc_playlist_next(p_plugin->getVLC(), &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
else
{
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
return INVOKERESULT_NO_SUCH_METHOD;
case ID_playlist_prev:
if( argCount == 0 )
{
libvlc_playlist_prev(p_plugin->getVLC(), &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
else
{
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
return INVOKERESULT_NO_SUCH_METHOD;
case ID_playlist_clear: /* deprecated */
if( argCount == 0 )
{
libvlc_playlist_clear(p_plugin->getVLC(), &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
else
{
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
return INVOKERESULT_NO_SUCH_METHOD;
case ID_playlist_removeitem: /* deprecated */
if( (argCount == 1) && isNumberValue(args[0]) )
{
libvlc_playlist_delete_item(p_plugin->getVLC(), numberValue(args[0]), &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
else
{
VOID_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR;
}
}
return INVOKERESULT_NO_SUCH_METHOD;
case ID_playlist_load:/* BM Ajout méthode chargement playlist */
{
if(argCount != 1)
return INVOKERESULT_NO_SUCH_METHOD;
char *filename = NULL;
// grab file name
if( NPVARIANT_IS_STRING(args[0]) )
{
/*
char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
if( s )
{
filename = p_plugin->getAbsoluteURL(s);
if( filename )
delete s;
else
// problem with combining url, use argument
filename = s;
}
*/
filename = stringValue(NPVARIANT_TO_STRING(args[0]));
if(!filename) return INVOKERESULT_OUT_OF_MEMORY;
}
else
return INVOKERESULT_NO_SUCH_METHOD;
//Chargement playlist
int res=libvlc_playlist_load(p_plugin->getVLC(),filename,&ex);
delete filename;
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
else
{
INT32_TO_NPVARIANT(res, result);
return INVOKERESULT_NO_ERROR;
}
}
default:
;
}
}
return INVOKERESULT_GENERIC_ERROR;
}
Users browsing this forum: No registered users and 70 guests