[vlc-devel] commit: Add media and player state support ( Rémi Denis-Courmont )

git version control git at videolan.org
Sun Feb 22 10:54:36 CET 2009


vlc | branch: master | Rémi Denis-Courmont <rdenis at simphalempin.com> | Sun Feb 22 11:54:23 2009 +0200| [60a842695c2a896fabc16dac503210a0f36f7a36] | committer: Rémi Denis-Courmont 

Add media and player state support

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=60a842695c2a896fabc16dac503210a0f36f7a36
---

 bindings/cil/src/libvlc.cs      |    9 ++++-----
 bindings/cil/src/media.cs       |   31 +++++++++++++++++++++++++++++++
 bindings/cil/src/player.cs      |   13 +++++++++++++
 bindings/cil/tests/testvlc.cs   |    5 +++--
 include/vlc/libvlc_structures.h |    3 ++-
 5 files changed, 53 insertions(+), 8 deletions(-)

diff --git a/bindings/cil/src/libvlc.cs b/bindings/cil/src/libvlc.cs
index 3fcfe59..df676e1 100644
--- a/bindings/cil/src/libvlc.cs
+++ b/bindings/cil/src/libvlc.cs
@@ -109,9 +109,9 @@ namespace VideoLAN.LibVLC
         MediaHandle MediaDuplicate (MediaHandle media, int type,
                                     NativeException ex);*/
 
-        /*[DllImport ("libvlc.dll", EntryPoint="libvlc_media_get_state")]
+        [DllImport ("libvlc.dll", EntryPoint="libvlc_media_get_state")]
         public static extern
-        int MediaGetState (MediaHandle media, NativeException ex);*/
+        State MediaGetState (MediaHandle media, NativeException ex);
 
         /*[DllImport ("libvlc.dll", EntryPoint="libvlc_media_subitems")]
         public static extern
@@ -301,11 +301,10 @@ namespace VideoLAN.LibVLC
         void PlayerSetRate (PlayerHandle player, float rate,
                             NativeException ex);
 
-        /*[DllImport ("libvlc.dll",
+        [DllImport ("libvlc.dll",
                     EntryPoint="libvlc_media_player_get_state")]
         public static extern
-        void PlayerSetState (PlayerHandle player, float rate,
-                             NativeException ex); */
+        State PlayerGetState (PlayerHandle player, NativeException ex);
 
         [DllImport ("libvlc.dll",
                     EntryPoint="libvlc_media_player_get_fps")]
diff --git a/bindings/cil/src/media.cs b/bindings/cil/src/media.cs
index a6ed833..5c3b0cf 100644
--- a/bindings/cil/src/media.cs
+++ b/bindings/cil/src/media.cs
@@ -43,6 +43,24 @@ namespace VideoLAN.LibVLC
     };
 
     /**
+     * @brief State: media/player state
+     *
+     * Media and Player objects are always in one of these state.
+     * @see Media::State and @see Player::State.
+     */
+    public enum State
+    {
+        NothingSpecial, /**< Nothing going on */
+        Opening, /**< Being opened */
+        Buffering, /**< Buffering before play */
+        Playing, /**< Playing */
+        Paused, /**< Paused */
+        Stopped, /**< Stopped */
+        Ended, /**< Played until the end */
+        Error, /**< Failed */
+    };
+
+    /**
      * @brief Media: a source media
      * @ingroup API
      * Each media object represents an input media, such as a file or an URL.
@@ -122,6 +140,19 @@ namespace VideoLAN.LibVLC
         }
 
         /**
+         * Current state of the media.
+         */
+        public State State
+        {
+            get
+            {
+                State ret = LibVLC.MediaGetState (Handle, ex);
+                Raise ();
+                return ret;
+            }
+        }
+
+        /**
          * Duration of the media in microseconds. The precision of the result
          * depends on the input stram protocol and file format. The value
          * might be incorrect and unknown (VLC usually returns 0 or -1 then).
diff --git a/bindings/cil/src/player.cs b/bindings/cil/src/player.cs
index 2e3d54b..431b9de 100644
--- a/bindings/cil/src/player.cs
+++ b/bindings/cil/src/player.cs
@@ -364,6 +364,19 @@ namespace VideoLAN.LibVLC
         }
 
         /**
+         * Current state of the player.
+         */
+        public State State
+        {
+            get
+            {
+                State ret = LibVLC.PlayerGetState (Handle, ex);
+                Raise ();
+                return ret;
+            }
+        }
+
+        /**
          * Frame rate in unit/seconds.
          */
         public float FramePerSeconds
diff --git a/bindings/cil/tests/testvlc.cs b/bindings/cil/tests/testvlc.cs
index 3868cad..91c27ac 100644
--- a/bindings/cil/tests/testvlc.cs
+++ b/bindings/cil/tests/testvlc.cs
@@ -33,6 +33,7 @@ namespace VideoLAN.LibVLC.Test
             Console.WriteLine ("Media at    {0}", m.Location);
             Console.WriteLine (" duration:  {0}µs", m.Duration);
             Console.WriteLine (" preparsed: {0}", m.IsPreparsed);
+            Console.WriteLine (" state:     {0}", m.State);
         }
 
         private static void DumpPlayer (Player p)
@@ -41,8 +42,8 @@ namespace VideoLAN.LibVLC.Test
                 return;
 
             int percent = (int)(p.Position * 100);
-            Console.Write ("{0} of {1} ms ({2}%)\r", p.Time, p.Length,
-                           percent);
+            Console.Write ("{0}: {1} of {2} ms ({3}%)\r", p.State,
+                           p.Time, p.Length, percent);
         }
 
         private static void Sleep (int msec)
diff --git a/include/vlc/libvlc_structures.h b/include/vlc/libvlc_structures.h
index bede67c..7ad8378 100644
--- a/include/vlc/libvlc_structures.h
+++ b/include/vlc/libvlc_structures.h
@@ -127,7 +127,8 @@ typedef struct libvlc_media_player_t libvlc_media_player_t;
 
 /**
  * Note the order of libvlc_state_t enum must match exactly the order of
- * @see mediacontrol_PlayerStatus and @see input_state_e enums.
+ * @see mediacontrol_PlayerStatus, @see input_state_e enums,
+ * and VideoLAN.LibVLC.State (at bindings/cil/src/media.cs).
  *
  * Expected states by web plugins are:
  * IDLE/CLOSE=0, OPENING=1, BUFFERING=2, PLAYING=3, PAUSED=4,




More information about the vlc-devel mailing list