Commit 4e4c0be0 authored by Martin Finkel's avatar Martin Finkel

Update all event managers

parent 2581072f
This diff is collapsed.
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security;
namespace LibVLCSharp.Shared
{
internal abstract class EventManager
{
internal struct Internal
{
[SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "libvlc_event_attach")]
internal static extern int LibVLCEventAttach(IntPtr eventManager, EventType eventType, EventCallback eventCallback,
IntPtr userData);
[SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "libvlc_event_detach")]
internal static extern void LibVLCEventDetach(IntPtr eventManager, EventType eventType, EventCallback eventCallback,
IntPtr userData);
}
internal IntPtr NativeReference;
readonly List<EventCallback> _callbacks = new List<EventCallback>();
internal protected EventManager(IntPtr ptr)
{
if (ptr == IntPtr.Zero)
throw new NullReferenceException(nameof(ptr));
NativeReference = ptr;
}
internal protected void AttachNativeEvent(EventType eventType, EventCallback eventCallback)
{
_callbacks.Add(eventCallback);
if (Internal.LibVLCEventAttach(NativeReference, eventType, eventCallback, IntPtr.Zero) != 0)
{
_callbacks.Remove(eventCallback);
throw new VLCException($"Could not attach event {eventType}");
}
}
internal protected void DetachNativeEvent(EventType eventType, EventCallback eventCallback)
{
_callbacks.Remove(eventCallback);
Internal.LibVLCEventDetach(NativeReference, eventType, eventCallback, IntPtr.Zero);
}
#if IOS
internal protected static LibVLCEvent RetrieveEvent(IntPtr eventPtr) => Marshal.PtrToStructure<LibVLCEvent>(eventPtr);
#else
internal protected LibVLCEvent RetrieveEvent(IntPtr eventPtr) => Marshal.PtrToStructure<LibVLCEvent>(eventPtr);
#endif
internal protected void OnEventUnhandled(object sender, EventType eventType)
{
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;
}
[SuppressUnmanagedCodeSecurity, UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void EventCallback(IntPtr args);
}
\ No newline at end of file
using System;
namespace LibVLCSharp.Shared
{
internal class MediaDiscovererEventManager : EventManager
{
readonly object _lock = new object();
#if IOS
static EventHandler<EventArgs> _mediaDiscovererStarted;
static EventHandler<EventArgs> _mediaDiscovererStopped;
#else
EventHandler<EventArgs> _mediaDiscovererStarted;
EventHandler<EventArgs> _mediaDiscovererStopped;
#endif
public MediaDiscovererEventManager(IntPtr ptr) : base(ptr)
{
}
protected internal override void AttachEvent<T>(EventType eventType, EventHandler<T> eventHandler)
{
lock (_lock)
{
switch (eventType)
{
case EventType.MediaDiscovererStarted:
_mediaDiscovererStarted += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnStarted);
break;
case EventType.MediaDiscovererStopped:
_mediaDiscovererStopped += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnStopped);
break;
default:
OnEventUnhandled(this, eventType);
break;
}
}
}
protected internal override void DetachEvent<T>(EventType eventType, EventHandler<T> eventHandler)
{
lock (_lock)
{
switch (eventType)
{
case EventType.MediaDiscovererStarted:
_mediaDiscovererStarted -= eventHandler as EventHandler<EventArgs>;
DetachNativeEvent(eventType, OnStarted);
break;
case EventType.MediaDiscovererStopped:
_mediaDiscovererStopped -= eventHandler as EventHandler<EventArgs>;
DetachNativeEvent(eventType, OnStopped);
break;
default:
OnEventUnhandled(this, eventType);
break;
}
}
}
#if IOS
[MonoPInvokeCallback(typeof(EventCallback))]
static void OnStarted(IntPtr ptr)
{
_mediaDiscovererStarted?.Invoke(null, EventArgs.Empty);
}
[MonoPInvokeCallback(typeof(EventCallback))]
static void OnStopped(IntPtr ptr)
{
_mediaDiscovererStopped?.Invoke(null, EventArgs.Empty);
}
#else
void OnStarted(IntPtr ptr)
{
_mediaDiscovererStarted?.Invoke(this, EventArgs.Empty);
}
void OnStopped(IntPtr ptr)
{
_mediaDiscovererStopped?.Invoke(this, EventArgs.Empty);
}
#endif
}
}
using System;
namespace LibVLCSharp.Shared
{
internal class MediaEventManager : EventManager
{
readonly object _lock = new object();
#if IOS
static EventHandler<MediaMetaChangedEventArgs> _mediaMetaChanged;
static EventHandler<MediaParsedChangedEventArgs> _mediaParsedChanged;
static EventHandler<MediaSubItemAddedEventArgs> _mediaSubItemAdded;
static EventHandler<MediaDurationChangedEventArgs> _mediaDurationChanged;
static EventHandler<MediaFreedEventArgs> _mediaFreed;
static EventHandler<MediaStateChangedEventArgs> _mediaStateChanged;
static EventHandler<MediaSubItemTreeAddedEventArgs> _mediaSubItemTreeAdded;
#else
EventHandler<MediaMetaChangedEventArgs> _mediaMetaChanged;
EventHandler<MediaParsedChangedEventArgs> _mediaParsedChanged;
EventHandler<MediaSubItemAddedEventArgs> _mediaSubItemAdded;
EventHandler<MediaDurationChangedEventArgs> _mediaDurationChanged;
EventHandler<MediaFreedEventArgs> _mediaFreed;
EventHandler<MediaStateChangedEventArgs> _mediaStateChanged;
EventHandler<MediaSubItemTreeAddedEventArgs> _mediaSubItemTreeAdded;
#endif
public MediaEventManager(IntPtr ptr) : base(ptr)
{
}
protected internal override void AttachEvent<T>(EventType eventType, EventHandler<T> eventHandler)
{
lock(_lock)
{
switch (eventType)
{
case EventType.MediaMetaChanged:
_mediaMetaChanged += eventHandler as EventHandler<MediaMetaChangedEventArgs>;
AttachNativeEvent(eventType, OnMetaChanged);
break;
case EventType.MediaParsedChanged:
_mediaParsedChanged += eventHandler as EventHandler<MediaParsedChangedEventArgs>;
AttachNativeEvent(eventType, OnParsedChanged);
break;
case EventType.MediaSubItemAdded:
_mediaSubItemAdded += eventHandler as EventHandler<MediaSubItemAddedEventArgs>;
AttachNativeEvent(eventType, OnSubItemAdded);
break;
case EventType.MediaDurationChanged:
_mediaDurationChanged += eventHandler as EventHandler<MediaDurationChangedEventArgs>;
AttachNativeEvent(eventType, OnDurationChanged);
break;
case EventType.MediaFreed:
_mediaFreed += eventHandler as EventHandler<MediaFreedEventArgs>;
AttachNativeEvent(eventType, OnMediaFreed);
break;
case EventType.MediaStateChanged:
_mediaStateChanged += eventHandler as EventHandler<MediaStateChangedEventArgs>;
AttachNativeEvent(eventType, OnMediaStateChanged);
break;
case EventType.MediaSubItemTreeAdded:
_mediaSubItemTreeAdded += eventHandler as EventHandler<MediaSubItemTreeAddedEventArgs>;
AttachNativeEvent(eventType, OnSubItemTreeAdded);
break;
default:
OnEventUnhandled(this, eventType);
break;
}
}
}
protected internal override void DetachEvent<T>(EventType eventType, EventHandler<T> eventHandler)
{
lock (_lock)
{
switch (eventType)
{
case EventType.MediaMetaChanged:
_mediaMetaChanged -= eventHandler as EventHandler<MediaMetaChangedEventArgs>;
DetachNativeEvent(eventType, OnMetaChanged);
break;
case EventType.MediaParsedChanged:
_mediaParsedChanged -= eventHandler as EventHandler<MediaParsedChangedEventArgs>;
DetachNativeEvent(eventType, OnParsedChanged);
break;
case EventType.MediaSubItemAdded:
_mediaSubItemAdded -= eventHandler as EventHandler<MediaSubItemAddedEventArgs>;
DetachNativeEvent(eventType, OnSubItemAdded);
break;
case EventType.MediaDurationChanged:
_mediaDurationChanged -= eventHandler as EventHandler<MediaDurationChangedEventArgs>;
DetachNativeEvent(eventType, OnDurationChanged);
break;
case EventType.MediaFreed:
_mediaFreed -= eventHandler as EventHandler<MediaFreedEventArgs>;
DetachNativeEvent(eventType, OnMediaFreed);
break;
case EventType.MediaStateChanged:
_mediaStateChanged -= eventHandler as EventHandler<MediaStateChangedEventArgs>;
DetachNativeEvent(eventType, OnMediaStateChanged);
break;
case EventType.MediaSubItemTreeAdded:
_mediaSubItemTreeAdded -= eventHandler as EventHandler<MediaSubItemTreeAddedEventArgs>;
DetachNativeEvent(eventType, OnSubItemTreeAdded);
break;
default:
OnEventUnhandled(this, eventType);
break;
}
}
}
#if IOS
[MonoPInvokeCallback(typeof(EventCallback))]
static void OnSubItemTreeAdded(IntPtr ptr)
{
_mediaSubItemTreeAdded?.Invoke(null,
new MediaSubItemTreeAddedEventArgs(RetrieveEvent(ptr).Union.MediaSubItemTreeAdded.MediaInstance));
}
[MonoPInvokeCallback(typeof(EventCallback))]
static void OnMediaStateChanged(IntPtr ptr)
{
_mediaStateChanged?.Invoke(null,
new MediaStateChangedEventArgs(RetrieveEvent(ptr).Union.MediaStateChanged.NewState));
}
[MonoPInvokeCallback(typeof(EventCallback))]
static void OnMediaFreed(IntPtr ptr)
{
_mediaFreed?.Invoke(null, new MediaFreedEventArgs(RetrieveEvent(ptr).Union.MediaFreed.MediaInstance));
}
[MonoPInvokeCallback(typeof(EventCallback))]
static void OnDurationChanged(IntPtr ptr)
{
_mediaDurationChanged?.Invoke(null,
new MediaDurationChangedEventArgs(RetrieveEvent(ptr).Union.MediaDurationChanged.NewDuration));
}
[MonoPInvokeCallback(typeof(EventCallback))]
static void OnSubItemAdded(IntPtr ptr)
{
_mediaSubItemAdded?.Invoke(null,
new MediaSubItemAddedEventArgs(RetrieveEvent(ptr).Union.MediaSubItemAdded.NewChild));
}
[MonoPInvokeCallback(typeof(EventCallback))]
static void OnParsedChanged(IntPtr ptr)
{
_mediaParsedChanged?.Invoke(null,
new MediaParsedChangedEventArgs(RetrieveEvent(ptr).Union.MediaParsedChanged.NewStatus));
}
[MonoPInvokeCallback(typeof(EventCallback))]
static void OnMetaChanged(IntPtr ptr)
{
_mediaMetaChanged?.Invoke(null,
new MediaMetaChangedEventArgs(RetrieveEvent(ptr).Union.MediaMetaChanged.MetaType));
}
#else
void OnSubItemTreeAdded(IntPtr ptr)
{
_mediaSubItemTreeAdded?.Invoke(this,
new MediaSubItemTreeAddedEventArgs(RetrieveEvent(ptr).Union.MediaSubItemTreeAdded.MediaInstance));
}
void OnMediaStateChanged(IntPtr ptr)
{
_mediaStateChanged?.Invoke(this,
new MediaStateChangedEventArgs(RetrieveEvent(ptr).Union.MediaStateChanged.NewState));
}
void OnMediaFreed(IntPtr ptr)
{
_mediaFreed?.Invoke(this, new MediaFreedEventArgs(RetrieveEvent(ptr).Union.MediaFreed.MediaInstance));
}
void OnDurationChanged(IntPtr ptr)
{
_mediaDurationChanged?.Invoke(this,
new MediaDurationChangedEventArgs(RetrieveEvent(ptr).Union.MediaDurationChanged.NewDuration));
}
void OnSubItemAdded(IntPtr ptr)
{
_mediaSubItemAdded?.Invoke(this,
new MediaSubItemAddedEventArgs(RetrieveEvent(ptr).Union.MediaSubItemAdded.NewChild));
}
void OnParsedChanged(IntPtr ptr)
{
_mediaParsedChanged?.Invoke(this,
new MediaParsedChangedEventArgs(RetrieveEvent(ptr).Union.MediaParsedChanged.NewStatus));
}
void OnMetaChanged(IntPtr ptr)
{
_mediaMetaChanged?.Invoke(this,
new MediaMetaChangedEventArgs(RetrieveEvent(ptr).Union.MediaMetaChanged.MetaType));
}
#endif
}
}
\ No newline at end of file
using System;
namespace LibVLCSharp.Shared
{
internal class MediaListEventManager : EventManager
{
readonly object _lock = new object();
#if IOS
static EventHandler<MediaListItemAddedEventArgs> _mediaListItemAdded;
static EventHandler<MediaListWillAddItemEventArgs> _mediaListWillAddItem;
static EventHandler<MediaListItemDeletedEventArgs> _mediaListItemDeleted;
static EventHandler<MediaListWillDeleteItemEventArgs> _mediaListWillDeleteItem;
static EventHandler<EventArgs> _mediaListEndReached;
#else
EventHandler<MediaListItemAddedEventArgs> _mediaListItemAdded;
EventHandler<MediaListWillAddItemEventArgs> _mediaListWillAddItem;
EventHandler<MediaListItemDeletedEventArgs> _mediaListItemDeleted;
EventHandler<MediaListWillDeleteItemEventArgs> _mediaListWillDeleteItem;
EventHandler<EventArgs> _mediaListEndReached;
#endif
public MediaListEventManager(IntPtr ptr) : base(ptr)
{
}
protected internal override void AttachEvent<T>(EventType eventType, EventHandler<T> eventHandler)
{
lock (_lock)
{
switch (eventType)
{
case EventType.MediaListItemAdded:
_mediaListItemAdded += eventHandler as EventHandler<MediaListItemAddedEventArgs>;
AttachNativeEvent(eventType, OnItemAdded);
break;
case EventType.MediaListWillAddItem:
_mediaListWillAddItem += eventHandler as EventHandler<MediaListWillAddItemEventArgs>;
AttachNativeEvent(eventType, OnWillAddItem);
break;
case EventType.MediaListItemDeleted:
_mediaListItemDeleted += eventHandler as EventHandler<MediaListItemDeletedEventArgs>;
AttachNativeEvent(eventType, OnItemDeleted);
break;
case EventType.MediaListViewWillDeleteItem:
_mediaListWillDeleteItem += eventHandler as EventHandler<MediaListWillDeleteItemEventArgs>;
AttachNativeEvent(eventType, OnWillDeleteItem);
break;
case EventType.MediaListEndReached:
_mediaListEndReached += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnEndReached);
break;
default:
OnEventUnhandled(this, eventType);
break;
}
}
}
protected internal override void DetachEvent<T>(EventType eventType, EventHandler<T> eventHandler)
{
lock (_lock)
{
switch (eventType)
{
case EventType.MediaListItemAdded:
_mediaListItemAdded -= eventHandler as EventHandler<MediaListItemAddedEventArgs>;
DetachNativeEvent(eventType, OnItemAdded);
break;
case EventType.MediaListWillAddItem:
_mediaListWillAddItem -= eventHandler as EventHandler<MediaListWillAddItemEventArgs>;
DetachNativeEvent(eventType, OnWillAddItem);
break;
case EventType.MediaListItemDeleted:
_mediaListItemDeleted -= eventHandler as EventHandler<MediaListItemDeletedEventArgs>;
DetachNativeEvent(eventType, OnItemDeleted);
break;
case EventType.MediaListViewWillDeleteItem:
_mediaListWillDeleteItem -= eventHandler as EventHandler<MediaListWillDeleteItemEventArgs>;
DetachNativeEvent(eventType, OnWillDeleteItem);
break;
case EventType.MediaListEndReached:
_mediaListEndReached -= eventHandler as EventHandler<EventArgs>;
DetachNativeEvent(eventType, OnEndReached);
break;
default:
OnEventUnhandled(this, eventType);
break;
}
}
}
#if IOS
[MonoPInvokeCallback(typeof(EventCallback))]
static void OnItemAdded(IntPtr ptr)
{
var itemAdded = RetrieveEvent(ptr).Union.MediaListItemAdded;
_mediaListItemAdded?.Invoke(null,
new MediaListItemAddedEventArgs(new Media(itemAdded.MediaInstance), itemAdded.Index));
}
[MonoPInvokeCallback(typeof(EventCallback))]
static void OnWillAddItem(IntPtr ptr)
{
var willAddItem = RetrieveEvent(ptr).Union.MediaListWillAddItem;
_mediaListWillAddItem?.Invoke(null,
new MediaListWillAddItemEventArgs(new Media(willAddItem.MediaInstance), willAddItem.Index));
}
[MonoPInvokeCallback(typeof(EventCallback))]
static void OnItemDeleted(IntPtr ptr)
{
var itemDeleted = RetrieveEvent(ptr).Union.MediaListItemDeleted;
_mediaListItemDeleted?.Invoke(null,
new MediaListItemDeletedEventArgs(new Media(itemDeleted.MediaInstance), itemDeleted.Index));
}
[MonoPInvokeCallback(typeof(EventCallback))]
static void OnWillDeleteItem(IntPtr ptr)
{
var willDeleteItem = RetrieveEvent(ptr).Union.MediaListWillDeleteItem;
_mediaListWillDeleteItem?.Invoke(null,
new MediaListWillDeleteItemEventArgs(new Media(willDeleteItem.MediaInstance), willDeleteItem.Index));
}
[MonoPInvokeCallback(typeof(EventCallback))]
static void OnEndReached(IntPtr ptr)
{
_mediaListEndReached?.Invoke(null, EventArgs.Empty);
}
#else
void OnItemAdded(IntPtr ptr)
{
var itemAdded = RetrieveEvent(ptr).Union.MediaListItemAdded;
_mediaListItemAdded?.Invoke(this,
new MediaListItemAddedEventArgs(new Media(itemAdded.MediaInstance), itemAdded.Index));
}
void OnWillAddItem(IntPtr ptr)
{
var willAddItem = RetrieveEvent(ptr).Union.MediaListWillAddItem;
_mediaListWillAddItem?.Invoke(this,
new MediaListWillAddItemEventArgs(new Media(willAddItem.MediaInstance), willAddItem.Index));
}
void OnItemDeleted(IntPtr ptr)
{
var itemDeleted = RetrieveEvent(ptr).Union.MediaListItemDeleted;
_mediaListItemDeleted?.Invoke(this,
new MediaListItemDeletedEventArgs(new Media(itemDeleted.MediaInstance), itemDeleted.Index));
}
void OnWillDeleteItem(IntPtr ptr)
{
var willDeleteItem = RetrieveEvent(ptr).Union.MediaListWillDeleteItem;
_mediaListWillDeleteItem?.Invoke(this,
new MediaListWillDeleteItemEventArgs(new Media(willDeleteItem.MediaInstance), willDeleteItem.Index));
}
void OnEndReached(IntPtr ptr)
{
_mediaListEndReached?.Invoke(this, EventArgs.Empty);
}
#endif
}
}
using System;
namespace LibVLCSharp.Shared
{
internal class MediaPlayerEventManager : EventManager
{
readonly object _lock = new object();
#if IOS
static EventHandler<MediaPlayerMediaChangedEventArgs> _mediaPlayerMediaChanged;
static EventHandler<EventArgs> _mediaPlayerNothingSpecial;
static EventHandler<EventArgs> _mediaPlayerOpening;
static EventHandler<MediaPlayerBufferingEventArgs> _mediaPlayerBuffering;
static EventHandler<EventArgs> _mediaPlayerPlaying;
static EventHandler<EventArgs> _mediaPlayerPaused;
static EventHandler<EventArgs> _mediaPlayerStopped;
static EventHandler<EventArgs> _mediaPlayerForward;
static EventHandler<EventArgs> _mediaPlayerBackward;
static EventHandler<EventArgs> _mediaPlayerEndReached;
static EventHandler<EventArgs> _mediaPlayerEncounteredError;
static EventHandler<MediaPlayerTimeChangedEventArgs> _mediaPlayerTimeChanged;
static EventHandler<MediaPlayerPositionChangedEventArgs> _mediaPlayerPositionChanged;
static EventHandler<MediaPlayerSeekableChangedEventArgs> _mediaPlayerSeekableChanged;
static EventHandler<MediaPlayerPausableChangedEventArgs> _mediaPlayerPausableChanged;
static EventHandler<MediaPlayerTitleChangedEventArgs> _mediaPlayerTitleChanged;
static EventHandler<MediaPlayerChapterChangedEventArgs> _mediaPlayerChapterChanged; //vlc 3
static EventHandler<MediaPlayerSnapshotTakenEventArgs> _mediaPlayerSnapshotTaken;
static EventHandler<MediaPlayerLengthChangedEventArgs> _mediaPlayerLengthChanged;
static EventHandler<MediaPlayerVoutEventArgs> _mediaPlayerVout;
static EventHandler<MediaPlayerScrambledChangedEventArgs> _mediaPlayerScrambledChanged;
static EventHandler<MediaPlayerESAddedEventArgs> _mediaPlayerESAdded; // vlc 3
static EventHandler<MediaPlayerESDeletedEventArgs> _mediaPlayerESDeleted; // vlc 3
static EventHandler<MediaPlayerESSelectedEventArgs> _mediaPlayerESSelected; // vlc 3
static EventHandler<MediaPlayerAudioDeviceEventArgs> _mediaPlayerAudioDevice; // vlc 3
static EventHandler<EventArgs> _mediaPlayerCorked; // vlc 2.2
static EventHandler<EventArgs> _mediaPlayerUncorked; // vlc 2.2
static EventHandler<EventArgs> _mediaPlayerMuted; // vlc 2.2
static EventHandler<EventArgs> _mediaPlayerUnmuted; // vlc 2.2
static EventHandler<MediaPlayerVolumeChangedEventArgs> _mediaPlayerVolumeChanged; // vlc 2.2
#else
EventHandler<MediaPlayerMediaChangedEventArgs> _mediaPlayerMediaChanged;
EventHandler<EventArgs> _mediaPlayerNothingSpecial;
EventHandler<EventArgs> _mediaPlayerOpening;
EventHandler<MediaPlayerBufferingEventArgs> _mediaPlayerBuffering;
EventHandler<EventArgs> _mediaPlayerPlaying;
EventHandler<EventArgs> _mediaPlayerPaused;
EventHandler<EventArgs> _mediaPlayerStopped;
EventHandler<EventArgs> _mediaPlayerForward;
EventHandler<EventArgs> _mediaPlayerBackward;
EventHandler<EventArgs> _mediaPlayerEndReached;
EventHandler<EventArgs> _mediaPlayerEncounteredError;
EventHandler<MediaPlayerTimeChangedEventArgs> _mediaPlayerTimeChanged;
EventHandler<MediaPlayerPositionChangedEventArgs> _mediaPlayerPositionChanged;
EventHandler<MediaPlayerSeekableChangedEventArgs> _mediaPlayerSeekableChanged;
EventHandler<MediaPlayerPausableChangedEventArgs> _mediaPlayerPausableChanged;
EventHandler<MediaPlayerTitleChangedEventArgs> _mediaPlayerTitleChanged;
EventHandler<MediaPlayerChapterChangedEventArgs> _mediaPlayerChapterChanged; //vlc 3
EventHandler<MediaPlayerSnapshotTakenEventArgs> _mediaPlayerSnapshotTaken;
EventHandler<MediaPlayerLengthChangedEventArgs> _mediaPlayerLengthChanged;
EventHandler<MediaPlayerVoutEventArgs> _mediaPlayerVout;
EventHandler<MediaPlayerScrambledChangedEventArgs> _mediaPlayerScrambledChanged;
EventHandler<MediaPlayerESAddedEventArgs> _mediaPlayerESAdded; // vlc 3
EventHandler<MediaPlayerESDeletedEventArgs> _mediaPlayerESDeleted; // vlc 3
EventHandler<MediaPlayerESSelectedEventArgs> _mediaPlayerESSelected; // vlc 3
EventHandler<MediaPlayerAudioDeviceEventArgs> _mediaPlayerAudioDevice; // vlc 3
EventHandler<EventArgs> _mediaPlayerCorked; // vlc 2.2
EventHandler<EventArgs> _mediaPlayerUncorked; // vlc 2.2
EventHandler<EventArgs> _mediaPlayerMuted; // vlc 2.2
EventHandler<EventArgs> _mediaPlayerUnmuted; // vlc 2.2
EventHandler<MediaPlayerVolumeChangedEventArgs> _mediaPlayerVolumeChanged; // vlc 2.2
#endif
public MediaPlayerEventManager(IntPtr ptr) : base(ptr)
{
}
protected internal override void AttachEvent<T>(EventType eventType, EventHandler<T> eventHandler)
{
lock(_lock)
{
switch (eventType)
{
case EventType.MediaPlayerPositionChanged:
_mediaPlayerPositionChanged += eventHandler as EventHandler<MediaPlayerPositionChangedEventArgs>;
AttachNativeEvent(eventType, OnPositionChanged);
break;
case EventType.MediaPlayerMediaChanged:
_mediaPlayerMediaChanged += eventHandler as EventHandler<MediaPlayerMediaChangedEventArgs>;
AttachNativeEvent(eventType, OnMediaChanged);
break;
case EventType.MediaPlayerNothingSpecial:
_mediaPlayerNothingSpecial += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnNothingSpecial);
break;
case EventType.MediaPlayerOpening:
_mediaPlayerOpening += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnOpening);
break;
case EventType.MediaPlayerBuffering:
_mediaPlayerBuffering += eventHandler as EventHandler<MediaPlayerBufferingEventArgs>;
AttachNativeEvent(eventType, OnBuffering);
break;
case EventType.MediaPlayerPlaying:
_mediaPlayerPlaying += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnPlaying);
break;
case EventType.MediaPlayerPaused:
_mediaPlayerPaused += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnPaused);
break;
case EventType.MediaPlayerStopped:
_mediaPlayerStopped += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnStopped);
break;
case EventType.MediaPlayerForward:
_mediaPlayerForward += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnForward);
break;
case EventType.MediaPlayerBackward:
_mediaPlayerBackward += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnBackward);
break;
case EventType.MediaPlayerEndReached:
_mediaPlayerEndReached += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnEndReached);
break;
case EventType.MediaPlayerEncounteredError:
_mediaPlayerEncounteredError += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnEncounteredError);
break;
case EventType.MediaPlayerTimeChanged:
_mediaPlayerTimeChanged += eventHandler as EventHandler<MediaPlayerTimeChangedEventArgs>;
AttachNativeEvent(eventType, OnTimeChanged);
break;
case EventType.MediaPlayerSeekableChanged:
_mediaPlayerSeekableChanged += eventHandler as EventHandler<MediaPlayerSeekableChangedEventArgs>;
AttachNativeEvent(eventType, OnSeekableChanged);
break;
case EventType.MediaPlayerPausableChanged:
_mediaPlayerPausableChanged += eventHandler as EventHandler<MediaPlayerPausableChangedEventArgs>;
AttachNativeEvent(eventType, OnPausableChanged);
break;
case EventType.MediaPlayerTitleChanged:
_mediaPlayerTitleChanged += eventHandler as EventHandler<MediaPlayerTitleChangedEventArgs>;
AttachNativeEvent(eventType, OnTitleChanged);
break;
case EventType.MediaPlayerChapterChanged:
_mediaPlayerChapterChanged += eventHandler as EventHandler<MediaPlayerChapterChangedEventArgs>;
AttachNativeEvent(eventType, OnChapterChanged);
break;
case EventType.MediaPlayerSnapshotTaken:
_mediaPlayerSnapshotTaken += eventHandler as EventHandler<MediaPlayerSnapshotTakenEventArgs>;
AttachNativeEvent(eventType, OnSnapshotTaken);
break;
case EventType.MediaPlayerLengthChanged:
_mediaPlayerLengthChanged += eventHandler as EventHandler<MediaPlayerLengthChangedEventArgs>;
AttachNativeEvent(eventType, OnLengthChanged);
break;
case EventType.MediaPlayerVout:
_mediaPlayerVout += eventHandler as EventHandler<MediaPlayerVoutEventArgs>;
AttachNativeEvent(eventType, OnVout);