...
 
Commits (5)
......@@ -2,6 +2,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Threading.Tasks;
using LibVLCSharp.Shared;
using NUnit.Framework;
......@@ -76,5 +77,84 @@ namespace LibVLCSharp.Tests
Assert.True(called);
Assert.True(mp.IsPlaying);
}
int callCountRegisterOne = 0;
int callCountRegisterTwo = 0;
[Test]
public async Task EventFireOnceForeachRegistration()
{
try
{
var libVLC = new LibVLC();
var media = new Media(libVLC, "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4", Media.FromType.FromLocation);
var mp = new MediaPlayer(media);
mp.Playing += Mp_Playing;
mp.Playing += Mp_Playing1;
Debug.WriteLine("first play");
mp.Play();
await Task.Delay(2000);
Assert.AreEqual(callCountRegisterOne, 1);
Assert.AreEqual(callCountRegisterTwo, 1);
callCountRegisterOne = 0;
callCountRegisterTwo = 0;
mp.Stop();
mp.Playing -= Mp_Playing;
Debug.WriteLine("second play");
mp.Play();
await Task.Delay(2000);
Assert.AreEqual(callCountRegisterOne, 0);
Assert.AreEqual(callCountRegisterTwo, 1);
// mp.Stop();
mp.Playing -= Mp_Playing1; // native crash in detach?
callCountRegisterOne = 0;
callCountRegisterTwo = 0;
Debug.WriteLine("third play");
mp.Play();
await Task.Delay(500);
Assert.AreEqual(callCountRegisterOne, 0);
Assert.AreEqual(callCountRegisterTwo, 0);
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
void Mp_Playing1(object sender, EventArgs e)
{
callCountRegisterTwo++;
Debug.WriteLine($"Mp_Playing1 called with {callCountRegisterTwo}");
}
void Mp_Playing(object sender, EventArgs e)
{
callCountRegisterOne++;
Debug.WriteLine($"Mp_Playing called with {callCountRegisterOne}");
}
}
}
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Security;
......@@ -29,7 +30,7 @@ namespace LibVLCSharp.Shared
NativeReference = ptr;
}
protected void AttachNativeEvent(EventType eventType, EventCallback eventCallback)
private void AttachNativeEvent(EventType eventType, EventCallback eventCallback)
{
_callbacks.Add(eventCallback);
if (Internal.LibVLCEventAttach(NativeReference, eventType, eventCallback, IntPtr.Zero) != 0)
......@@ -39,13 +40,39 @@ namespace LibVLCSharp.Shared
}
}
protected void DetachNativeEvent(EventType eventType, EventCallback eventCallback)
private void DetachNativeEvent(EventType eventType, EventCallback eventCallback)
{
_callbacks.Remove(eventCallback);
Internal.LibVLCEventDetach(NativeReference, eventType, eventCallback, IntPtr.Zero);
}
protected void Attach(EventType eventType, ref int registrationCount, Action managedSubscribe, Func<EventCallback> setCallback)
{
managedSubscribe();
if (registrationCount == 0)
{
AttachNativeEvent(eventType, setCallback());
}
registrationCount++;
}
protected void Detach(EventType eventType, ref int registrationCount, Action managedUnsubscribe, ref EventCallback eventCallback)
{
if (registrationCount == 0) return;
registrationCount--;
managedUnsubscribe();
if (registrationCount == 0)
{
Debug.Assert(eventCallback != null);
DetachNativeEvent(eventType, eventCallback);
eventCallback = null;
}
}
#if IOS
internal protected static LibVLCEvent RetrieveEvent(IntPtr eventPtr) => MarshalUtils.PtrToStructure<LibVLCEvent>(eventPtr);
#else
......
......@@ -12,6 +12,13 @@ namespace LibVLCSharp.Shared
EventHandler<EventArgs> _mediaDiscovererStarted;
EventHandler<EventArgs> _mediaDiscovererStopped;
#endif
int _discovererStartedRegistrationCount;
int _discovererStoppedRegistrationCount;
EventCallback _discovererStartedCallback;
EventCallback _discovererStoppedCallback;
public MediaDiscovererEventManager(IntPtr ptr) : base(ptr)
{
}
......@@ -23,12 +30,16 @@ namespace LibVLCSharp.Shared
switch (eventType)
{
case EventType.MediaDiscovererStarted:
_mediaDiscovererStarted += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnStarted);
Attach(eventType,
ref _discovererStartedRegistrationCount,
() => _mediaDiscovererStarted += eventHandler as EventHandler<EventArgs>,
() => _discovererStartedCallback = OnStarted);
break;
case EventType.MediaDiscovererStopped:
_mediaDiscovererStopped += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnStopped);
Attach(eventType,
ref _discovererStoppedRegistrationCount,
() => _mediaDiscovererStopped += eventHandler as EventHandler<EventArgs>,
() => _discovererStoppedCallback = OnStopped);
break;
default:
OnEventUnhandled(this, eventType);
......@@ -44,12 +55,16 @@ namespace LibVLCSharp.Shared
switch (eventType)
{
case EventType.MediaDiscovererStarted:
_mediaDiscovererStarted -= eventHandler as EventHandler<EventArgs>;
DetachNativeEvent(eventType, OnStarted);
Detach(eventType,
ref _discovererStartedRegistrationCount,
() => _mediaDiscovererStarted -= eventHandler as EventHandler<EventArgs>,
ref _discovererStartedCallback);
break;
case EventType.MediaDiscovererStopped:
_mediaDiscovererStopped -= eventHandler as EventHandler<EventArgs>;
DetachNativeEvent(eventType, OnStopped);
Detach(eventType,
ref _discovererStoppedRegistrationCount,
() => _mediaDiscovererStopped -= eventHandler as EventHandler<EventArgs>,
ref _discovererStoppedCallback);
break;
default:
OnEventUnhandled(this, eventType);
......
......@@ -22,6 +22,23 @@ namespace LibVLCSharp.Shared
EventHandler<MediaStateChangedEventArgs> _mediaStateChanged;
EventHandler<MediaSubItemTreeAddedEventArgs> _mediaSubItemTreeAdded;
#endif
int _mediaMetaChangedRegistrationCount;
int _mediaParsedChangedRegistrationCount;
int _mediaSubItemChangedRegistrationCount;
int _mediaDurationChangedRegistrationCount;
int _mediaFreedRegistrationCount;
int _mediaStateChangedRegistrationCount;
int _mediaSubitemTreeAddedRegistrationCount;
EventCallback _mediaMetaChangedCallback;
EventCallback _mediaParsedChangedCallback;
EventCallback _mediaSubItemChangedCallback;
EventCallback _mediaDurationChangedCallback;
EventCallback _mediaFreedCallback;
EventCallback _mediaStateChangedCallback;
EventCallback _mediaSubitemTreeAddedCallback;
public MediaEventManager(IntPtr ptr) : base(ptr)
{
}
......@@ -33,32 +50,46 @@ namespace LibVLCSharp.Shared
switch (eventType)
{
case EventType.MediaMetaChanged:
_mediaMetaChanged += eventHandler as EventHandler<MediaMetaChangedEventArgs>;
AttachNativeEvent(eventType, OnMetaChanged);
Attach(eventType,
ref _mediaMetaChangedRegistrationCount,
() => _mediaMetaChanged += eventHandler as EventHandler<MediaMetaChangedEventArgs>,
() => _mediaMetaChangedCallback = OnMetaChanged);
break;
case EventType.MediaParsedChanged:
_mediaParsedChanged += eventHandler as EventHandler<MediaParsedChangedEventArgs>;
AttachNativeEvent(eventType, OnParsedChanged);
Attach(eventType,
ref _mediaParsedChangedRegistrationCount,
() => _mediaParsedChanged += eventHandler as EventHandler<MediaParsedChangedEventArgs>,
() => _mediaParsedChangedCallback = OnParsedChanged);
break;
case EventType.MediaSubItemAdded:
_mediaSubItemAdded += eventHandler as EventHandler<MediaSubItemAddedEventArgs>;
AttachNativeEvent(eventType, OnSubItemAdded);
Attach(eventType,
ref _mediaSubItemChangedRegistrationCount,
() => _mediaSubItemAdded += eventHandler as EventHandler<MediaSubItemAddedEventArgs>,
() => _mediaSubItemChangedCallback = OnSubItemAdded);
break;
case EventType.MediaDurationChanged:
_mediaDurationChanged += eventHandler as EventHandler<MediaDurationChangedEventArgs>;
AttachNativeEvent(eventType, OnDurationChanged);
Attach(eventType,
ref _mediaDurationChangedRegistrationCount,
() => _mediaDurationChanged += eventHandler as EventHandler<MediaDurationChangedEventArgs>,
() => _mediaDurationChangedCallback = OnDurationChanged);
break;
case EventType.MediaFreed:
_mediaFreed += eventHandler as EventHandler<MediaFreedEventArgs>;
AttachNativeEvent(eventType, OnMediaFreed);
Attach(eventType,
ref _mediaFreedRegistrationCount,
() => _mediaFreed += eventHandler as EventHandler<MediaFreedEventArgs>,
() => _mediaFreedCallback = OnMediaFreed);
break;
case EventType.MediaStateChanged:
_mediaStateChanged += eventHandler as EventHandler<MediaStateChangedEventArgs>;
AttachNativeEvent(eventType, OnMediaStateChanged);
Attach(eventType,
ref _mediaStateChangedRegistrationCount,
() => _mediaStateChanged += eventHandler as EventHandler<MediaStateChangedEventArgs>,
() => _mediaStateChangedCallback = OnMediaStateChanged);
break;
case EventType.MediaSubItemTreeAdded:
_mediaSubItemTreeAdded += eventHandler as EventHandler<MediaSubItemTreeAddedEventArgs>;
AttachNativeEvent(eventType, OnSubItemTreeAdded);
Attach(eventType,
ref _mediaSubitemTreeAddedRegistrationCount,
() => _mediaSubItemTreeAdded += eventHandler as EventHandler<MediaSubItemTreeAddedEventArgs>,
() => _mediaSubitemTreeAddedCallback = OnSubItemTreeAdded);
break;
default:
OnEventUnhandled(this, eventType);
......@@ -74,32 +105,46 @@ namespace LibVLCSharp.Shared
switch (eventType)
{
case EventType.MediaMetaChanged:
_mediaMetaChanged -= eventHandler as EventHandler<MediaMetaChangedEventArgs>;
DetachNativeEvent(eventType, OnMetaChanged);
Detach(eventType,
ref _mediaMetaChangedRegistrationCount,
() => _mediaMetaChanged -= eventHandler as EventHandler<MediaMetaChangedEventArgs>,
ref _mediaMetaChangedCallback);
break;
case EventType.MediaParsedChanged:
_mediaParsedChanged -= eventHandler as EventHandler<MediaParsedChangedEventArgs>;
DetachNativeEvent(eventType, OnParsedChanged);
Detach(eventType,
ref _mediaParsedChangedRegistrationCount,
() => _mediaParsedChanged -= eventHandler as EventHandler<MediaParsedChangedEventArgs>,
ref _mediaParsedChangedCallback);
break;
case EventType.MediaSubItemAdded:
_mediaSubItemAdded -= eventHandler as EventHandler<MediaSubItemAddedEventArgs>;
DetachNativeEvent(eventType, OnSubItemAdded);
Detach(eventType,
ref _mediaSubItemChangedRegistrationCount,
() => _mediaSubItemAdded -= eventHandler as EventHandler<MediaSubItemAddedEventArgs>,
ref _mediaSubItemChangedCallback);
break;
case EventType.MediaDurationChanged:
_mediaDurationChanged -= eventHandler as EventHandler<MediaDurationChangedEventArgs>;
DetachNativeEvent(eventType, OnDurationChanged);
Detach(eventType,
ref _mediaDurationChangedRegistrationCount,
() => _mediaDurationChanged -= eventHandler as EventHandler<MediaDurationChangedEventArgs>,
ref _mediaDurationChangedCallback);
break;
case EventType.MediaFreed:
_mediaFreed -= eventHandler as EventHandler<MediaFreedEventArgs>;
DetachNativeEvent(eventType, OnMediaFreed);
Detach(eventType,
ref _mediaFreedRegistrationCount,
() => _mediaFreed -= eventHandler as EventHandler<MediaFreedEventArgs>,
ref _mediaFreedCallback);
break;
case EventType.MediaStateChanged:
_mediaStateChanged -= eventHandler as EventHandler<MediaStateChangedEventArgs>;
DetachNativeEvent(eventType, OnMediaStateChanged);
Detach(eventType,
ref _mediaStateChangedRegistrationCount,
() => _mediaStateChanged -= eventHandler as EventHandler<MediaStateChangedEventArgs>,
ref _mediaStateChangedCallback);
break;
case EventType.MediaSubItemTreeAdded:
_mediaSubItemTreeAdded -= eventHandler as EventHandler<MediaSubItemTreeAddedEventArgs>;
DetachNativeEvent(eventType, OnSubItemTreeAdded);
Detach(eventType,
ref _mediaSubitemTreeAddedRegistrationCount,
() => _mediaSubItemTreeAdded -= eventHandler as EventHandler<MediaSubItemTreeAddedEventArgs>,
ref _mediaSubitemTreeAddedCallback);
break;
default:
OnEventUnhandled(this, eventType);
......
......@@ -19,6 +19,19 @@ namespace LibVLCSharp.Shared
EventHandler<EventArgs> _mediaListEndReached;
#endif
int _mediaListItemAddedRegistrationCount;
int _mediaListWillAddItemdRegistrationCount;
int _mediaListItemDeletedRegistrationCount;
int _mediaListWillDeleteItemRegistrationCount;
int _mediaListEndReachedRegistrationCount;
EventCallback _mediaListItemAddedCallback;
EventCallback _mediaListWillAddItemdCallback;
EventCallback _mediaListItemDeletedCallback;
EventCallback _mediaListWillDeleteItemCallback;
EventCallback _mediaListEndReachedCallback;
public MediaListEventManager(IntPtr ptr) : base(ptr)
{
}
......@@ -30,24 +43,34 @@ namespace LibVLCSharp.Shared
switch (eventType)
{
case EventType.MediaListItemAdded:
_mediaListItemAdded += eventHandler as EventHandler<MediaListItemAddedEventArgs>;
AttachNativeEvent(eventType, OnItemAdded);
Attach(eventType,
ref _mediaListItemAddedRegistrationCount,
() => _mediaListItemAdded += eventHandler as EventHandler<MediaListItemAddedEventArgs>,
() => _mediaListItemAddedCallback = OnItemAdded);
break;
case EventType.MediaListWillAddItem:
_mediaListWillAddItem += eventHandler as EventHandler<MediaListWillAddItemEventArgs>;
AttachNativeEvent(eventType, OnWillAddItem);
Attach(eventType,
ref _mediaListWillAddItemdRegistrationCount,
() => _mediaListWillAddItem += eventHandler as EventHandler<MediaListWillAddItemEventArgs>,
() => _mediaListWillAddItemdCallback = OnWillAddItem);
break;
case EventType.MediaListItemDeleted:
_mediaListItemDeleted += eventHandler as EventHandler<MediaListItemDeletedEventArgs>;
AttachNativeEvent(eventType, OnItemDeleted);
Attach(eventType,
ref _mediaListItemDeletedRegistrationCount,
() => _mediaListItemDeleted += eventHandler as EventHandler<MediaListItemDeletedEventArgs>,
() => _mediaListItemDeletedCallback = OnItemDeleted);
break;
case EventType.MediaListViewWillDeleteItem:
_mediaListWillDeleteItem += eventHandler as EventHandler<MediaListWillDeleteItemEventArgs>;
AttachNativeEvent(eventType, OnWillDeleteItem);
Attach(eventType,
ref _mediaListWillDeleteItemRegistrationCount,
() => _mediaListWillDeleteItem += eventHandler as EventHandler<MediaListWillDeleteItemEventArgs>,
() => _mediaListWillDeleteItemCallback = OnWillDeleteItem);
break;
case EventType.MediaListEndReached:
_mediaListEndReached += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnEndReached);
Attach(eventType,
ref _mediaListEndReachedRegistrationCount,
() => _mediaListEndReached += eventHandler as EventHandler<EventArgs>,
() => _mediaListEndReachedCallback = OnEndReached);
break;
default:
OnEventUnhandled(this, eventType);
......@@ -63,24 +86,34 @@ namespace LibVLCSharp.Shared
switch (eventType)
{
case EventType.MediaListItemAdded:
_mediaListItemAdded -= eventHandler as EventHandler<MediaListItemAddedEventArgs>;
DetachNativeEvent(eventType, OnItemAdded);
Detach(eventType,
ref _mediaListItemAddedRegistrationCount,
() => _mediaListItemAdded -= eventHandler as EventHandler<MediaListItemAddedEventArgs>,
ref _mediaListItemAddedCallback);
break;
case EventType.MediaListWillAddItem:
_mediaListWillAddItem -= eventHandler as EventHandler<MediaListWillAddItemEventArgs>;
DetachNativeEvent(eventType, OnWillAddItem);
Detach(eventType,
ref _mediaListWillAddItemdRegistrationCount,
() => _mediaListWillAddItem -= eventHandler as EventHandler<MediaListWillAddItemEventArgs>,
ref _mediaListWillAddItemdCallback);
break;
case EventType.MediaListItemDeleted:
_mediaListItemDeleted -= eventHandler as EventHandler<MediaListItemDeletedEventArgs>;
DetachNativeEvent(eventType, OnItemDeleted);
Detach(eventType,
ref _mediaListItemDeletedRegistrationCount,
() => _mediaListItemDeleted -= eventHandler as EventHandler<MediaListItemDeletedEventArgs>,
ref _mediaListItemDeletedCallback);
break;
case EventType.MediaListViewWillDeleteItem:
_mediaListWillDeleteItem -= eventHandler as EventHandler<MediaListWillDeleteItemEventArgs>;
DetachNativeEvent(eventType, OnWillDeleteItem);
Detach(eventType,
ref _mediaListWillDeleteItemRegistrationCount,
() => _mediaListWillDeleteItem -= eventHandler as EventHandler<MediaListWillDeleteItemEventArgs>,
ref _mediaListWillDeleteItemCallback);
break;
case EventType.MediaListEndReached:
_mediaListEndReached -= eventHandler as EventHandler<EventArgs>;
DetachNativeEvent(eventType, OnEndReached);
Detach(eventType,
ref _mediaListEndReachedRegistrationCount,
() => _mediaListEndReached -= eventHandler as EventHandler<EventArgs>,
ref _mediaListEndReachedCallback);
break;
default:
OnEventUnhandled(this, eventType);
......
......@@ -37,6 +37,7 @@ namespace LibVLCSharp.Shared
static EventHandler<EventArgs> _mediaPlayerUnmuted; // vlc 2.2
static EventHandler<MediaPlayerVolumeChangedEventArgs> _mediaPlayerVolumeChanged; // vlc 2.2
#else
EventHandler<MediaPlayerPositionChangedEventArgs> _mediaPlayerPositionChanged;
EventHandler<MediaPlayerMediaChangedEventArgs> _mediaPlayerMediaChanged;
EventHandler<EventArgs> _mediaPlayerNothingSpecial;
EventHandler<EventArgs> _mediaPlayerOpening;
......@@ -49,7 +50,6 @@ namespace LibVLCSharp.Shared
EventHandler<EventArgs> _mediaPlayerEndReached;
EventHandler<EventArgs> _mediaPlayerEncounteredError;
EventHandler<MediaPlayerTimeChangedEventArgs> _mediaPlayerTimeChanged;
EventHandler<MediaPlayerPositionChangedEventArgs> _mediaPlayerPositionChanged;
EventHandler<MediaPlayerSeekableChangedEventArgs> _mediaPlayerSeekableChanged;
EventHandler<MediaPlayerPausableChangedEventArgs> _mediaPlayerPausableChanged;
EventHandler<MediaPlayerTitleChangedEventArgs> _mediaPlayerTitleChanged;
......@@ -72,6 +72,68 @@ namespace LibVLCSharp.Shared
{
}
int _positionChangedRegistrationCount;
int _mediaChangedRegistrationCount;
int _nothingSpecialRegistrationCount;
int _openingRegistrationCount;
int _bufferingRegistrationCount;
int _playingRegistrationCount;
int _pausedRegistrationCount;
int _stoppedRegistrationCount;
int _forwardRegistrationCount;
int _backwardRegistrationCount;
int _endReachedRegistrationCount;
int _encounteredErrorRegistrationCount;
int _timeChangedRegistrationCount;
int _seekableChangedRegistrationCount;
int _pausableChangedRegistrationCount;
int _titleChangedChangedRegistrationCount;
int _chapterChangedRegistrationCount;
int _snapshotTakenRegistrationCount;
int _lengthChangedRegistrationCount;
int _voutRegistrationCount;
int _scrambledChangedRegistrationCount;
int _eSAddedRegistrationCount;
int _eSDeletedRegistrationCount;
int _eSSelectedRegistrationCount;
int _audioDeviceRegistrationCount;
int _corkedRegistrationCount;
int _uncorkedRegistrationCount;
int _mutedRegistrationCount;
int _unmutedRegistrationCount;
int _volumeChangedRegistrationCount;
EventCallback _positionChangedCallback;
EventCallback _mediaChangedCallback;
EventCallback _nothingSpecialCallback;
EventCallback _openingCallback;
EventCallback _bufferingCallback;
EventCallback _playingCallback;
EventCallback _pausedCallback;
EventCallback _stoppedCallback;
EventCallback _forwardCallback;
EventCallback _backwardCallback;
EventCallback _endReachedCallback;
EventCallback _encounteredErrorCallback;
EventCallback _timeChangedCallback;
EventCallback _seekableChangedCallback;
EventCallback _pausableChangedCallback;
EventCallback _titleChangedCallback;
EventCallback _chapterChangedCallback;
EventCallback _snapshotTakenCallback;
EventCallback _lengthChangedCallback;
EventCallback _voutCallback;
EventCallback _scrambledChangedCallback;
EventCallback _eSAddedCallback;
EventCallback _eSDeletedCallback;
EventCallback _eSSelectedCallback;
EventCallback _audioDeviceCallback;
EventCallback _corkedCallback;
EventCallback _uncorkedCallback;
EventCallback _mutedCallback;
EventCallback _unmutedCallback;
EventCallback _volumeChangedCallback;
protected internal override void AttachEvent<T>(EventType eventType, EventHandler<T> eventHandler)
{
lock(_lock)
......@@ -79,125 +141,185 @@ namespace LibVLCSharp.Shared
switch (eventType)
{
case EventType.MediaPlayerPositionChanged:
_mediaPlayerPositionChanged += eventHandler as EventHandler<MediaPlayerPositionChangedEventArgs>;
AttachNativeEvent(eventType, OnPositionChanged);
Attach(eventType,
ref _positionChangedRegistrationCount,
() => _mediaPlayerPositionChanged += eventHandler as EventHandler<MediaPlayerPositionChangedEventArgs>,
() => _positionChangedCallback = OnPositionChanged);
break;
case EventType.MediaPlayerMediaChanged:
_mediaPlayerMediaChanged += eventHandler as EventHandler<MediaPlayerMediaChangedEventArgs>;
AttachNativeEvent(eventType, OnMediaChanged);
Attach(eventType,
ref _mediaChangedRegistrationCount,
() => _mediaPlayerMediaChanged += eventHandler as EventHandler<MediaPlayerMediaChangedEventArgs>,
() => _mediaChangedCallback = OnMediaChanged);
break;
case EventType.MediaPlayerNothingSpecial:
_mediaPlayerNothingSpecial += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnNothingSpecial);
Attach(eventType,
ref _nothingSpecialRegistrationCount,
() => _mediaPlayerNothingSpecial += eventHandler as EventHandler<EventArgs>,
() => _nothingSpecialCallback = OnNothingSpecial);
break;
case EventType.MediaPlayerOpening:
_mediaPlayerOpening += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnOpening);
Attach(eventType,
ref _openingRegistrationCount,
() => _mediaPlayerOpening += eventHandler as EventHandler<EventArgs>,
() => _openingCallback = OnOpening);
break;
case EventType.MediaPlayerBuffering:
_mediaPlayerBuffering += eventHandler as EventHandler<MediaPlayerBufferingEventArgs>;
AttachNativeEvent(eventType, OnBuffering);
Attach(eventType,
ref _bufferingRegistrationCount,
() => _mediaPlayerBuffering += eventHandler as EventHandler<MediaPlayerBufferingEventArgs>,
() => _bufferingCallback = OnBuffering);
break;
case EventType.MediaPlayerPlaying:
_mediaPlayerPlaying += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnPlaying);
Attach(eventType,
ref _playingRegistrationCount,
() => _mediaPlayerPlaying += eventHandler as EventHandler<EventArgs>,
() => _playingCallback = OnPlaying);
break;
case EventType.MediaPlayerPaused:
_mediaPlayerPaused += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnPaused);
Attach(eventType,
ref _pausedRegistrationCount,
() => _mediaPlayerPaused += eventHandler as EventHandler<EventArgs>,
() => _pausedCallback = OnPaused);
break;
case EventType.MediaPlayerStopped:
_mediaPlayerStopped += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnStopped);
Attach(eventType,
ref _stoppedRegistrationCount,
() => _mediaPlayerStopped += eventHandler as EventHandler<EventArgs>,
() => _stoppedCallback = OnStopped);
break;
case EventType.MediaPlayerForward:
_mediaPlayerForward += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnForward);
Attach(eventType,
ref _forwardRegistrationCount,
() => _mediaPlayerForward += eventHandler as EventHandler<EventArgs>,
() => _forwardCallback = OnForward);
break;
case EventType.MediaPlayerBackward:
_mediaPlayerBackward += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnBackward);
Attach(eventType,
ref _backwardRegistrationCount,
() => _mediaPlayerBackward += eventHandler as EventHandler<EventArgs>,
() => _backwardCallback = OnBackward);
break;
case EventType.MediaPlayerEndReached:
_mediaPlayerEndReached += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnEndReached);
Attach(eventType,
ref _endReachedRegistrationCount,
() => _mediaPlayerEndReached += eventHandler as EventHandler<EventArgs>,
() => _endReachedCallback = OnEndReached);
break;
case EventType.MediaPlayerEncounteredError:
_mediaPlayerEncounteredError += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnEncounteredError);
Attach(eventType,
ref _encounteredErrorRegistrationCount,
() => _mediaPlayerEncounteredError += eventHandler as EventHandler<EventArgs>,
() => _encounteredErrorCallback = OnEncounteredError);
break;
case EventType.MediaPlayerTimeChanged:
_mediaPlayerTimeChanged += eventHandler as EventHandler<MediaPlayerTimeChangedEventArgs>;
AttachNativeEvent(eventType, OnTimeChanged);
Attach(eventType,
ref _timeChangedRegistrationCount,
() => _mediaPlayerTimeChanged += eventHandler as EventHandler<MediaPlayerTimeChangedEventArgs>,
() => _timeChangedCallback = OnTimeChanged);
break;
case EventType.MediaPlayerSeekableChanged:
_mediaPlayerSeekableChanged += eventHandler as EventHandler<MediaPlayerSeekableChangedEventArgs>;
AttachNativeEvent(eventType, OnSeekableChanged);
Attach(eventType,
ref _seekableChangedRegistrationCount,
() => _mediaPlayerSeekableChanged += eventHandler as EventHandler<MediaPlayerSeekableChangedEventArgs>,
() => _seekableChangedCallback = OnSeekableChanged);
break;
case EventType.MediaPlayerPausableChanged:
_mediaPlayerPausableChanged += eventHandler as EventHandler<MediaPlayerPausableChangedEventArgs>;
AttachNativeEvent(eventType, OnPausableChanged);
Attach(eventType,
ref _pausableChangedRegistrationCount,
() => _mediaPlayerPausableChanged += eventHandler as EventHandler<MediaPlayerPausableChangedEventArgs>,
() => _pausableChangedCallback = OnPausableChanged);
break;
case EventType.MediaPlayerTitleChanged:
_mediaPlayerTitleChanged += eventHandler as EventHandler<MediaPlayerTitleChangedEventArgs>;
AttachNativeEvent(eventType, OnTitleChanged);
Attach(eventType,
ref _titleChangedChangedRegistrationCount,
() => _mediaPlayerTitleChanged += eventHandler as EventHandler<MediaPlayerTitleChangedEventArgs>,
() => _titleChangedCallback = OnTitleChanged);
break;
case EventType.MediaPlayerChapterChanged:
_mediaPlayerChapterChanged += eventHandler as EventHandler<MediaPlayerChapterChangedEventArgs>;
AttachNativeEvent(eventType, OnChapterChanged);
Attach(eventType,
ref _chapterChangedRegistrationCount,
() => _mediaPlayerChapterChanged += eventHandler as EventHandler<MediaPlayerChapterChangedEventArgs>,
() => _chapterChangedCallback = OnChapterChanged);
break;
case EventType.MediaPlayerSnapshotTaken:
_mediaPlayerSnapshotTaken += eventHandler as EventHandler<MediaPlayerSnapshotTakenEventArgs>;
AttachNativeEvent(eventType, OnSnapshotTaken);
Attach(eventType,
ref _snapshotTakenRegistrationCount,
() => _mediaPlayerSnapshotTaken += eventHandler as EventHandler<MediaPlayerSnapshotTakenEventArgs>,
() => _snapshotTakenCallback = OnSnapshotTaken);
break;
case EventType.MediaPlayerLengthChanged:
_mediaPlayerLengthChanged += eventHandler as EventHandler<MediaPlayerLengthChangedEventArgs>;
AttachNativeEvent(eventType, OnLengthChanged);
Attach(eventType,
ref _lengthChangedRegistrationCount,
() => _mediaPlayerLengthChanged += eventHandler as EventHandler<MediaPlayerLengthChangedEventArgs>,
() => _lengthChangedCallback = OnLengthChanged);
break;
case EventType.MediaPlayerVout:
_mediaPlayerVout += eventHandler as EventHandler<MediaPlayerVoutEventArgs>;
AttachNativeEvent(eventType, OnVout);
Attach(eventType,
ref _voutRegistrationCount,
() => _mediaPlayerVout += eventHandler as EventHandler<MediaPlayerVoutEventArgs>,
() => _voutCallback = OnVout);
break;
case EventType.MediaPlayerScrambledChanged:
_mediaPlayerScrambledChanged += eventHandler as EventHandler<MediaPlayerScrambledChangedEventArgs>;
AttachNativeEvent(eventType, OnScrambledChanged);
Attach(eventType,
ref _scrambledChangedRegistrationCount,
() => _mediaPlayerScrambledChanged += eventHandler as EventHandler<MediaPlayerScrambledChangedEventArgs>,
() => _scrambledChangedCallback = OnScrambledChanged);
break;
case EventType.MediaPlayerESAdded:
_mediaPlayerESAdded += eventHandler as EventHandler<MediaPlayerESAddedEventArgs>;
AttachNativeEvent(eventType, OnESAdded);
Attach(eventType,
ref _eSAddedRegistrationCount,
() => _mediaPlayerESAdded += eventHandler as EventHandler<MediaPlayerESAddedEventArgs>,
() => _eSAddedCallback = OnESAdded);
break;
case EventType.MediaPlayerESDeleted:
_mediaPlayerESDeleted += eventHandler as EventHandler<MediaPlayerESDeletedEventArgs>;
AttachNativeEvent(eventType, OnESDeleted);
Attach(eventType,
ref _eSDeletedRegistrationCount,
() => _mediaPlayerESDeleted += eventHandler as EventHandler<MediaPlayerESDeletedEventArgs>,
() => _eSDeletedCallback = OnESDeleted);
break;
case EventType.MediaPlayerESSelected:
_mediaPlayerESSelected += eventHandler as EventHandler<MediaPlayerESSelectedEventArgs>;
AttachNativeEvent(eventType, OnESSelected);
break;
Attach(eventType,
ref _eSSelectedRegistrationCount,
() => _mediaPlayerESSelected += eventHandler as EventHandler<MediaPlayerESSelectedEventArgs>,
() => _eSSelectedCallback = OnESSelected);
break;
case EventType.MediaPlayerAudioDevice:
_mediaPlayerAudioDevice += eventHandler as EventHandler<MediaPlayerAudioDeviceEventArgs>;
AttachNativeEvent(eventType, OnAudioDevice);
break;
Attach(eventType,
ref _audioDeviceRegistrationCount,
() => _mediaPlayerAudioDevice += eventHandler as EventHandler<MediaPlayerAudioDeviceEventArgs>,
() => _audioDeviceCallback = OnAudioDevice);
break;
case EventType.MediaPlayerCorked:
_mediaPlayerCorked += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnCorked);
break;
Attach(eventType,
ref _corkedRegistrationCount,
() => _mediaPlayerCorked += eventHandler as EventHandler<EventArgs>,
() => _corkedCallback = OnCorked);
break;
case EventType.MediaPlayerUncorked:
_mediaPlayerUncorked += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnUncorked);
break;
Attach(eventType,
ref _uncorkedRegistrationCount,
() => _mediaPlayerUncorked += eventHandler as EventHandler<EventArgs>,
() => _uncorkedCallback = OnUncorked);
break;
case EventType.MediaPlayerMuted:
_mediaPlayerMuted += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnMuted);
break;
Attach(eventType,
ref _mutedRegistrationCount,
() => _mediaPlayerMuted += eventHandler as EventHandler<EventArgs>,
() => _mutedCallback = OnMuted);
break;
case EventType.MediaPlayerUnmuted:
_mediaPlayerUnmuted += eventHandler as EventHandler<EventArgs>;
AttachNativeEvent(eventType, OnUnmuted);
break;
Attach(eventType,
ref _unmutedRegistrationCount,
() => _mediaPlayerUnmuted += eventHandler as EventHandler<EventArgs>,
() => _unmutedCallback = OnUnmuted);
break;
case EventType.MediaPlayerAudioVolume:
_mediaPlayerVolumeChanged += eventHandler as EventHandler<MediaPlayerVolumeChangedEventArgs>;
AttachNativeEvent(eventType, OnVolumeChanged);
break;
Attach(eventType,
ref _volumeChangedRegistrationCount,
() => _mediaPlayerVolumeChanged += eventHandler as EventHandler<MediaPlayerVolumeChangedEventArgs>,
() => _volumeChangedCallback = OnVolumeChanged);
break;
default:
OnEventUnhandled(this, eventType);
break;
......@@ -212,124 +334,184 @@ namespace LibVLCSharp.Shared
switch (eventType)
{
case EventType.MediaPlayerPositionChanged:
_mediaPlayerPositionChanged -= eventHandler as EventHandler<MediaPlayerPositionChangedEventArgs>;
DetachNativeEvent(eventType, OnPositionChanged);
Detach(eventType,
ref _positionChangedRegistrationCount,
() => _mediaPlayerPositionChanged -= eventHandler as EventHandler<MediaPlayerPositionChangedEventArgs>,
ref _positionChangedCallback);
break;
case EventType.MediaPlayerMediaChanged:
_mediaPlayerMediaChanged -= eventHandler as EventHandler<MediaPlayerMediaChangedEventArgs>;
DetachNativeEvent(eventType, OnMediaChanged);
Detach(eventType,
ref _mediaChangedRegistrationCount,
() => _mediaPlayerMediaChanged -= eventHandler as EventHandler<MediaPlayerMediaChangedEventArgs>,
ref _mediaChangedCallback);
break;
case EventType.MediaPlayerNothingSpecial:
_mediaPlayerNothingSpecial -= eventHandler as EventHandler<EventArgs>;
DetachNativeEvent(eventType, OnNothingSpecial);
Detach(eventType,
ref _nothingSpecialRegistrationCount,
() => _mediaPlayerNothingSpecial -= eventHandler as EventHandler<EventArgs>,
ref _nothingSpecialCallback);
break;
case EventType.MediaPlayerOpening:
_mediaPlayerOpening -= eventHandler as EventHandler<EventArgs>;
DetachNativeEvent(eventType, OnOpening);
Detach(eventType,
ref _openingRegistrationCount,
() => _mediaPlayerOpening -= eventHandler as EventHandler<EventArgs>,
ref _openingCallback);
break;
case EventType.MediaPlayerBuffering:
_mediaPlayerBuffering -= eventHandler as EventHandler<MediaPlayerBufferingEventArgs>;
DetachNativeEvent(eventType, OnBuffering);
Detach(eventType,
ref _bufferingRegistrationCount,
() => _mediaPlayerBuffering -= eventHandler as EventHandler<MediaPlayerBufferingEventArgs>,
ref _bufferingCallback);
break;
case EventType.MediaPlayerPlaying:
_mediaPlayerPlaying -= eventHandler as EventHandler<EventArgs>;
DetachNativeEvent(eventType, OnPlaying);
Detach(eventType,
ref _playingRegistrationCount,
() => _mediaPlayerPlaying -= eventHandler as EventHandler<EventArgs>,
ref _playingCallback);
break;
case EventType.MediaPlayerPaused:
_mediaPlayerPaused -= eventHandler as EventHandler<EventArgs>;
DetachNativeEvent(eventType, OnPaused);
Detach(eventType,
ref _pausedRegistrationCount,
() => _mediaPlayerPaused -= eventHandler as EventHandler<EventArgs>,
ref _pausedCallback);
break;
case EventType.MediaPlayerStopped:
_mediaPlayerStopped -= eventHandler as EventHandler<EventArgs>;
DetachNativeEvent(eventType, OnStopped);
Detach(eventType,
ref _stoppedRegistrationCount,
() => _mediaPlayerStopped -= eventHandler as EventHandler<EventArgs>,
ref _stoppedCallback);
break;
case EventType.MediaPlayerForward:
_mediaPlayerForward -= eventHandler as EventHandler<EventArgs>;
DetachNativeEvent(eventType, OnForward);
Detach(eventType,
ref _forwardRegistrationCount,
() => _mediaPlayerForward -= eventHandler as EventHandler<EventArgs>,
ref _forwardCallback);
break;
case EventType.MediaPlayerBackward:
_mediaPlayerBackward -= eventHandler as EventHandler<EventArgs>;
DetachNativeEvent(eventType, OnBackward);
Detach(eventType,
ref _backwardRegistrationCount,
() => _mediaPlayerBackward -= eventHandler as EventHandler<EventArgs>,
ref _backwardCallback);
break;
case EventType.MediaPlayerEndReached:
_mediaPlayerEndReached -= eventHandler as EventHandler<EventArgs>;
DetachNativeEvent(eventType, OnEndReached);
Detach(eventType,
ref _endReachedRegistrationCount,
() => _mediaPlayerEndReached -= eventHandler as EventHandler<EventArgs>,
ref _endReachedCallback);
break;
case EventType.MediaPlayerEncounteredError:
_mediaPlayerEncounteredError -= eventHandler as EventHandler<EventArgs>;
DetachNativeEvent(eventType, OnEncounteredError);
Detach(eventType,
ref _encounteredErrorRegistrationCount,
() => _mediaPlayerEncounteredError -= eventHandler as EventHandler<EventArgs>,
ref _encounteredErrorCallback);
break;
case EventType.MediaPlayerTimeChanged:
_mediaPlayerTimeChanged -= eventHandler as EventHandler<MediaPlayerTimeChangedEventArgs>;
DetachNativeEvent(eventType, OnTimeChanged);
Detach(eventType,
ref _timeChangedRegistrationCount,
() => _mediaPlayerTimeChanged -= eventHandler as EventHandler<MediaPlayerTimeChangedEventArgs>,
ref _timeChangedCallback);
break;
case EventType.MediaPlayerSeekableChanged:
_mediaPlayerSeekableChanged -= eventHandler as EventHandler<MediaPlayerSeekableChangedEventArgs>;
DetachNativeEvent(eventType, OnSeekableChanged);
Detach(eventType,
ref _seekableChangedRegistrationCount,
() => _mediaPlayerSeekableChanged -= eventHandler as EventHandler<MediaPlayerSeekableChangedEventArgs>,
ref _seekableChangedCallback);
break;
case EventType.MediaPlayerPausableChanged:
_mediaPlayerPausableChanged -= eventHandler as EventHandler<MediaPlayerPausableChangedEventArgs>;
DetachNativeEvent(eventType, OnPausableChanged);
Detach(eventType,
ref _pausableChangedRegistrationCount,
() => _mediaPlayerPausableChanged -= eventHandler as EventHandler<MediaPlayerPausableChangedEventArgs>,
ref _pausableChangedCallback);
break;
case EventType.MediaPlayerTitleChanged:
_mediaPlayerTitleChanged -= eventHandler as EventHandler<MediaPlayerTitleChangedEventArgs>;
DetachNativeEvent(eventType, OnTitleChanged);
Detach(eventType,
ref _titleChangedChangedRegistrationCount,
() => _mediaPlayerTitleChanged -= eventHandler as EventHandler<MediaPlayerTitleChangedEventArgs>,
ref _titleChangedCallback);
break;
case EventType.MediaPlayerChapterChanged:
_mediaPlayerChapterChanged -= eventHandler as EventHandler<MediaPlayerChapterChangedEventArgs>;
DetachNativeEvent(eventType, OnChapterChanged);
Detach(eventType,
ref _chapterChangedRegistrationCount,
() => _mediaPlayerChapterChanged -= eventHandler as EventHandler<MediaPlayerChapterChangedEventArgs>,
ref _chapterChangedCallback);
break;
case EventType.MediaPlayerSnapshotTaken:
_mediaPlayerSnapshotTaken -= eventHandler as EventHandler<MediaPlayerSnapshotTakenEventArgs>;
DetachNativeEvent(eventType, OnSnapshotTaken);
Detach(eventType,
ref _snapshotTakenRegistrationCount,
() => _mediaPlayerSnapshotTaken -= eventHandler as EventHandler<MediaPlayerSnapshotTakenEventArgs>,
ref _snapshotTakenCallback);
break;
case EventType.MediaPlayerLengthChanged:
_mediaPlayerLengthChanged -= eventHandler as EventHandler<MediaPlayerLengthChangedEventArgs>;
DetachNativeEvent(eventType, OnLengthChanged);
Detach(eventType,
ref _lengthChangedRegistrationCount,
() => _mediaPlayerLengthChanged -= eventHandler as EventHandler<MediaPlayerLengthChangedEventArgs>,
ref _lengthChangedCallback);
break;
case EventType.MediaPlayerVout:
_mediaPlayerVout -= eventHandler as EventHandler<MediaPlayerVoutEventArgs>;
DetachNativeEvent(eventType, OnVout);
Detach(eventType,
ref _voutRegistrationCount,
() => _mediaPlayerVout -= eventHandler as EventHandler<MediaPlayerVoutEventArgs>,
ref _voutCallback);
break;
case EventType.MediaPlayerScrambledChanged:
_mediaPlayerScrambledChanged -= eventHandler as EventHandler<MediaPlayerScrambledChangedEventArgs>;
DetachNativeEvent(eventType, OnScrambledChanged);
Detach(eventType,
ref _scrambledChangedRegistrationCount,
() => _mediaPlayerScrambledChanged -= eventHandler as EventHandler<MediaPlayerScrambledChangedEventArgs>,
ref _scrambledChangedCallback);
break;
case EventType.MediaPlayerESAdded:
_mediaPlayerESAdded -= eventHandler as EventHandler<MediaPlayerESAddedEventArgs>;
DetachNativeEvent(eventType, OnESAdded);
Detach(eventType,
ref _eSAddedRegistrationCount,
() => _mediaPlayerESAdded -= eventHandler as EventHandler<MediaPlayerESAddedEventArgs>,
ref _eSAddedCallback);
break;
case EventType.MediaPlayerESDeleted:
_mediaPlayerESDeleted -= eventHandler as EventHandler<MediaPlayerESDeletedEventArgs>;
DetachNativeEvent(eventType, OnESDeleted);
Detach(eventType,
ref _eSDeletedRegistrationCount,
() => _mediaPlayerESDeleted -= eventHandler as EventHandler<MediaPlayerESDeletedEventArgs>,
ref _eSDeletedCallback);
break;
case EventType.MediaPlayerESSelected:
_mediaPlayerESSelected -= eventHandler as EventHandler<MediaPlayerESSelectedEventArgs>;
DetachNativeEvent(eventType, OnESSelected);
Detach(eventType,
ref _eSSelectedRegistrationCount,
() => _mediaPlayerESSelected -= eventHandler as EventHandler<MediaPlayerESSelectedEventArgs>,
ref _eSSelectedCallback);
break;
case EventType.MediaPlayerAudioDevice:
_mediaPlayerAudioDevice -= eventHandler as EventHandler<MediaPlayerAudioDeviceEventArgs>;
DetachNativeEvent(eventType, OnAudioDevice);
Detach(eventType,
ref _audioDeviceRegistrationCount,
() => _mediaPlayerAudioDevice -= eventHandler as EventHandler<MediaPlayerAudioDeviceEventArgs>,
ref _audioDeviceCallback);
break;
case EventType.MediaPlayerCorked:
_mediaPlayerCorked -= eventHandler as EventHandler<EventArgs>;
DetachNativeEvent(eventType, OnCorked);
Detach(eventType,
ref _corkedRegistrationCount,
() => _mediaPlayerCorked -= eventHandler as EventHandler<EventArgs>,
ref _corkedCallback);
break;
case EventType.MediaPlayerUncorked:
_mediaPlayerUncorked -= eventHandler as EventHandler<EventArgs>;
DetachNativeEvent(eventType, OnUncorked);
Detach(eventType,
ref _uncorkedRegistrationCount,
() => _mediaPlayerUncorked -= eventHandler as EventHandler<EventArgs>,
ref _uncorkedCallback);
break;
case EventType.MediaPlayerMuted:
_mediaPlayerMuted -= eventHandler as EventHandler<EventArgs>;
DetachNativeEvent(eventType, OnMuted);
Detach(eventType,
ref _mutedRegistrationCount,
() => _mediaPlayerMuted -= eventHandler as EventHandler<EventArgs>,
ref _mutedCallback);
break;
case EventType.MediaPlayerUnmuted:
_mediaPlayerUnmuted -= eventHandler as EventHandler<EventArgs>;
DetachNativeEvent(eventType, OnUnmuted);
Detach(eventType,
ref _unmutedRegistrationCount,
() => _mediaPlayerUnmuted -= eventHandler as EventHandler<EventArgs>,
ref _unmutedCallback);
break;
case EventType.MediaPlayerAudioVolume:
_mediaPlayerVolumeChanged -= eventHandler as EventHandler<MediaPlayerVolumeChangedEventArgs>;
DetachNativeEvent(eventType, OnVolumeChanged);
Detach(eventType,
ref _volumeChangedRegistrationCount,
() => _mediaPlayerVolumeChanged -= eventHandler as EventHandler<MediaPlayerVolumeChangedEventArgs>,
ref _volumeChangedCallback);
break;
default:
OnEventUnhandled(this, eventType);
......
......@@ -12,6 +12,13 @@ namespace LibVLCSharp.Shared
EventHandler<RendererDiscovererItemAddedEventArgs> _itemAdded;
EventHandler<RendererDiscovererItemDeletedEventArgs> _itemDeleted;
#endif
int _itemAddedRegistrationCount;
int _itemDeletedRegistrationCount;
EventCallback _itemAddedCallback;
EventCallback _itemDeletedCallback;
internal RendererDiscovererEventManager(IntPtr ptr) : base(ptr)
{
}
......@@ -23,12 +30,16 @@ namespace LibVLCSharp.Shared
switch(eventType)
{
case EventType.RendererDiscovererItemAdded:
_itemAdded += eventHandler as EventHandler<RendererDiscovererItemAddedEventArgs>;
AttachNativeEvent(eventType, OnItemAdded);
Attach(eventType,
ref _itemAddedRegistrationCount,
() => _itemAdded += eventHandler as EventHandler<RendererDiscovererItemAddedEventArgs>,
() => _itemAddedCallback = OnItemAdded);
break;
case EventType.RendererDiscovererItemDeleted:
_itemDeleted += eventHandler as EventHandler<RendererDiscovererItemDeletedEventArgs>;
AttachNativeEvent(eventType, OnItemDeleted);
Attach(eventType,
ref _itemDeletedRegistrationCount,
() => _itemDeleted += eventHandler as EventHandler<RendererDiscovererItemDeletedEventArgs>,
() => _itemDeletedCallback = OnItemDeleted);
break;
default:
OnEventUnhandled(this, eventType);
......@@ -44,12 +55,16 @@ namespace LibVLCSharp.Shared
switch (eventType)
{
case EventType.RendererDiscovererItemAdded:
_itemAdded -= eventHandler as EventHandler<RendererDiscovererItemAddedEventArgs>;
DetachNativeEvent(eventType, OnItemAdded);
Detach(eventType,
ref _itemAddedRegistrationCount,
() => _itemAdded -= eventHandler as EventHandler<RendererDiscovererItemAddedEventArgs>,
ref _itemAddedCallback);
break;
case EventType.RendererDiscovererItemDeleted:
_itemDeleted -= eventHandler as EventHandler<RendererDiscovererItemDeletedEventArgs>;
DetachNativeEvent(eventType, OnItemDeleted);
Detach(eventType,
ref _itemDeletedRegistrationCount,
() => _itemDeleted -= eventHandler as EventHandler<RendererDiscovererItemDeletedEventArgs>,
ref _itemDeletedCallback);
break;
default:
OnEventUnhandled(this, eventType);
......