Click here to Skip to main content
15,891,905 members
Articles / Web Development / HTML

nVLC

Rate me:
Please Sign up or sign in to vote.
4.94/5 (213 votes)
12 Feb 2018GPL316 min read 12.2M   69.9K   379  
A .NET API for the libVLC interface so the vast majority of VLC functionality could be utilized in managed applications
//    nVLC
//    
//    Author:  Roman Ginzburg
//
//    nVLC is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    nVLC is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//    GNU General Public License for more details.
//     
// ========================================================================

using System;
using Declarations.Events;
using Implementation.Media;
using LibVlcWrapper;

namespace Implementation.Events
{
    class MediaListEventManager : EventManager, IMediaListEvents
    {
        public MediaListEventManager(IEventProvider eventProvider)
            : base(eventProvider)
        {
        }

        protected override void MediaPlayerEventOccured(ref libvlc_event_t libvlc_event, IntPtr userData)
        {
            switch (libvlc_event.type)
            {
                case libvlc_event_e.libvlc_MediaListItemAdded:
                    if (m_itemAdded != null)
                    {
                        BasicMedia media = new BasicMedia(libvlc_event.MediaDescriptor.media_list_item_added.item, ReferenceCountAction.AddRef);
                        m_itemAdded(m_eventProvider, new MediaListItemAdded(media, libvlc_event.MediaDescriptor.media_list_item_added.index));
                        media.Release();
                    }
                    break;

                case libvlc_event_e.libvlc_MediaListWillAddItem:
                    if (m_willAddItem != null)
                    {
                        BasicMedia media2 = new BasicMedia(libvlc_event.MediaDescriptor.media_list_will_add_item.item, ReferenceCountAction.AddRef);
                        m_willAddItem(m_eventProvider, new MediaListWillAddItem(media2, libvlc_event.MediaDescriptor.media_list_will_add_item.index));
                        media2.Release();
                    }
                    break;

                case libvlc_event_e.libvlc_MediaListItemDeleted:
                    if (m_itemDeleted != null)
                    {
                        BasicMedia media3 = new BasicMedia(libvlc_event.MediaDescriptor.media_list_item_deleted.item, ReferenceCountAction.AddRef);
                        m_itemDeleted(m_eventProvider, new MediaListItemDeleted(media3, libvlc_event.MediaDescriptor.media_list_item_deleted.index));
                        media3.Release();
                    }
                    break;

                case libvlc_event_e.libvlc_MediaListWillDeleteItem:
                    if (m_willDeleteItem != null)
                    {
                        BasicMedia media4 = new BasicMedia(libvlc_event.MediaDescriptor.media_list_will_delete_item.item, ReferenceCountAction.AddRef);
                        m_willDeleteItem(m_eventProvider, new MediaListWillDeleteItem(media4, libvlc_event.MediaDescriptor.media_list_will_delete_item.index));
                        media4.Release();
                    }
                    break;
            }
        }

        #region IMediaListEvents Members

        event EventHandler<MediaListItemAdded> m_itemAdded;
        public event EventHandler<MediaListItemAdded> ItemAdded
        {
            add
            {
                if (m_itemAdded == null)
                {
                    Attach(libvlc_event_e.libvlc_MediaListItemAdded);
                }
                m_itemAdded += value;
            }
            remove
            {
                if (m_itemAdded != null)
                {
                    m_itemAdded -= value;
                    if (m_itemAdded == null)
                    {
                        Dettach(libvlc_event_e.libvlc_MediaListItemAdded);
                    }
                }
            }
        }

        event EventHandler<MediaListWillAddItem> m_willAddItem;
        public event EventHandler<MediaListWillAddItem> WillAddItem
        {
            add
            {
                if (m_willAddItem != null)
                {
                    Attach(libvlc_event_e.libvlc_MediaListWillAddItem);
                }
                m_willAddItem += value;
            }
            remove
            {
                if (m_willAddItem != null)
                {
                    m_willAddItem -= value;
                    if (m_willAddItem == null)
                    {
                        Dettach(libvlc_event_e.libvlc_MediaListWillAddItem);
                    }
                }
            }
        }

        event EventHandler<MediaListItemDeleted> m_itemDeleted;
        public event EventHandler<MediaListItemDeleted> ItemDeleted
        {
            add
            {
                if (m_itemDeleted == null)
                {
                    Attach(libvlc_event_e.libvlc_MediaListItemDeleted);
                }
                m_itemDeleted += value;
            }
            remove
            {
                if (m_itemDeleted != null)
                {
                    m_itemDeleted -= value;
                    if (m_itemDeleted == null)
                    {
                        Dettach(libvlc_event_e.libvlc_MediaListItemDeleted);
                    }
                }
            }
        }

        event EventHandler<MediaListWillDeleteItem> m_willDeleteItem;
        public event EventHandler<MediaListWillDeleteItem> WillDeleteItem
        {
            add
            {
                if (m_willDeleteItem == null)
                {
                    Attach(libvlc_event_e.libvlc_MediaListWillDeleteItem);
                }
                m_willDeleteItem += value;
            }
            remove
            {
                if (m_willDeleteItem != null)
                {
                    m_willDeleteItem -= value;
                    if (m_willDeleteItem == null)
                    {
                        Dettach(libvlc_event_e.libvlc_MediaListWillDeleteItem);
                    }
                }
            }
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior)
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions