[vlc-devel] commit: Media event handling ( Rémi Denis-Courmont )
git version control
git at videolan.org
Mon Feb 23 20:13:39 CET 2009
vlc | branch: master | Rémi Denis-Courmont <rdenis at simphalempin.com> | Mon Feb 23 20:50:27 2009 +0200| [45dbbcc4b8ada235bf3ff6b50c3a180fea3ffdaf] | committer: Rémi Denis-Courmont
Media event handling
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=45dbbcc4b8ada235bf3ff6b50c3a180fea3ffdaf
---
bindings/cil/src/media.cs | 128 +++++++++++++++++++++++++++++++++++++---
bindings/cil/tests/testvlc.cs | 13 +++-
2 files changed, 127 insertions(+), 14 deletions(-)
diff --git a/bindings/cil/src/media.cs b/bindings/cil/src/media.cs
index 575e4c8..1edf093 100644
--- a/bindings/cil/src/media.cs
+++ b/bindings/cil/src/media.cs
@@ -43,6 +43,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
*
* Media and Player objects are always in one of these 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);
+ }
};
};
diff --git a/bindings/cil/tests/testvlc.cs b/bindings/cil/tests/testvlc.cs
index 91c27ac..1d4786c 100644
--- a/bindings/cil/tests/testvlc.cs
+++ b/bindings/cil/tests/testvlc.cs
@@ -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
More information about the vlc-devel
mailing list