]> git.sesse.net Git - vlc/commitdiff
Play and add (Refs:#457)
authorClément Stenac <zorglub@videolan.org>
Fri, 3 Feb 2006 19:53:47 +0000 (19:53 +0000)
committerClément Stenac <zorglub@videolan.org>
Fri, 3 Feb 2006 19:53:47 +0000 (19:53 +0000)
include/vlc/libvlc.h
src/control/core.c
src/control/playlist.c
test/NativeLibvlcTest.py
test/native_libvlc/native_libvlc_test.c
test/pyunit.h

index 01a167548b426f8993f8484891def912c56dc490..6127c3e6340dbec74a2b7b469b8ab979ea747a01 100644 (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 * );
 
 
 
index b89911fb0bc8500ba95843f10fc9ff1ae93d0903..5e5f828ecbe25645f446fc6408376efb7260170e 100644 (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 )
 {
index 5bddf54adfb02836a17601918d6cc2c7cbe2e5a7..12e1ebca2a891df5e53d746defc6aed9d0567072 100644 (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 )
index 1623c70a216af5fb88bbf08ac079c5aebc98cddc..2c7c0aa38622b795b694749ff7bb61f46156662f 100644 (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()
index b9b056bb0f9c7184b60f2e5ac38767f5abfde381..6064e926bd00a38c310fdd614200105923e9caac 100644 (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 }
 };
 
index 3fc59785502a410bfc9eda364a4305c5f28e0728..1b07165e7ac9e46fa52fadccc272fcdc5ad7be1b 100644 (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},