]> git.sesse.net Git - vlc/commitdiff
Media event handling
authorRémi Denis-Courmont <rdenis@simphalempin.com>
Mon, 23 Feb 2009 18:50:27 +0000 (20:50 +0200)
committerRémi Denis-Courmont <rdenis@simphalempin.com>
Mon, 23 Feb 2009 19:13:29 +0000 (21:13 +0200)
bindings/cil/src/media.cs
bindings/cil/tests/testvlc.cs

index 575e4c87c79359171ee3f3683b532600a11f85a3..1edf093fb2a0ad2c551a5b805ab179e4156759df 100644 (file)
@@ -42,6 +42,30 @@ namespace VideoLAN.LibVLC
         }
     };
 
+    /**
+     * @brief MetaType: type of a media meta-information entry
+     */
+    public enum MetaType
+    {
+        Title,
+        Artist,
+        Genre,
+        Copyright,
+        Album,
+        TrackNumber,
+        Description,
+        Rating,
+        Date,
+        Setting,
+        URL,
+        Language,
+        NowPlaying,
+        Publisher,
+        EncodedBy,
+        ArtworkURL,
+        TrackID,
+    };
+
     /**
      * @brief State: media/player state
      *
@@ -60,6 +84,45 @@ namespace VideoLAN.LibVLC
         Error, /**< Failed */
     };
 
+    /* Media events */
+    [StructLayout (LayoutKind.Sequential)]
+    internal sealed class MediaMetaEvent : GenericEvent
+    {
+        public MetaType metaType;
+    };
+    internal delegate void MediaMetaCallback (MediaMetaEvent e, IntPtr d);
+
+    /*[StructLayout (LayoutKind.Sequential)]
+    internal sealed class MediaSubitemEvent : GenericEvent
+    {
+        public IntPtr child; -- MediaHandle
+    };*/
+
+    [StructLayout (LayoutKind.Sequential)]
+    internal sealed class MediaDurationEvent : GenericEvent
+    {
+        public long duration;
+    };
+    internal delegate void MediaDurationCallback (MediaDurationEvent e,
+                                                  IntPtr d);
+
+    [StructLayout (LayoutKind.Sequential)]
+    internal sealed class MediaPreparseEvent : GenericEvent
+    {
+        public int status;
+    };
+    internal delegate void MediaPreparseCallback (MediaPreparseEvent e,
+                                                  IntPtr d);
+
+    /* media_freed -> bad idea w.r.t. the GC */
+
+    [StructLayout (LayoutKind.Sequential)]
+    internal sealed class MediaStateEvent : GenericEvent
+    {
+        public State state;
+    };
+    internal delegate void MediaStateCallback (MediaStateEvent e, IntPtr d);
+
     /**
      * @brief Media: a source media
      * @ingroup API
@@ -87,6 +150,35 @@ namespace VideoLAN.LibVLC
 
             handle = LibVLC.MediaCreate (instance.Handle, umrl, ex);
             Raise ();
+            Attach ();
+        }
+
+        private Media (MediaHandle handle)
+        {
+            this.handle = handle;
+            Attach ();
+        }
+
+        /**
+         * Duplicates a media object.
+         */
+        public object Clone ()
+        {
+            return new Media (LibVLC.MediaDuplicate (Handle));
+        }
+
+        private void Attach ()
+        {
+            Attach (EventType.MediaMetaChanged,
+                    new MediaMetaCallback (MetaCallback));
+            //Attach (EventType.MediaSubItemAdded, SubItemAdded);
+            Attach (EventType.MediaDurationChanged,
+                    new MediaDurationCallback (DurationCallback));
+            /*Attach (EventType.MediaPreparsedChanged,
+                    new MediaPreparseCallback (PreparseCallback));*/
+            /* MediaFreed: better not... */
+            Attach (EventType.MediaStateChanged,
+                    new MediaStateCallback (StateCallback));
         }
 
         /**
@@ -128,17 +220,9 @@ namespace VideoLAN.LibVLC
             }
         }
 
-        private Media (MediaHandle handle)
+        public override string ToString ()
         {
-            this.handle = handle;
-        }
-
-        /**
-         * Duplicates a media object.
-         */
-        public object Clone ()
-        {
-            return new Media (LibVLC.MediaDuplicate (Handle));
+            return Location;
         }
 
         /**
@@ -154,6 +238,14 @@ namespace VideoLAN.LibVLC
             }
         }
 
+        public delegate void StateChange (Media media, State state);
+        public event StateChange StateChanged;
+        private void StateCallback (MediaStateEvent ev, IntPtr data)
+        {
+            if (StateChanged != null)
+                StateChanged (this, ev.state);
+        }
+
         internal override EventManagerHandle GetManager ()
         {
             return LibVLC.MediaEventManager (Handle, null);
@@ -174,6 +266,14 @@ namespace VideoLAN.LibVLC
             }
         }
 
+        public delegate void DurationChange (Media media, long duration);
+        public event DurationChange DurationChanged;
+        private void DurationCallback (MediaDurationEvent ev, IntPtr data)
+        {
+            if (DurationChanged != null)
+                DurationChanged (this, ev.duration);
+        }
+
         /**
          * Whether the media was "preparsed". If true, the meta-infos were
          * extracted, even before the media was played. This is normally only
@@ -188,5 +288,13 @@ namespace VideoLAN.LibVLC
                 return preparsed != 0;
             }
         }
+
+        public delegate void PreparseChange (Media media, bool preparsed);
+        public event PreparseChange PreparseChanged;
+        private void PreparseCallback (MediaPreparseEvent ev, IntPtr data)
+        {
+            if (PreparseChanged != null)
+                PreparseChanged (this, ev.status != 0);
+        }
     };
 };
index 91c27ac539ba3208e61c620b48a90c13c2048ea2..1d4786c8d2f837b2a427bd6d6b777d88fc8c9c4c 100644 (file)
@@ -30,10 +30,14 @@ namespace VideoLAN.LibVLC.Test
     {
         private static void DumpMedia (Media m)
         {
-            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);
+            Console.WriteLine ("Media: {0} {1} (duration: {2}, {3}preparsed)",
+                               m.State, m.Location, m.Duration,
+                               m.IsPreparsed ? "" : "not ");
+        }
+
+        private static void WriteMediaState (Media m, State s)
+        {
+            Console.WriteLine (" -> {0}", s);
         }
 
         private static void DumpPlayer (Player p)
@@ -69,6 +73,7 @@ namespace VideoLAN.LibVLC.Test
 
                 DumpMedia (media);
                 DumpMedia ((Media)media.Clone ());
+                media.StateChanged += WriteMediaState;
 
                 player.Play ();
                 do