//==========================================================================
    private void Dispose(bool disposing)
    {
      if(m_MediaPlayerHandle != IntPtr.Zero)
      {
        m_Library.libvlc_media_player_release(m_MediaPlayerHandle);

        if(disposing)
          UnregisterMediaPlayer(m_MediaPlayerHandle);

        m_MediaPlayerHandle = IntPtr.Zero;
      }

      if(disposing)
      {
        if(m_Instance != null)
        {
          if(m_IsInstanceOwner)
            m_Instance.Dispose();
          m_Instance = null;
        }

        if(m_Library != null)
        {
          if(m_IsLibraryOwner)
            LibVLCLibrary.Free(m_Library);
          m_Library = null;
        }
      }
    }
    //==========================================================================
    public MediaPlayer(LibVLCLibrary library, Instance instance)
    {
      if(library != null)
        if(instance != null)
          if(instance.Library != library)
            throw new ArgumentException("The provided instance has not been created with the provided library!", "instance");
      if(instance != null)
        if(library == null)
          library = instance.Library;

      if(library == null)
      {
        m_Library = LibVLCLibrary.Load(null);
        m_IsLibraryOwner = true;
      }
      else
      {
        m_Library = library;
        m_IsLibraryOwner = false;
      }
      try
      {
        if(instance == null)
        {
          m_Instance = new Instance(m_Library);
          m_IsInstanceOwner = true;
        }
        else
        {
          m_Instance = instance;
          m_IsInstanceOwner = false;
        }
        try
        {
          m_MediaPlayerHandle = CreateHandle();
        }
        catch
        {
          if(m_IsInstanceOwner)
            m_Instance.Dispose();
          m_Instance = null;
          throw;
        }
      }
      catch
      {
        if(m_IsLibraryOwner)
          LibVLCLibrary.Free(m_Library);
        m_Library = null;
        throw;
      }
    }