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

Expose events on main objects

parent 4e4c0be0
...@@ -31,7 +31,7 @@ namespace LibVLCSharp.Shared ...@@ -31,7 +31,7 @@ namespace LibVLCSharp.Shared
NativeReference = ptr; NativeReference = ptr;
} }
internal protected void AttachNativeEvent(EventType eventType, EventCallback eventCallback) protected void AttachNativeEvent(EventType eventType, EventCallback eventCallback)
{ {
_callbacks.Add(eventCallback); _callbacks.Add(eventCallback);
if (Internal.LibVLCEventAttach(NativeReference, eventType, eventCallback, IntPtr.Zero) != 0) if (Internal.LibVLCEventAttach(NativeReference, eventType, eventCallback, IntPtr.Zero) != 0)
...@@ -41,7 +41,7 @@ namespace LibVLCSharp.Shared ...@@ -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); _callbacks.Remove(eventCallback);
...@@ -55,10 +55,8 @@ namespace LibVLCSharp.Shared ...@@ -55,10 +55,8 @@ namespace LibVLCSharp.Shared
#endif #endif
internal protected void OnEventUnhandled(object sender, EventType eventType) 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 AttachEvent<T>(EventType eventType, EventHandler<T> eventHandler) where T : EventArgs;
internal protected abstract void DetachEvent<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 ...@@ -818,6 +818,52 @@ namespace LibVLCSharp.Shared
} }
#endregion #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 #region Callbacks
......
...@@ -131,6 +131,9 @@ namespace LibVLCSharp.Shared ...@@ -131,6 +131,9 @@ namespace LibVLCSharp.Shared
/// </summary> /// </summary>
public bool IsRunning => Native.LibVLCMediaDiscovererIsRunning(NativeReference) != 0; public bool IsRunning => Native.LibVLCMediaDiscovererIsRunning(NativeReference) != 0;
/// <summary>
/// The MediaList attached to this MediaDiscoverer
/// </summary>
public MediaList MediaList public MediaList MediaList
{ {
get get
...@@ -144,5 +147,21 @@ namespace LibVLCSharp.Shared ...@@ -144,5 +147,21 @@ namespace LibVLCSharp.Shared
return _mediaList; 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 ...@@ -287,5 +287,39 @@ namespace LibVLCSharp.Shared
return _eventManager; 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
...@@ -39,7 +39,7 @@ namespace LibVLCSharp.Shared ...@@ -39,7 +39,7 @@ namespace LibVLCSharp.Shared
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_media_player_event_manager")] EntryPoint = "libvlc_media_player_event_manager")]
internal static extern IntPtr LibVLCMediaPlayerEventManager(IntPtr mediaPlayer); internal static extern IntPtr LibVLCMediaPlayerEventManager(IntPtr mediaPlayer);
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_media_player_is_playing")] EntryPoint = "libvlc_media_player_is_playing")]
...@@ -134,7 +134,7 @@ namespace LibVLCSharp.Shared ...@@ -134,7 +134,7 @@ namespace LibVLCSharp.Shared
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_media_player_get_chapter_count")] EntryPoint = "libvlc_media_player_get_chapter_count")]
internal static extern int LibVLCMediaPlayerGetChapterCount(IntPtr mediaPlayer); internal static extern int LibVLCMediaPlayerGetChapterCount(IntPtr mediaPlayer);
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_media_player_will_play")] EntryPoint = "libvlc_media_player_will_play")]
...@@ -229,7 +229,7 @@ namespace LibVLCSharp.Shared ...@@ -229,7 +229,7 @@ namespace LibVLCSharp.Shared
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_toggle_fullscreen")] EntryPoint = "libvlc_toggle_fullscreen")]
internal static extern void LibVLCToggleFullscreen(IntPtr mediaPlayer); internal static extern void LibVLCToggleFullscreen(IntPtr mediaPlayer);
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_set_fullscreen")] EntryPoint = "libvlc_set_fullscreen")]
...@@ -253,7 +253,7 @@ namespace LibVLCSharp.Shared ...@@ -253,7 +253,7 @@ namespace LibVLCSharp.Shared
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_audio_set_callbacks")] EntryPoint = "libvlc_audio_set_callbacks")]
internal static extern void LibVLCAudioSetCallbacks(IntPtr mediaPlayer, LibVLCAudioPlayCb play, LibVLCAudioPauseCb pause, internal static extern void LibVLCAudioSetCallbacks(IntPtr mediaPlayer, LibVLCAudioPlayCb play, LibVLCAudioPauseCb pause,
LibVLCAudioResumeCb resume, LibVLCAudioFlushCb flush, LibVLCAudioDrainCb drain, IntPtr opaque); LibVLCAudioResumeCb resume, LibVLCAudioFlushCb flush, LibVLCAudioDrainCb drain, IntPtr opaque);
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
...@@ -269,8 +269,8 @@ namespace LibVLCSharp.Shared ...@@ -269,8 +269,8 @@ namespace LibVLCSharp.Shared
// TODO: UTF8 // TODO: UTF8
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_audio_set_format")] EntryPoint = "libvlc_audio_set_format")]
internal static extern void LibVLCAudioSetFormat(IntPtr mediaPlayer, [MarshalAs(UnmanagedType.LPStr)] string format, internal static extern void LibVLCAudioSetFormat(IntPtr mediaPlayer, [MarshalAs(UnmanagedType.LPStr)] string format,
uint rate, uint channels); uint rate, uint channels);
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
...@@ -282,7 +282,7 @@ namespace LibVLCSharp.Shared ...@@ -282,7 +282,7 @@ namespace LibVLCSharp.Shared
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_audio_output_device_set")] EntryPoint = "libvlc_audio_output_device_set")]
internal static extern void LibVLCAudioOutputDeviceSet(IntPtr mediaPlayer, [MarshalAs(UnmanagedType.LPStr)] string module, internal static extern void LibVLCAudioOutputDeviceSet(IntPtr mediaPlayer, [MarshalAs(UnmanagedType.LPStr)] string module,
[MarshalAs(UnmanagedType.LPStr)] string deviceId); [MarshalAs(UnmanagedType.LPStr)] string deviceId);
// TODO: UTF8 // TODO: UTF8
...@@ -359,20 +359,20 @@ namespace LibVLCSharp.Shared ...@@ -359,20 +359,20 @@ namespace LibVLCSharp.Shared
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_video_set_callbacks")] EntryPoint = "libvlc_video_set_callbacks")]
internal static extern void LibVLCVideoSetCallbacks(IntPtr mediaPlayer, LibVLCVideoLockCb lockCallback, internal static extern void LibVLCVideoSetCallbacks(IntPtr mediaPlayer, LibVLCVideoLockCb lockCallback,
LibVLCVideoUnlockCb unlock, LibVLCVideoDisplayCb display, IntPtr opaque); LibVLCVideoUnlockCb unlock, LibVLCVideoDisplayCb display, IntPtr opaque);
//TODO: UTF8 //TODO: UTF8
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_video_set_format")] EntryPoint = "libvlc_video_set_format")]
internal static extern void LibVLCVideoSetFormat(IntPtr mediaPlayer, [MarshalAs(UnmanagedType.LPStr)] string chroma, internal static extern void LibVLCVideoSetFormat(IntPtr mediaPlayer, [MarshalAs(UnmanagedType.LPStr)] string chroma,
uint width, uint height, uint pitch); uint width, uint height, uint pitch);
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_video_set_format_callbacks")] EntryPoint = "libvlc_video_set_format_callbacks")]
internal static extern void LibVLCVideoSetFormatCallbacks(IntPtr mediaPlayer, LibVLCVideoFormatCb setup, internal static extern void LibVLCVideoSetFormatCallbacks(IntPtr mediaPlayer, LibVLCVideoFormatCb setup,
LibVLCVideoCleanupCb cleanup); LibVLCVideoCleanupCb cleanup);
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
...@@ -415,7 +415,7 @@ namespace LibVLCSharp.Shared ...@@ -415,7 +415,7 @@ namespace LibVLCSharp.Shared
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_video_set_aspect_ratio")] EntryPoint = "libvlc_video_set_aspect_ratio")]
internal static extern void LibVLCVideoSetAspectRatio(IntPtr mediaPlayer, [MarshalAs(UnmanagedType.LPStr)] string aspect); internal static extern void LibVLCVideoSetAspectRatio(IntPtr mediaPlayer, [MarshalAs(UnmanagedType.LPStr)] string aspect);
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_video_get_spu")] EntryPoint = "libvlc_video_get_spu")]
...@@ -462,7 +462,7 @@ namespace LibVLCSharp.Shared ...@@ -462,7 +462,7 @@ namespace LibVLCSharp.Shared
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_media_player_get_full_title_descriptions")] EntryPoint = "libvlc_media_player_get_full_title_descriptions")]
internal static extern int LibVLCMediaPlayerGetFullTitleDescriptions(IntPtr mediaPlayer, IntPtr titles); internal static extern int LibVLCMediaPlayerGetFullTitleDescriptions(IntPtr mediaPlayer, IntPtr titles);
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_video_get_chapter_description")] EntryPoint = "libvlc_video_get_chapter_description")]
...@@ -483,7 +483,7 @@ namespace LibVLCSharp.Shared ...@@ -483,7 +483,7 @@ namespace LibVLCSharp.Shared
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_chapter_descriptions_release")] EntryPoint = "libvlc_chapter_descriptions_release")]
internal static extern void LibVLCChapterDescriptionsRelease(IntPtr chapters, uint count); internal static extern void LibVLCChapterDescriptionsRelease(IntPtr chapters, uint count);
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_video_get_crop_geometry")] EntryPoint = "libvlc_video_get_crop_geometry")]
...@@ -494,7 +494,7 @@ namespace LibVLCSharp.Shared ...@@ -494,7 +494,7 @@ namespace LibVLCSharp.Shared
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_video_set_crop_geometry")] EntryPoint = "libvlc_video_set_crop_geometry")]
internal static extern void LibVLCVideoSetCropGeometry(IntPtr mediaPlayer, [MarshalAs(UnmanagedType.LPStr)] string geometry); internal static extern void LibVLCVideoSetCropGeometry(IntPtr mediaPlayer, [MarshalAs(UnmanagedType.LPStr)] string geometry);
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_video_get_teletext")] EntryPoint = "libvlc_video_get_teletext")]
...@@ -524,12 +524,12 @@ namespace LibVLCSharp.Shared ...@@ -524,12 +524,12 @@ namespace LibVLCSharp.Shared
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_video_set_track")] EntryPoint = "libvlc_video_set_track")]
internal static extern int LibVLCVideoSetTrack(IntPtr mediaPlayer, int track); internal static extern int LibVLCVideoSetTrack(IntPtr mediaPlayer, int track);
// TODO: UTF8 // TODO: UTF8
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_video_take_snapshot")] EntryPoint = "libvlc_video_take_snapshot")]
internal static extern int LibVLCVideoTakeSnapshot(IntPtr mediaPlayer, uint num, internal static extern int LibVLCVideoTakeSnapshot(IntPtr mediaPlayer, uint num,
[MarshalAs(UnmanagedType.LPStr)] string filepath, uint width, uint height); [MarshalAs(UnmanagedType.LPStr)] string filepath, uint width, uint height);
// TODO: UTF8 // TODO: UTF8
...@@ -558,7 +558,7 @@ namespace LibVLCSharp.Shared ...@@ -558,7 +558,7 @@ namespace LibVLCSharp.Shared
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_video_set_marquee_string")] EntryPoint = "libvlc_video_set_marquee_string")]
internal static extern void LibVLCVideoSetMarqueeString(IntPtr mediaPlayer, VideoMarqueeOption option, [MarshalAs(UnmanagedType.LPStr)] string marqueeValue); internal static extern void LibVLCVideoSetMarqueeString(IntPtr mediaPlayer, VideoMarqueeOption option, [MarshalAs(UnmanagedType.LPStr)] string marqueeValue);
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_video_get_logo_int")] EntryPoint = "libvlc_video_get_logo_int")]
...@@ -573,7 +573,7 @@ namespace LibVLCSharp.Shared ...@@ -573,7 +573,7 @@ namespace LibVLCSharp.Shared
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_video_set_logo_string")] EntryPoint = "libvlc_video_set_logo_string")]
internal static extern void LibVLCVideoSetLogoString(IntPtr mediaPlayer, VideoLogoOption option, internal static extern void LibVLCVideoSetLogoString(IntPtr mediaPlayer, VideoLogoOption option,
[MarshalAs(UnmanagedType.LPStr)] string logoOptionValue); [MarshalAs(UnmanagedType.LPStr)] string logoOptionValue);
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
...@@ -595,19 +595,19 @@ namespace LibVLCSharp.Shared ...@@ -595,19 +595,19 @@ namespace LibVLCSharp.Shared
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_video_set_adjust_float")] EntryPoint = "libvlc_video_set_adjust_float")]
internal static extern void LibVLCVideoSetAdjustFloat(IntPtr mediaPlayer, VideoAdjustOption option, float value); internal static extern void LibVLCVideoSetAdjustFloat(IntPtr mediaPlayer, VideoAdjustOption option, float value);
//TODO: UTF8 //TODO: UTF8
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_media_player_add_slave")] EntryPoint = "libvlc_media_player_add_slave")]
internal static extern int LibVLCMediaPlayerAddSlave(IntPtr mediaPlayer, MediaSlaveType mediaSlaveType, internal static extern int LibVLCMediaPlayerAddSlave(IntPtr mediaPlayer, MediaSlaveType mediaSlaveType,
[MarshalAs(UnmanagedType.LPStr)] string uri, bool selectWhenloaded); [MarshalAs(UnmanagedType.LPStr)] string uri, bool selectWhenloaded);
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_video_update_viewpoint")] EntryPoint = "libvlc_video_update_viewpoint")]
internal static extern int LibVLCVideoUpdateViewpoint(IntPtr mediaPlayer, VideoViewpoint viewpoint, bool absolute); internal static extern int LibVLCVideoUpdateViewpoint(IntPtr mediaPlayer, VideoViewpoint viewpoint, bool absolute);
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_track_description_list_release")] EntryPoint = "libvlc_track_description_list_release")]
...@@ -630,7 +630,7 @@ namespace LibVLCSharp.Shared ...@@ -630,7 +630,7 @@ namespace LibVLCSharp.Shared
internal static extern void LibVLCMediaPlayerSetAndroidContext(IntPtr mediaPlayer, IntPtr aWindow); internal static extern void LibVLCMediaPlayerSetAndroidContext(IntPtr mediaPlayer, IntPtr aWindow);
#endif #endif
} }
MediaPlayerEventManager _eventManager; MediaPlayerEventManager _eventManager;
/// <summary>Create an empty Media Player object</summary> /// <summary>Create an empty Media Player object</summary>
...@@ -639,7 +639,7 @@ namespace LibVLCSharp.Shared ...@@ -639,7 +639,7 @@ namespace LibVLCSharp.Shared
/// <para>should be created.</para> /// <para>should be created.</para>
/// </param> /// </param>
/// <returns>a new media player object, or NULL on error.</returns> /// <returns>a new media player object, or NULL on error.</returns>
public MediaPlayer(LibVLC libVLC) public MediaPlayer(LibVLC libVLC)
: base(() => Native.LibVLCMediaPlayerNew(libVLC.NativeReference), Native.LibVLCMediaPlayerRelease) : base(() => Native.LibVLCMediaPlayerNew(libVLC.NativeReference), Native.LibVLCMediaPlayerRelease)
{ {
} }
...@@ -654,7 +654,7 @@ namespace LibVLCSharp.Shared ...@@ -654,7 +654,7 @@ namespace LibVLCSharp.Shared
: base(() => Native.LibVLCMediaPlayerNewFromMedia(media.NativeReference), Native.LibVLCMediaPlayerRelease) : base(() => Native.LibVLCMediaPlayerNewFromMedia(media.NativeReference), Native.LibVLCMediaPlayerRelease)
{ {
} }
/// <summary> /// <summary>
/// Get the media used by the media_player. /// Get the media used by the media_player.
/// Set the media that will be used by the media_player. /// Set the media that will be used by the media_player.
...@@ -852,7 +852,7 @@ namespace LibVLCSharp.Shared ...@@ -852,7 +852,7 @@ namespace LibVLCSharp.Shared
/// </summary> /// </summary>
public void PreviousChapter() public void PreviousChapter()
{ {
Native.LibVLCMediaPlayerPreviousChapter(NativeReference); Native.LibVLCMediaPlayerPreviousChapter(NativeReference);
} }
/// <summary> /// <summary>
...@@ -898,8 +898,8 @@ namespace LibVLCSharp.Shared ...@@ -898,8 +898,8 @@ namespace LibVLCSharp.Shared
public float Fps public float Fps
{ {
get { _fps = Native.LibVLCMediaPlayerGetFps(NativeReference); return _fps; } get { _fps = Native.LibVLCMediaPlayerGetFps(NativeReference); return _fps; }
} }
/// <summary> /// <summary>
/// Get the number of video outputs /// Get the number of video outputs
/// </summary> /// </summary>
...@@ -1056,7 +1056,7 @@ namespace LibVLCSharp.Shared ...@@ -1056,7 +1056,7 @@ namespace LibVLCSharp.Shared
/// <param name="channels">channels count</param> /// <param name="channels">channels count</param>
public void SetAudioFormat(string format, uint rate, uint channels) public void SetAudioFormat(string format, uint rate, uint channels)
{ {
Native.LibVLCAudioSetFormat(NativeReference, format, rate, channels); Native.LibVLCAudioSetFormat(NativeReference, format, rate, channels);
} }
/// <summary> /// <summary>
...@@ -1146,7 +1146,7 @@ namespace LibVLCSharp.Shared ...@@ -1146,7 +1146,7 @@ namespace LibVLCSharp.Shared
var track = Marshal.PtrToStructure<TrackDescription>(trackPtr); var track = Marshal.PtrToStructure<TrackDescription>(trackPtr);
while (true) while (true)
{ {
trackDescriptions.Add(track); trackDescriptions.Add(track);
if (track.Next != IntPtr.Zero) if (track.Next != IntPtr.Zero)
{ {
...@@ -1154,7 +1154,7 @@ namespace LibVLCSharp.Shared ...@@ -1154,7 +1154,7 @@ namespace LibVLCSharp.Shared
} }
else else
{ {
break; break;
} }
} }
return trackDescriptions.ToArray(); return trackDescriptions.ToArray();
...@@ -1349,7 +1349,7 @@ namespace LibVLCSharp.Shared ...@@ -1349,7 +1349,7 @@ namespace LibVLCSharp.Shared
public bool SetSpu(int spu) public bool SetSpu(int spu)
{ {
return Native.LibVLCVideoSetSpu(NativeReference, spu) == 0; return Native.LibVLCVideoSetSpu(NativeReference, spu) == 0;
} }
public int SpuCount => Native.LibVLCVideoGetSpuCount(NativeReference); public int SpuCount => Native.LibVLCVideoGetSpuCount(NativeReference);
...@@ -1461,7 +1461,7 @@ namespace LibVLCSharp.Shared ...@@ -1461,7 +1461,7 @@ namespace LibVLCSharp.Shared
/// <param name="width">the snapshot's width</param> /// <param name="width">the snapshot's width</param>
/// <param name="height">the snapshot's height</param> /// <param name="height">the snapshot's height</param>
/// <returns>true on success</returns> /// <returns>true on success</returns>
public bool TakeSnapshot(uint num, string filePath, uint width, uint height) => public bool TakeSnapshot(uint num, string filePath, uint width, uint height) =>
Native.LibVLCVideoTakeSnapshot(NativeReference, num, filePath, width, height) == 0; Native.LibVLCVideoTakeSnapshot(NativeReference, num, filePath, width, height) == 0;
/// <summary> /// <summary>
...@@ -1584,15 +1584,15 @@ namespace LibVLCSharp.Shared ...@@ -1584,15 +1584,15 @@ namespace LibVLCSharp.Shared
public bool SetRenderer(RendererItem rendererItem) => public bool SetRenderer(RendererItem rendererItem) =>
Native.LibVLCMediaPlayerSetRenderer(NativeReference, rendererItem.NativeReference) == 0; Native.LibVLCMediaPlayerSetRenderer(NativeReference, rendererItem.NativeReference) == 0;
#region Enums #region Enums
#endregion
#region Callbacks #endregion
#region Callbacks
/// <summary> /// <summary>
/// <para>A LibVLC media player plays one media (usually in a custom drawable).</para> /// <para>A LibVLC media player plays one media (usually in a custom drawable).</para>
/// <para>@{</para> /// <para>@{</para>
...@@ -1677,7 +1677,7 @@ namespace LibVLCSharp.Shared ...@@ -1677,7 +1677,7 @@ namespace LibVLCSharp.Shared
/// <para>in the video decoders, video filters and/or video converters.</para> /// <para>in the video decoders, video filters and/or video converters.</para>
/// </remarks> /// </remarks>
[SuppressUnmanagedCodeSecurity, UnmanagedFunctionPointer(CallingConvention.Cdecl)] [SuppressUnmanagedCodeSecurity, UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate uint LibVLCVideoFormatCb(ref IntPtr userData, IntPtr chroma, ref uint width, public delegate uint LibVLCVideoFormatCb(ref IntPtr userData, IntPtr chroma, ref uint width,
ref uint height, ref uint pitches, ref uint lines); ref uint height, ref uint pitches, ref uint lines);
/// <summary>Callback prototype to configure picture buffers format.</summary> /// <summary>Callback prototype to configure picture buffers format.</summary>
...@@ -1776,9 +1776,8 @@ namespace LibVLCSharp.Shared ...@@ -1776,9 +1776,8 @@ namespace LibVLCSharp.Shared
[SuppressUnmanagedCodeSecurity, UnmanagedFunctionPointer(CallingConvention.Cdecl)] [SuppressUnmanagedCodeSecurity, UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void LibVLCVolumeCb(IntPtr data, float volume, [MarshalAs(UnmanagedType.I1)] bool mute); public delegate void LibVLCVolumeCb(IntPtr data, float volume, [MarshalAs(UnmanagedType.I1)] bool mute);
#endregion #endregion
#region events
/// <summary> /// <summary>
/// Get the Event Manager from which the media player send event. /// Get the Event Manager from which the media player send event.
/// </summary> /// </summary>
...@@ -1795,17 +1794,188 @@ namespace LibVLCSharp.Shared ...@@ -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