예제 #1
0
파일: Vlc.cs 프로젝트: kgloveyou/xZune.Vlc
        /// <summary>
        /// 使用已经设定好的路径,载入 LibVlc
        /// </summary>
        public static void LoadLibVlc()
        {
            if (!IsLibLoaded)
            {
                try
                {
                    FileInfo libcore = new FileInfo(Path.Combine(LibDirectory, @"libvlccore.dll"));
                    FileInfo libvlc  = new FileInfo(Path.Combine(LibDirectory, @"libvlc.dll"));
                    LibCoreHandle = Win32Api.LoadLibrary(libcore.FullName);
                    LibHandle     = Win32Api.LoadLibrary(libvlc.FullName);
                }
                catch (Win32Exception e)
                {
                    throw new Exception("无法载入 LibVlc 库", e);
                }

                _getVersionFunction = new LibVlcFunction <GetVersion>(LibHandle);
                var versionString = InteropHelper.PtrToString(_getVersionFunction.Delegate());
                var match         = Regex.Match(versionString, "^[0-9.]*");
                if (match.Success)
                {
                    LibVersion = new Version(match.Groups[0].Value);
                }
                var devString = LibDev = versionString.Split(' ', '-')[1];
                _newInstanceFunction     = new LibVlcFunction <NewInstance>(LibHandle, LibVersion, devString);
                _releaseInstanceFunction = new LibVlcFunction <ReleaseInstance>(LibHandle, LibVersion, devString);
                _retainInstanceFunction  = new LibVlcFunction <RetainInstance>(LibHandle, LibVersion, devString);
                _addInterfaceFunction    = new LibVlcFunction <AddInterface>(LibHandle, LibVersion, devString);
                _setExitHandlerFunction  = new LibVlcFunction <SetExitHandler>(LibHandle, LibVersion, devString);
                _waitFunction            = new LibVlcFunction <Wait>(LibHandle, LibVersion, devString);
                _setUserAgentFunction    = new LibVlcFunction <SetUserAgent>(LibHandle, LibVersion, devString);
                _setAppIdFunction        = new LibVlcFunction <SetAppId>(LibHandle, LibVersion, devString);
                _getCompilerFunction     = new LibVlcFunction <GetCompiler>(LibHandle, LibVersion, devString);
                _getChangesetFunction    = new LibVlcFunction <GetChangeset>(LibHandle, LibVersion, devString);
                _freeFunction            = new LibVlcFunction <Free>(LibHandle, LibVersion, devString);
                _releaseLibVlcModuleDescriptionFunction = new LibVlcFunction <ReleaseLibVlcModuleDescription>(LibHandle, LibVersion, devString);
                _getAudioFilterListFunction             = new LibVlcFunction <GetAudioFilterList>(LibHandle, LibVersion, devString);
                _getVideoFilterListFunction             = new LibVlcFunction <GetVideoFilterList>(LibHandle, LibVersion, devString);
                VlcError.LoadLibVlc(LibHandle, LibVersion, devString);
                VlcEventManager.LoadLibVlc(LibHandle, LibVersion, devString);
                VlcMedia.LoadLibVlc(LibHandle, LibVersion, devString);
                VlcMediaPlayer.LoadLibVlc(LibHandle, LibVersion, devString);
                IsLibLoaded = true;
            }
        }
예제 #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-xZune 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();
        }
예제 #3
0
 /// <summary>
 /// 释放当前的 ModuleDescription 资源
 /// </summary>
 public void Dispose()
 {
     VlcMediaPlayer.ReleaseTrackDescription(this);
     Items   = null;
     Pointer = IntPtr.Zero;
 }
예제 #4
0
 public VlcMediaPlayer CreateMediaPlayer()
 {
     return(VlcMediaPlayer.Create(this));
 }