1
mirror of https://code.videolan.org/videolan/vlc synced 2024-10-11 06:21:30 +02:00

Play and add (Refs:#457)

This commit is contained in:
Clément Stenac 2006-02-03 19:53:47 +00:00
parent 6df78501b9
commit 661a6c1357
6 changed files with 146 additions and 14 deletions

View File

@ -67,8 +67,21 @@ void libvlc_exception_init( libvlc_exception_t *p_exception );
* \return 0 if no exception raised, 1 else
*/
int libvlc_exception_raised( libvlc_exception_t *p_exception );
/**
* Raise an exception
* \param p_exception the exception to raise
* \param psz_message the exception message
*/
void libvlc_exception_raise( libvlc_exception_t *p_exception, char *psz_message );
/**
* Clear an exception object so it can be reused.
* The exception object must be initialized
* \param p_exception the exception to clear
*/
void libvlc_exception_clear( libvlc_exception_t * );
/**
* Get exception message
* \param p_exception the exception to query
@ -123,11 +136,13 @@ void libvlc_destroy( libvlc_instance_t *);
* Start playing. You can give some additionnal playlist item options
* that will be added to the item before playing it.
* \param p_instance the instance
* \param i_id the item to play. If this is a negative number, the next
* item will be selected. Else, the item with the given ID will be played
* \param i_options the number of options to add to the item
* \param ppsz_options the options to add to the item
* \param p_exception an initialized exception
*/
void libvlc_playlist_play( libvlc_instance_t*, int, char **,
void libvlc_playlist_play( libvlc_instance_t*, int, int, char **,
libvlc_exception_t * );
/**
@ -158,6 +173,29 @@ void libvlc_playlist_next( libvlc_instance_t *, libvlc_exception_t * );
*/
void libvlc_playlist_prev( libvlc_instance_t *, libvlc_exception_t * );
/**
* Add an item at the end of the playlist
* If you need more advanced options, \see libvlc_playlist_add_extended
* \param p_instance the instance
* \param psz_uri the URI to open, using VLC format
* \param psz_name a name that you might want to give or NULL
* \return the identifier of the new item
*/
int libvlc_playlist_add( libvlc_instance_t *, const char *, const char *,
libvlc_exception_t * );
/**
* Add an item at the end of the playlist, with additional input options
* \param p_instance the instance
* \param psz_uri the URI to open, using VLC format
* \param psz_name a name that you might want to give or NULL
* \param i_options the number of options to add
* \param ppsz_options strings representing the options to add
* \return the identifier of the new item
*/
int libvlc_playlist_add_extended( libvlc_instance_t *, const char *,
const char *, int, const char **,
libvlc_exception_t * );

View File

@ -35,6 +35,13 @@ inline void libvlc_exception_init( libvlc_exception_t *p_exception )
p_exception->psz_message = NULL;
}
void libvlc_exception_clear( libvlc_exception_t *p_exception )
{
if( p_exception->psz_message )
free( p_exception->psz_message );
p_exception->b_raised = 0;
}
inline int libvlc_exception_raised( libvlc_exception_t *p_exception )
{
return p_exception->b_raised;
@ -58,7 +65,6 @@ inline void libvlc_exception_raise( libvlc_exception_t *p_exception,
p_exception->psz_message = strdup( psz_message );
}
libvlc_instance_t * libvlc_new( int argc, char **argv,
libvlc_exception_t *p_exception )
{

View File

@ -26,7 +26,7 @@
#include <vlc/intf.h>
void libvlc_playlist_play( libvlc_instance_t *p_instance,
void libvlc_playlist_play( libvlc_instance_t *p_instance, int i_id,
int i_options, char **ppsz_options,
libvlc_exception_t *p_exception )
{
@ -37,7 +37,42 @@ void libvlc_playlist_play( libvlc_instance_t *p_instance,
libvlc_exception_raise( p_exception, "Empty playlist" );
return;
}
playlist_Play( p_instance->p_playlist );
if( i_id >= 0 )
{
/* Always use the current view when using libvlc */
playlist_view_t *p_view;
playlist_item_t *p_item;
if( p_instance->p_playlist->status.i_view == -1 )
{
playlist_Control( p_instance->p_playlist, PLAYLIST_GOTO,
i_id );
}
p_view = playlist_ViewFind( p_instance->p_playlist,
p_instance->p_playlist->status.i_view );
if( !p_view )
{
libvlc_exception_raise( p_exception,
"Unable to find current playlist view ");
return;
}
p_item = playlist_ItemGetById( p_instance->p_playlist, i_id );
if( !p_item )
{
libvlc_exception_raise( p_exception, "Unable to find item " );
return;
}
playlist_Control( p_instance->p_playlist, PLAYLIST_VIEWPLAY,
p_instance->p_playlist->status.i_view,
p_view->p_root, p_item );
}
else
{
playlist_Play( p_instance->p_playlist );
}
}
void libvlc_playlist_stop( libvlc_instance_t *p_instance,
@ -55,6 +90,24 @@ void libvlc_playlist_clear( libvlc_instance_t *p_instance,
playlist_Clear( p_instance->p_playlist );
}
int libvlc_playlist_add( libvlc_instance_t *p_instance, const char *psz_uri,
const char *psz_name, libvlc_exception_t *p_exception )
{
return libvlc_playlist_add_extended( p_instance, psz_uri, psz_name,
0, NULL, p_exception );
}
int libvlc_playlist_add_extended( libvlc_instance_t *p_instance,
const char *psz_uri, const char *psz_name,
int i_options, const char **ppsz_options,
libvlc_exception_t *p_exception )
{
return playlist_AddExt( p_instance->p_playlist, psz_uri, psz_name,
PLAYLIST_INSERT, PLAYLIST_END, -1, ppsz_options,
i_options );
}
libvlc_input_t * libvlc_playlist_get_input( libvlc_instance_t *p_instance,
libvlc_exception_t *p_exception )

View File

@ -10,3 +10,6 @@ class NativeLibvlcTestCase( unittest.TestCase ):
def testStartup( self ):
"""Checks creation/destroy of libvlc"""
native_libvlc_test.create_destroy()
def testPlaylist( self ):
"""Checks basic playlist interaction"""
native_libvlc_test.playlist_test()

View File

@ -23,28 +23,56 @@ static PyObject *exception_test( PyObject *self, PyObject *args )
static PyObject *create_destroy( PyObject *self, PyObject *args )
{
libvlc_instance_t *p_instance;
char *argv[] = {};
libvlc_instance_t *p_instance;
char *argv[] = { "vlc", "--quiet" };
libvlc_exception_t exception;
libvlc_exception_init( &exception );
libvlc_exception_t exception;
libvlc_exception_init( &exception );
p_instance = libvlc_new( 0, argv, &exception );
p_instance = libvlc_new( 2, argv, &exception );
ASSERT( p_instance != NULL, "Instance creation failed" );
ASSERT( p_instance != NULL, "Instance creation failed" );
ASSERT( !libvlc_exception_raised( &exception ),
ASSERT( !libvlc_exception_raised( &exception ),
"Exception raised while creating instance" );
libvlc_destroy( p_instance );
libvlc_destroy( p_instance );
Py_INCREF( Py_None );
return Py_None;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *playlist_test( PyObject *self, PyObject *args )
{
libvlc_instance_t *p_instance;
char *argv[] = { "vlc", "--quiet" };
int i_id;
libvlc_exception_t exception;
libvlc_exception_init( &exception );
p_instance = libvlc_new( 2, argv, &exception );
libvlc_playlist_play( p_instance, 0, 0, argv, &exception );
ASSERT( libvlc_exception_raised( &exception ),
"Playlist empty and exception not raised" );
libvlc_exception_clear( &exception );
i_id = libvlc_playlist_add( p_instance, "test" , NULL , &exception );
ASSERT_EXCEPTION;
ASSERT( i_id > 0 , "Returned identifier is <= 0" );
Py_INCREF( Py_None );
return Py_None;
}
static PyMethodDef native_libvlc_test_methods[] = {
DEF_METHOD( create_destroy, "Create and destroy" )
DEF_METHOD( exception_test, "Test Exception handling" )
DEF_METHOD( playlist_test, "Test Playlist interaction" )
{ NULL, NULL, 0, NULL }
};

View File

@ -6,4 +6,8 @@
Py_InitModule( #module, module##_methods ); \
}
#define ASSERT_EXCEPTION if( libvlc_exception_raised( &exception ) ) { \
if( libvlc_exception_get_message( &exception ) ) PyErr_SetString( PyExc_AssertionError, libvlc_exception_get_message( &exception ) ); \
else PyErr_SetString( PyExc_AssertionError, "Exception raised" ); return NULL; }
#define DEF_METHOD( method, desc ) { #method, method, METH_VARARGS, desc},