/// <summary> /// Create a <see cref="FunctionNotFoundException" /> with function's infomation, LibVlc's version and a inner /// exception. /// </summary> /// <param name="functionInfo">infomation of function</param> /// <param name="libvlcVersion">version of LibVlc</param> /// <param name="innerException">inner exception</param> public FunctionNotFoundException(LibVlcFunctionAttribute functionInfo, LibVlcVersion libvlcVersion, Exception innerException) : base(String.Format("Can't find function \"{0}\" in dll.", functionInfo.FunctionName), innerException) { FunctionInfomation = functionInfo; LibVlcVersion = libvlcVersion; }
/// <summary> /// Create a <see cref="FunctionNotAvailableException" /> with function's infomation and LibVlc's version. /// </summary> /// <param name="functionInfo">infomation of function</param> /// <param name="libvlcVersion">version of LibVlc</param> public FunctionNotAvailableException(LibVlcFunctionAttribute functionInfo, LibVlcVersion libvlcVersion) : base( String.Format("Function \"{0}\" isn't available on current version LibVlc.", functionInfo.FunctionName)) { FunctionInfomation = functionInfo; LibVlcVersion = libvlcVersion; }
/// <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) { if (IsLibLoaded) { return; } LibVlcDirectory = libVlcDirectory == null ? "" : libVlcDirectory; try { var libcore = new FileInfo(Path.Combine(LibVlcDirectory, "libvlccore.dll")); var 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 <libvlc_get_version>(LibVlcHandle, null); _getCompilerFunction = new LibVlcFunction <libvlc_get_compiler>(LibVlcHandle, null); _getChangeSetFunction = new LibVlcFunction <libvlc_get_changeset>(LibVlcHandle, null); _freeFunction = new LibVlcFunction <libvlc_free>(LibVlcHandle, null); LibVlcVersion = new LibVlcVersion(GetVersion()); var functionArgs = new object[] { LibVlcHandle, LibVlcVersion }; foreach (var type in Assembly.GetExecutingAssembly().GetTypes()) { var attrs = type.GetCustomAttributes(typeof(LibVlcFunctionAttribute), false); if (attrs.Length == 0) { continue; } var functionType = typeof(LibVlcFunction <>).MakeGenericType(type); var function = Activator.CreateInstance(functionType, functionArgs); _cache.Add(type, function); } }
/// <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(); }
/// <summary> /// Create a <see cref="FunctionNotFoundException" /> with function's infomation and LibVlc's version. /// </summary> /// <param name="functionInfo">infomation of function</param> /// <param name="libvlcVersion">version of LibVlc</param> public FunctionNotFoundException(LibVlcFunctionAttribute functionInfo, LibVlcVersion libvlcVersion) : this(functionInfo, libvlcVersion, null) { }