Exemplo n.º 1
0
        public Vlc(String[] argv)
        {
            InstancePointer = argv == null
                ? _newInstanceFunction.Delegate(0, IntPtr.Zero)
                : _newInstanceFunction.Delegate(argv.Length, InteropHelper.StringArrayToPtr(argv));

            if (InstancePointer == IntPtr.Zero)
            {
                var ex = VlcError.GetErrorMessage();
                throw new VlcCreateFailException(ex);
            }

            EventManager = new VlcEventManager(this, _getMediaEventManagerFunction.Delegate(InstancePointer));

            _onVlmMediaAdded                 = OnVlmMediaAdded;
            _onVlmMediaRemoved               = OnVlmMediaRemoved;
            _onVlmMediaChanged               = OnVlmMediaChanged;
            _onVlmMediaInstanceStarted       = OnVlmMediaInstanceStarted;
            _onVlmMediaInstanceStopped       = OnVlmMediaInstanceStopped;
            _onVlmMediaInstanceStatusInit    = OnVlmMediaInstanceStatusInit;
            _onVlmMediaInstanceStatusOpening = OnVlmMediaInstanceStatusOpening;
            _onVlmMediaInstanceStatusPlaying = OnVlmMediaInstanceStatusPlaying;
            _onVlmMediaInstanceStatusPause   = OnVlmMediaInstanceStatusPause;
            _onVlmMediaInstanceStatusEnd     = OnVlmMediaInstanceStatusEnd;
            _onVlmMediaInstanceStatusError   = OnVlmMediaInstanceStatusError;

            _onVlmMediaAddedHandle                 = GCHandle.Alloc(_onVlmMediaAdded);
            _onVlmMediaRemovedHandle               = GCHandle.Alloc(_onVlmMediaRemoved);
            _onVlmMediaChangedHandle               = GCHandle.Alloc(_onVlmMediaChanged);
            _onVlmMediaInstanceStartedHandle       = GCHandle.Alloc(_onVlmMediaInstanceStarted);
            _onVlmMediaInstanceStoppedHandle       = GCHandle.Alloc(_onVlmMediaInstanceStopped);
            _onVlmMediaInstanceStatusInitHandle    = GCHandle.Alloc(_onVlmMediaInstanceStatusInit);
            _onVlmMediaInstanceStatusOpeningHandle = GCHandle.Alloc(_onVlmMediaInstanceStatusOpening);
            _onVlmMediaInstanceStatusPlayingHandle = GCHandle.Alloc(_onVlmMediaInstanceStatusPlaying);
            _onVlmMediaInstanceStatusPauseHandle   = GCHandle.Alloc(_onVlmMediaInstanceStatusPause);
            _onVlmMediaInstanceStatusEndHandle     = GCHandle.Alloc(_onVlmMediaInstanceStatusEnd);
            _onVlmMediaInstanceStatusErrorHandle   = GCHandle.Alloc(_onVlmMediaInstanceStatusError);

            HandleManager.Add(this);

            EventManager.Attach(EventTypes.VlmMediaAdded, _onVlmMediaAdded, IntPtr.Zero);
            EventManager.Attach(EventTypes.VlmMediaRemoved, _onVlmMediaRemoved, IntPtr.Zero);
            EventManager.Attach(EventTypes.VlmMediaChanged, _onVlmMediaChanged, IntPtr.Zero);
            EventManager.Attach(EventTypes.VlmMediaInstanceStarted, _onVlmMediaInstanceStarted, IntPtr.Zero);
            EventManager.Attach(EventTypes.VlmMediaInstanceStopped, _onVlmMediaInstanceStopped, IntPtr.Zero);
            EventManager.Attach(EventTypes.VlmMediaInstanceStatusInit, _onVlmMediaInstanceStatusInit, IntPtr.Zero);
            EventManager.Attach(EventTypes.VlmMediaInstanceStatusOpening, _onVlmMediaInstanceStatusOpening, IntPtr.Zero);
            EventManager.Attach(EventTypes.VlmMediaInstanceStatusPlaying, _onVlmMediaInstanceStatusPlaying, IntPtr.Zero);
            EventManager.Attach(EventTypes.VlmMediaInstanceStatusPause, _onVlmMediaInstanceStatusPause, IntPtr.Zero);
            EventManager.Attach(EventTypes.VlmMediaInstanceStatusEnd, _onVlmMediaInstanceStatusEnd, IntPtr.Zero);
            EventManager.Attach(EventTypes.VlmMediaInstanceStatusError, _onVlmMediaInstanceStatusError, IntPtr.Zero);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Load LibVlc dlls, and mapping all function.
        /// </summary>
        /// <param name="libVlcDirectory">directory of LibVlc</param>
        /// <exception cref="LibVlcLoadLibraryException">
        ///     Can't load LibVlc dlls, check the platform and LibVlc target platform
        ///     (should be same, x86 or x64).
        /// </exception>
        /// <exception cref="TypeLoadException">A custom attribute type cannot be loaded. </exception>
        /// <exception cref="NoLibVlcFunctionAttributeException">
        ///     For LibVlcFunction, need LibVlcFunctionAttribute to get Infomation
        ///     of function.
        /// </exception>
        /// <exception cref="FunctionNotFoundException">Can't find function in dll.</exception>
        /// <exception cref="VersionStringParseException">Can't parse libvlc version string, it must like "2.2.0-Meta Weatherwax".</exception>
        /// <exception cref="OverflowException">
        ///     At least one component of version represents a number greater than
        ///     <see cref="F:System.Int32.MaxValue" />.
        /// </exception>
        public static void LoadLibVlc(String libVlcDirectory = null)
        {
            LibVlcDirectory = libVlcDirectory == null ? "" : libVlcDirectory;

            if (IsLibLoaded)
            {
                return;
            }

            try
            {
                FileInfo libcore = new FileInfo(Path.Combine(LibVlcDirectory, "libvlccore.dll"));
                FileInfo libvlc  = new FileInfo(Path.Combine(LibVlcDirectory, "libvlc.dll"));
                LibVlcVCoreHandle = Win32Api.LoadLibrary(libcore.FullName);
                LibVlcHandle      = Win32Api.LoadLibrary(libvlc.FullName);
            }
            catch (Win32Exception e)
            {
                throw new LibVlcLoadLibraryException(e);
            }

            _getVersionFunction = new LibVlcFunction <GetVersion>();
            LibVlcVersion       = new LibVlcVersion(GetVersion());

            _getCompilerFunction  = new LibVlcFunction <GetCompiler>();
            _getChangesetFunction = new LibVlcFunction <GetChangeset>();
            _freeFunction         = new LibVlcFunction <Free>();
            _releaseLibVlcModuleDescriptionFunction = new LibVlcFunction <ReleaseLibVlcModuleDescription>();
            _releaseAudioOutputListFunction         = new LibVlcFunction <ReleaseAudioOutputList>();
            _releaseAudioDeviceListFunction         = new LibVlcFunction <ReleaseAudioDeviceList>();
            _releaseTrackDescriptionFunction        = new LibVlcFunction <ReleaseTrackDescription>();
            _releaseTracksFunction = new LibVlcFunction <ReleaseTracks>();

            Vlc.LoadLibVlc();
            VlcError.LoadLibVlc();
            VlcEventManager.LoadLibVlc();
            VlcMedia.LoadLibVlc();
            VlcMediaPlayer.LoadLibVlc();
            AudioEqualizer.LoadLibVlc();
        }