Changeset 661a6c1357158cb970fd2b92fc5d126d65e021ac

Show
Ignore:
Timestamp:
02/03/06 20:53:47 (2 years ago)
Author:
Clément Stenac <zorglub@videolan.org>
git-committer:
Clément Stenac <zorglub@videolan.org> 1138996427 +0000
git-parent:

[6df78501b98cd69f9577c984347fbb3c8f265ec9]

git-author:
Clément Stenac <zorglub@videolan.org> 1138996427 +0000
Message:

Play and add (Refs:#457)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/vlc/libvlc.h

    r473fef1 r661a6c1  
    6868 */ 
    6969int libvlc_exception_raised( libvlc_exception_t *p_exception ); 
     70 
     71/** 
     72 * Raise an exception 
     73 * \param p_exception the exception to raise 
     74 * \param psz_message the exception message 
     75 */ 
    7076void libvlc_exception_raise( libvlc_exception_t *p_exception, char *psz_message ); 
     77 
     78/** 
     79 * Clear an exception object so it can be reused. 
     80 * The exception object must be initialized 
     81 * \param p_exception the exception to clear 
     82 */ 
     83void libvlc_exception_clear( libvlc_exception_t * ); 
    7184 
    7285/** 
     
    124137 * that will be added to the item before playing it. 
    125138 * \param p_instance the instance 
     139 * \param i_id the item to play. If this is a negative number, the next 
     140 * item will be selected. Else, the item with the given ID will be played 
    126141 * \param i_options the number of options to add to the item 
    127142 * \param ppsz_options the options to add to the item 
    128143 * \param p_exception an initialized exception 
    129144 */ 
    130 void libvlc_playlist_play( libvlc_instance_t*, int, char **, 
     145void libvlc_playlist_play( libvlc_instance_t*, int, int, char **, 
    131146                           libvlc_exception_t * ); 
    132147 
     
    159174void libvlc_playlist_prev( libvlc_instance_t *, libvlc_exception_t * ); 
    160175 
     176/** 
     177 * Add an item at the end of the playlist 
     178 * If you need more advanced options, \see libvlc_playlist_add_extended 
     179 * \param p_instance the instance 
     180 * \param psz_uri the URI to open, using VLC format 
     181 * \param psz_name a name that you might want to give or NULL 
     182 * \return the identifier of the new item 
     183 */ 
     184int libvlc_playlist_add( libvlc_instance_t *, const char *, const char *, 
     185                         libvlc_exception_t * ); 
     186 
     187/** 
     188 * Add an item at the end of the playlist, with additional input options 
     189 * \param p_instance the instance 
     190 * \param psz_uri the URI to open, using VLC format 
     191 * \param psz_name a name that you might want to give or NULL 
     192 * \param i_options the number of options to add 
     193 * \param ppsz_options strings representing the options to add 
     194 * \return the identifier of the new item 
     195 */ 
     196int libvlc_playlist_add_extended( libvlc_instance_t *, const char *, 
     197                                  const char *, int, const char **, 
     198                                  libvlc_exception_t * ); 
    161199 
    162200 
  • src/control/core.c

    r4dfa4e6 r661a6c1  
    3636} 
    3737 
     38void libvlc_exception_clear( libvlc_exception_t *p_exception ) 
     39{ 
     40    if( p_exception->psz_message ) 
     41        free( p_exception->psz_message ); 
     42    p_exception->b_raised = 0; 
     43} 
     44 
    3845inline int libvlc_exception_raised( libvlc_exception_t *p_exception ) 
    3946{ 
     
    5865        p_exception->psz_message = strdup( psz_message ); 
    5966} 
    60  
    6167 
    6268libvlc_instance_t * libvlc_new( int argc, char **argv, 
  • src/control/playlist.c

    radc858d r661a6c1  
    2727#include <vlc/intf.h> 
    2828 
    29 void libvlc_playlist_play( libvlc_instance_t *p_instance, 
     29void libvlc_playlist_play( libvlc_instance_t *p_instance, int i_id, 
    3030                           int i_options, char **ppsz_options, 
    3131                           libvlc_exception_t *p_exception ) 
     
    3838        return; 
    3939    } 
    40     playlist_Play( p_instance->p_playlist ); 
     40    if( i_id >= 0 ) 
     41    { 
     42        /* Always use the current view when using libvlc */ 
     43        playlist_view_t *p_view; 
     44        playlist_item_t *p_item; 
     45 
     46        if( p_instance->p_playlist->status.i_view == -1 ) 
     47        { 
     48            playlist_Control( p_instance->p_playlist, PLAYLIST_GOTO, 
     49                              i_id ); 
     50        } 
     51        p_view = playlist_ViewFind( p_instance->p_playlist, 
     52                                    p_instance->p_playlist->status.i_view ); 
     53        if( !p_view ) 
     54        { 
     55             libvlc_exception_raise( p_exception, 
     56                                     "Unable to find current playlist view "); 
     57             return; 
     58        } 
     59 
     60        p_item = playlist_ItemGetById( p_instance->p_playlist, i_id ); 
     61 
     62        if( !p_item ) 
     63        { 
     64            libvlc_exception_raise( p_exception, "Unable to find item " ); 
     65            return; 
     66        } 
     67 
     68        playlist_Control( p_instance->p_playlist, PLAYLIST_VIEWPLAY, 
     69                          p_instance->p_playlist->status.i_view, 
     70                          p_view->p_root, p_item ); 
     71    } 
     72    else 
     73    { 
     74        playlist_Play( p_instance->p_playlist ); 
     75    } 
    4176} 
    4277 
     
    5590    playlist_Clear( p_instance->p_playlist ); 
    5691} 
     92 
     93int libvlc_playlist_add( libvlc_instance_t *p_instance, const char *psz_uri, 
     94                         const char *psz_name, libvlc_exception_t *p_exception ) 
     95{ 
     96    return libvlc_playlist_add_extended( p_instance, psz_uri, psz_name, 
     97                                         0, NULL, p_exception ); 
     98} 
     99 
     100int libvlc_playlist_add_extended( libvlc_instance_t *p_instance, 
     101                                  const char *psz_uri, const char *psz_name, 
     102                                  int i_options, const char **ppsz_options, 
     103                                  libvlc_exception_t *p_exception ) 
     104{ 
     105    return playlist_AddExt( p_instance->p_playlist, psz_uri, psz_name, 
     106                            PLAYLIST_INSERT, PLAYLIST_END, -1, ppsz_options, 
     107                            i_options ); 
     108} 
     109 
    57110 
    58111 
  • test/NativeLibvlcTest.py

    r1e9a47f r661a6c1  
    1111        """Checks creation/destroy of libvlc""" 
    1212        native_libvlc_test.create_destroy() 
     13    def testPlaylist( self ): 
     14        """Checks basic playlist interaction""" 
     15        native_libvlc_test.playlist_test() 
  • test/native_libvlc/native_libvlc_test.c

    r1e9a47f r661a6c1  
    2424static PyObject *create_destroy( PyObject *self, PyObject *args ) 
    2525{ 
    26     libvlc_instance_t *p_instance; 
    27     char *argv[] = {}; 
     26    libvlc_instance_t *p_instance; 
     27    char *argv[] = { "vlc", "--quiet" }; 
    2828 
    29     libvlc_exception_t exception; 
    30     libvlc_exception_init( &exception ); 
     29    libvlc_exception_t exception; 
     30    libvlc_exception_init( &exception ); 
    3131 
    32     p_instance = libvlc_new( 0, argv, &exception ); 
     32    p_instance = libvlc_new( 2, argv, &exception ); 
    3333 
    34     ASSERT( p_instance != NULL, "Instance creation failed" ); 
     34    ASSERT( p_instance != NULL, "Instance creation failed" ); 
    3535 
    36     ASSERT( !libvlc_exception_raised( &exception ), 
     36    ASSERT( !libvlc_exception_raised( &exception ), 
    3737             "Exception raised while creating instance" ); 
    3838 
    39     libvlc_destroy( p_instance ); 
     39    libvlc_destroy( p_instance ); 
    4040      
    41      Py_INCREF( Py_None ); 
    42      return Py_None; 
     41    Py_INCREF( Py_None ); 
     42    return Py_None; 
     43
     44 
     45static PyObject *playlist_test( PyObject *self, PyObject *args ) 
     46
     47    libvlc_instance_t *p_instance; 
     48    char *argv[] = { "vlc", "--quiet" }; 
     49    int i_id; 
     50 
     51    libvlc_exception_t exception; 
     52    libvlc_exception_init( &exception ); 
     53 
     54    p_instance = libvlc_new( 2, argv, &exception ); 
     55 
     56    libvlc_playlist_play( p_instance, 0, 0, argv, &exception ); 
     57 
     58    ASSERT( libvlc_exception_raised( &exception ),  
     59            "Playlist empty and exception not raised" ); 
     60 
     61    libvlc_exception_clear( &exception ); 
     62    i_id = libvlc_playlist_add( p_instance, "test" , NULL , &exception ); 
     63 
     64    ASSERT_EXCEPTION; 
     65 
     66    ASSERT( i_id > 0 , "Returned identifier is <= 0" ); 
     67     
     68    Py_INCREF( Py_None ); 
     69    return Py_None; 
    4370} 
    4471 
     
    4673   DEF_METHOD( create_destroy, "Create and destroy" ) 
    4774   DEF_METHOD( exception_test, "Test Exception handling" ) 
     75   DEF_METHOD( playlist_test, "Test Playlist interaction" ) 
    4876   { NULL, NULL, 0, NULL } 
    4977}; 
  • test/pyunit.h

    r0638177 r661a6c1  
    77} 
    88 
     9#define ASSERT_EXCEPTION if( libvlc_exception_raised( &exception ) ) { \ 
     10         if( libvlc_exception_get_message( &exception ) )  PyErr_SetString( PyExc_AssertionError, libvlc_exception_get_message( &exception ) ); \ 
     11         else PyErr_SetString( PyExc_AssertionError, "Exception raised" ); return NULL; } 
     12 
    913#define DEF_METHOD( method, desc ) { #method, method, METH_VARARGS, desc},