Changeset 661a6c1357158cb970fd2b92fc5d126d65e021ac
- 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
| r473fef1 |
r661a6c1 |
|
| 68 | 68 | */ |
|---|
| 69 | 69 | int 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 | */ |
|---|
| 70 | 76 | void 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 | */ |
|---|
| | 83 | void libvlc_exception_clear( libvlc_exception_t * ); |
|---|
| 71 | 84 | |
|---|
| 72 | 85 | /** |
|---|
| … | … | |
| 124 | 137 | * that will be added to the item before playing it. |
|---|
| 125 | 138 | * \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 |
|---|
| 126 | 141 | * \param i_options the number of options to add to the item |
|---|
| 127 | 142 | * \param ppsz_options the options to add to the item |
|---|
| 128 | 143 | * \param p_exception an initialized exception |
|---|
| 129 | 144 | */ |
|---|
| 130 | | void libvlc_playlist_play( libvlc_instance_t*, int, char **, |
|---|
| | 145 | void libvlc_playlist_play( libvlc_instance_t*, int, int, char **, |
|---|
| 131 | 146 | libvlc_exception_t * ); |
|---|
| 132 | 147 | |
|---|
| … | … | |
| 159 | 174 | void libvlc_playlist_prev( libvlc_instance_t *, libvlc_exception_t * ); |
|---|
| 160 | 175 | |
|---|
| | 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 | */ |
|---|
| | 184 | int 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 | */ |
|---|
| | 196 | int libvlc_playlist_add_extended( libvlc_instance_t *, const char *, |
|---|
| | 197 | const char *, int, const char **, |
|---|
| | 198 | libvlc_exception_t * ); |
|---|
| 161 | 199 | |
|---|
| 162 | 200 | |
|---|
| r4dfa4e6 |
r661a6c1 |
|
| 36 | 36 | } |
|---|
| 37 | 37 | |
|---|
| | 38 | void 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 | |
|---|
| 38 | 45 | inline int libvlc_exception_raised( libvlc_exception_t *p_exception ) |
|---|
| 39 | 46 | { |
|---|
| … | … | |
| 58 | 65 | p_exception->psz_message = strdup( psz_message ); |
|---|
| 59 | 66 | } |
|---|
| 60 | | |
|---|
| 61 | 67 | |
|---|
| 62 | 68 | libvlc_instance_t * libvlc_new( int argc, char **argv, |
|---|
| radc858d |
r661a6c1 |
|
| 27 | 27 | #include <vlc/intf.h> |
|---|
| 28 | 28 | |
|---|
| 29 | | void libvlc_playlist_play( libvlc_instance_t *p_instance, |
|---|
| | 29 | void libvlc_playlist_play( libvlc_instance_t *p_instance, int i_id, |
|---|
| 30 | 30 | int i_options, char **ppsz_options, |
|---|
| 31 | 31 | libvlc_exception_t *p_exception ) |
|---|
| … | … | |
| 38 | 38 | return; |
|---|
| 39 | 39 | } |
|---|
| 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 | } |
|---|
| 41 | 76 | } |
|---|
| 42 | 77 | |
|---|
| … | … | |
| 55 | 90 | playlist_Clear( p_instance->p_playlist ); |
|---|
| 56 | 91 | } |
|---|
| | 92 | |
|---|
| | 93 | int 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 | |
|---|
| | 100 | int 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 | |
|---|
| 57 | 110 | |
|---|
| 58 | 111 | |
|---|
| r1e9a47f |
r661a6c1 |
|
| 11 | 11 | """Checks creation/destroy of libvlc""" |
|---|
| 12 | 12 | native_libvlc_test.create_destroy() |
|---|
| | 13 | def testPlaylist( self ): |
|---|
| | 14 | """Checks basic playlist interaction""" |
|---|
| | 15 | native_libvlc_test.playlist_test() |
|---|
| r1e9a47f |
r661a6c1 |
|
| 24 | 24 | static PyObject *create_destroy( PyObject *self, PyObject *args ) |
|---|
| 25 | 25 | { |
|---|
| 26 | | libvlc_instance_t *p_instance; |
|---|
| 27 | | char *argv[] = {}; |
|---|
| | 26 | libvlc_instance_t *p_instance; |
|---|
| | 27 | char *argv[] = { "vlc", "--quiet" }; |
|---|
| 28 | 28 | |
|---|
| 29 | | libvlc_exception_t exception; |
|---|
| 30 | | libvlc_exception_init( &exception ); |
|---|
| | 29 | libvlc_exception_t exception; |
|---|
| | 30 | libvlc_exception_init( &exception ); |
|---|
| 31 | 31 | |
|---|
| 32 | | p_instance = libvlc_new( 0, argv, &exception ); |
|---|
| | 32 | p_instance = libvlc_new( 2, argv, &exception ); |
|---|
| 33 | 33 | |
|---|
| 34 | | ASSERT( p_instance != NULL, "Instance creation failed" ); |
|---|
| | 34 | ASSERT( p_instance != NULL, "Instance creation failed" ); |
|---|
| 35 | 35 | |
|---|
| 36 | | ASSERT( !libvlc_exception_raised( &exception ), |
|---|
| | 36 | ASSERT( !libvlc_exception_raised( &exception ), |
|---|
| 37 | 37 | "Exception raised while creating instance" ); |
|---|
| 38 | 38 | |
|---|
| 39 | | libvlc_destroy( p_instance ); |
|---|
| | 39 | libvlc_destroy( p_instance ); |
|---|
| 40 | 40 | |
|---|
| 41 | | Py_INCREF( Py_None ); |
|---|
| 42 | | return Py_None; |
|---|
| | 41 | Py_INCREF( Py_None ); |
|---|
| | 42 | return Py_None; |
|---|
| | 43 | } |
|---|
| | 44 | |
|---|
| | 45 | static 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; |
|---|
| 43 | 70 | } |
|---|
| 44 | 71 | |
|---|
| … | … | |
| 46 | 73 | DEF_METHOD( create_destroy, "Create and destroy" ) |
|---|
| 47 | 74 | DEF_METHOD( exception_test, "Test Exception handling" ) |
|---|
| | 75 | DEF_METHOD( playlist_test, "Test Playlist interaction" ) |
|---|
| 48 | 76 | { NULL, NULL, 0, NULL } |
|---|
| 49 | 77 | }; |
|---|
| r0638177 |
r661a6c1 |
|
| 7 | 7 | } |
|---|
| 8 | 8 | |
|---|
| | 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 | |
|---|
| 9 | 13 | #define DEF_METHOD( method, desc ) { #method, method, METH_VARARGS, desc}, |
|---|