Commit 7731020e authored by Martin Finkel's avatar Martin Finkel

Expose events on main objects

parent 4e4c0be0
......@@ -31,7 +31,7 @@ namespace LibVLCSharp.Shared
NativeReference = ptr;
}
internal protected void AttachNativeEvent(EventType eventType, EventCallback eventCallback)
protected void AttachNativeEvent(EventType eventType, EventCallback eventCallback)
{
_callbacks.Add(eventCallback);
if (Internal.LibVLCEventAttach(NativeReference, eventType, eventCallback, IntPtr.Zero) != 0)
......@@ -41,7 +41,7 @@ namespace LibVLCSharp.Shared
}
}
internal protected void DetachNativeEvent(EventType eventType, EventCallback eventCallback)
protected void DetachNativeEvent(EventType eventType, EventCallback eventCallback)
{
_callbacks.Remove(eventCallback);
......@@ -55,9 +55,7 @@ namespace LibVLCSharp.Shared
#endif
internal protected void OnEventUnhandled(object sender, EventType eventType)
{
throw new InvalidOperationException($"eventType {nameof(eventType)} unhandled by type {sender.GetType().Name}");
}
=> throw new InvalidOperationException($"eventType {nameof(eventType)} unhandled by type {sender.GetType().Name}");
internal protected abstract void AttachEvent<T>(EventType eventType, EventHandler<T> eventHandler) where T : EventArgs;
internal protected abstract void DetachEvent<T>(EventType eventType, EventHandler<T> eventHandler) where T : EventArgs;
......
......@@ -818,6 +818,52 @@ namespace LibVLCSharp.Shared
}
#endregion
#region Events
public event EventHandler<MediaMetaChangedEventArgs> MetaChanged
{
add => EventManager.AttachEvent(EventType.MediaMetaChanged, value);
remove => EventManager.DetachEvent(EventType.MediaMetaChanged, value);
}
public event EventHandler<MediaParsedChangedEventArgs> ParsedChanged
{
add => EventManager.AttachEvent(EventType.MediaParsedChanged, value);
remove => EventManager.DetachEvent(EventType.MediaParsedChanged, value);
}
public event EventHandler<MediaParsedChangedEventArgs> SubItemAdded
{
add => EventManager.AttachEvent(EventType.MediaSubItemAdded, value);
remove => EventManager.DetachEvent(EventType.MediaSubItemAdded, value);
}
public event EventHandler<MediaDurationChangedEventArgs> DurationChanged
{
add => EventManager.AttachEvent(EventType.MediaDurationChanged, value);
remove => EventManager.DetachEvent(EventType.MediaDurationChanged, value);
}
public event EventHandler<MediaFreedEventArgs> MediaFreed
{
add => EventManager.AttachEvent(EventType.MediaFreed, value);
remove => EventManager.DetachEvent(EventType.MediaFreed, value);
}
public event EventHandler<MediaFreedEventArgs> StateChanged
{
add => EventManager.AttachEvent(EventType.MediaStateChanged, value);
remove => EventManager.DetachEvent(EventType.MediaStateChanged, value);
}
public event EventHandler<MediaFreedEventArgs> SubItemTreeAdded
{
add => EventManager.AttachEvent(EventType.MediaSubItemTreeAdded, value);
remove => EventManager.DetachEvent(EventType.MediaSubItemTreeAdded, value);
}
#endregion
}
#region Callbacks
......
......@@ -131,6 +131,9 @@ namespace LibVLCSharp.Shared
/// </summary>
public bool IsRunning => Native.LibVLCMediaDiscovererIsRunning(NativeReference) != 0;
/// <summary>
/// The MediaList attached to this MediaDiscoverer
/// </summary>
public MediaList MediaList
{
get
......@@ -144,5 +147,21 @@ namespace LibVLCSharp.Shared
return _mediaList;
}
}
#region Events
public event EventHandler<EventArgs> Started
{
add => EventManager.AttachEvent(EventType.MediaDiscovererStarted, value);
remove => EventManager.DetachEvent(EventType.MediaDiscovererStarted, value);
}
public event EventHandler<EventArgs> Stopped
{
add => EventManager.AttachEvent(EventType.MediaDiscovererStopped, value);
remove => EventManager.DetachEvent(EventType.MediaDiscovererStopped, value);
}
#endregion
}
}
......@@ -287,5 +287,39 @@ namespace LibVLCSharp.Shared
return _eventManager;
}
}
#region Events
public event EventHandler<MediaListItemAddedEventArgs> ItemAdded
{
add => EventManager.AttachEvent(EventType.MediaListItemAdded, value);
remove => EventManager.DetachEvent(EventType.MediaListItemAdded, value);
}
public event EventHandler<MediaListWillAddItemEventArgs> WillAddItem
{
add => EventManager.AttachEvent(EventType.MediaListWillAddItem, value);
remove => EventManager.DetachEvent(EventType.MediaListWillAddItem, value);
}
public event EventHandler<MediaListItemDeletedEventArgs> ItemDeleted
{
add => EventManager.AttachEvent(EventType.MediaListItemDeleted, value);
remove => EventManager.DetachEvent(EventType.MediaListItemDeleted, value);
}
public event EventHandler<MediaListWillDeleteItemEventArgs> WillDeleteItem
{
add => EventManager.AttachEvent(EventType.MediaListWillDeleteItem, value);
remove => EventManager.DetachEvent(EventType.MediaListWillDeleteItem, value);
}
public event EventHandler<EventArgs> EndReached
{
add => EventManager.AttachEvent(EventType.MediaListEndReached, value);
remove => EventManager.DetachEvent(EventType.MediaListEndReached, value);
}
#endregion
}
}
\ No newline at end of file
......@@ -1584,14 +1584,14 @@ namespace LibVLCSharp.Shared
public bool SetRenderer(RendererItem rendererItem) =>
Native.LibVLCMediaPlayerSetRenderer(NativeReference, rendererItem.NativeReference) == 0;
#region Enums
#region Enums
#endregion
#endregion
#region Callbacks
#region Callbacks
/// <summary>
/// <para>A LibVLC media player plays one media (usually in a custom drawable).</para>
......@@ -1776,8 +1776,7 @@ namespace LibVLCSharp.Shared
[SuppressUnmanagedCodeSecurity, UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void LibVLCVolumeCb(IntPtr data, float volume, [MarshalAs(UnmanagedType.I1)] bool mute);
#endregion
#region events
#endregion
/// <summary>
/// Get the Event Manager from which the media player send event.
......@@ -1795,17 +1794,188 @@ namespace LibVLCSharp.Shared
}
}
#region events
public event EventHandler<MediaPlayerMediaChangedEventArgs> MediaChanged
{
add => EventManager.AttachEvent(EventType.MediaPlayerMediaChanged, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerMediaChanged, value);
}
public event EventHandler<EventArgs> NothingSpecial
{
add => EventManager.AttachEvent(EventType.MediaPlayerNothingSpecial, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerNothingSpecial, value);
}
public event EventHandler<EventArgs> Opening
{
add => EventManager.AttachEvent(EventType.MediaPlayerOpening, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerOpening, value);
}
public event EventHandler<MediaPlayerBufferingEventArgs> Buffering
{
add => EventManager.AttachEvent(EventType.MediaPlayerBuffering, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerBuffering, value);
}
public event EventHandler<EventArgs> Playing
{
add => EventManager.AttachEvent(EventType.MediaPlayerPlaying, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerPlaying, value);
}
public event EventHandler<EventArgs> Paused
{
add => EventManager.AttachEvent(EventType.MediaPlayerPaused, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerPaused, value);
}
public event EventHandler<EventArgs> Stopped
{
add => EventManager.AttachEvent(EventType.MediaPlayerStopped, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerStopped, value);
}
public event EventHandler<EventArgs> Forward
{
add => EventManager.AttachEvent(EventType.MediaPlayerForward, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerForward, value);
}
public event EventHandler<EventArgs> Backward
{
add => EventManager.AttachEvent(EventType.MediaPlayerBackward, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerBackward, value);
}
public event EventHandler<EventArgs> EndReached
{
add => EventManager.AttachEvent(EventType.MediaPlayerEndReached, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerEndReached, value);
}
public event EventHandler<EventArgs> EncounteredError
{
add => EventManager.AttachEvent(EventType.MediaPlayerEncounteredError, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerEncounteredError, value);
}
public event EventHandler<MediaPlayerTimeChangedEventArgs> TimeChanged
{
add => EventManager.AttachEvent(EventType.MediaPlayerTimeChanged, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerTimeChanged, value);
}
public event EventHandler<MediaPlayerPositionChangedEventArgs> PositionChanged
{
add
add => EventManager.AttachEvent(EventType.MediaPlayerPositionChanged, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerPositionChanged, value);
}
public event EventHandler<MediaPlayerSeekableChangedEventArgs> SeekableChanged
{
EventManager.AttachEvent(EventType.MediaPlayerPositionChanged, value);
add => EventManager.AttachEvent(EventType.MediaPlayerSeekableChanged, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerSeekableChanged, value);
}
remove
public event EventHandler<MediaPlayerPausableChangedEventArgs> PausableChanged
{
EventManager.DetachEvent(EventType.MediaPlayerPositionChanged, value);
add => EventManager.AttachEvent(EventType.MediaPlayerPausableChanged, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerPausableChanged, value);
}
public event EventHandler<MediaPlayerTitleChangedEventArgs> TitleChanged
{
add => EventManager.AttachEvent(EventType.MediaPlayerTitleChanged, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerTitleChanged, value);
}
public event EventHandler<MediaPlayerChapterChangedEventArgs> ChapterChanged
{
add => EventManager.AttachEvent(EventType.MediaPlayerChapterChanged, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerChapterChanged, value);
}
public event EventHandler<MediaPlayerSnapshotTakenEventArgs> SnapshotTaken
{
add => EventManager.AttachEvent(EventType.MediaPlayerSnapshotTaken, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerSnapshotTaken, value);
}
public event EventHandler<MediaPlayerLengthChangedEventArgs> LengthChanged
{
add => EventManager.AttachEvent(EventType.MediaPlayerLengthChanged, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerLengthChanged, value);
}
public event EventHandler<MediaPlayerVoutEventArgs> Vout
{
add => EventManager.AttachEvent(EventType.MediaPlayerVout, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerVout, value);
}
public event EventHandler<MediaPlayerScrambledChangedEventArgs> ScrambledChanged
{
add => EventManager.AttachEvent(EventType.MediaPlayerScrambledChanged, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerScrambledChanged, value);
}
public event EventHandler<MediaPlayerESAddedEventArgs> ESAdded
{
add => EventManager.AttachEvent(EventType.MediaPlayerESAdded, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerESAdded, value);
}
public event EventHandler<MediaPlayerESDeletedEventArgs> ESDeleted
{
add => EventManager.AttachEvent(EventType.MediaPlayerESDeleted, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerESDeleted, value);
}
public event EventHandler<MediaPlayerESSelectedEventArgs> ESSelected
{
add => EventManager.AttachEvent(EventType.MediaPlayerESSelected, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerESSelected, value);
}
public event EventHandler<MediaPlayerAudioDeviceEventArgs> AudioDevice
{
add => EventManager.AttachEvent(EventType.MediaPlayerAudioDevice, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerAudioDevice, value);
}
public event EventHandler<EventArgs> Corked
{
add => EventManager.AttachEvent(EventType.MediaPlayerCorked, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerCorked, value);
}
public event EventHandler<EventArgs> Uncorked
{
add => EventManager.AttachEvent(EventType.MediaPlayerUncorked, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerUncorked, value);
}
public event EventHandler<EventArgs> Muted
{
add => EventManager.AttachEvent(EventType.MediaPlayerMuted, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerMuted, value);
}
public event EventHandler<EventArgs> Unmuted
{
add => EventManager.AttachEvent(EventType.MediaPlayerUnmuted, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerUnmuted, value);
}
public event EventHandler<MediaPlayerVolumeChangedEventArgs> VolumeChanged
{
add => EventManager.AttachEvent(EventType.MediaPlayerAudioVolume, value);
remove => EventManager.DetachEvent(EventType.MediaPlayerAudioVolume, value);
}
#endregion
}
......
......@@ -61,26 +61,14 @@ namespace LibVLCSharp.Shared
public event EventHandler<RendererDiscovererItemAddedEventArgs> ItemAdded
{
add
{
EventManager.AttachEvent(EventType.RendererDiscovererItemAdded, value);
}
remove
{
EventManager.DetachEvent(EventType.RendererDiscovererItemAdded, value);
}
add => EventManager.AttachEvent(EventType.RendererDiscovererItemAdded, value);
remove => EventManager.DetachEvent(EventType.RendererDiscovererItemAdded, value);
}
public event EventHandler<RendererDiscovererItemDeletedEventArgs> ItemDeleted
{
add
{
EventManager.AttachEvent(EventType.RendererDiscovererItemDeleted, value);
}
remove
{
EventManager.DetachEvent(EventType.RendererDiscovererItemDeleted, value);
}
add => EventManager.AttachEvent(EventType.RendererDiscovererItemDeleted, value);
remove => EventManager.DetachEvent(EventType.RendererDiscovererItemDeleted, value);
}
}
......
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