mozilla plugin "load playlist"

All you've ever wanted to know about the ActiveX, Mozilla plugins, the web interface and various PHP extensions
makko
New Cone
New Cone
Posts: 5
Joined: 19 Jan 2007 13:15
Location: France

mozilla plugin "load playlist"

Postby makko » 19 Jan 2007 13:22

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.

Allclone
New Cone
New Cone
Posts: 9
Joined: 13 Nov 2005 22:59
Location: Kazoo
Contact:

Postby Allclone » 22 Jan 2007 08:35

I would be Interested as it would be an interesting thing to use as a pre-loaded content setup.

Spellcoder
Blank Cone
Blank Cone
Posts: 57
Joined: 19 Apr 2006 12:21
Location: Hengelo // The Netherlands
Contact:

Postby Spellcoder » 22 Jan 2007 12:41

Where does it save the playlist?
On a server, in a cookie or client-side session?

makko
New Cone
New Cone
Posts: 5
Joined: 19 Jan 2007 13:15
Location: France

Code

Postby makko » 23 Jan 2007 09:16

Here come the code addons to the 0.8a svn version.

/include/libvlc.h (to be added)

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 * ); /** @}*/


/src/control/playlist.c (to be added)

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 ); }
/mozilla/control/npolibvlc.cpp (sections to be replaced)

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; }
After compiling as usual, the playlist object handles a new "load" method.
Be careful as the first itemID to be played is 6. I don't know why. May be some VLC's guru could explain this.

Quovodis
Cone that earned his stripes
Cone that earned his stripes
Posts: 271
Joined: 16 Jun 2004 11:13
Location: Cork, Ireland

Postby Quovodis » 28 Jan 2007 19:51

hmmm, i don't know how useful this addition is as you can already load a playlist using the add(MRL) methods


Return to “Web and scripting”

Who is online

Users browsing this forum: No registered users and 8 guests