Commit 45dbbcc4 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Media event handling

parent c05739b1
......@@ -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);
}
};
};
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment