/// <summary> /// 设置媒体的元数据 /// </summary> /// <param name="type">元数据类型</param> /// <param name="data">元数据值</param> public void SetMeta(MetaDataType type, String data) { GCHandle handle = GCHandle.Alloc(Encoding.UTF8.GetBytes(data), GCHandleType.Pinned); _setMetaFunction.Delegate(InstancePointer, type, handle.AddrOfPinnedObject()); handle.Free(); }
/// <summary> /// 向一个媒体添加选项,这个选项将会确定媒体播放器将如何读取介质, /// </summary> /// <param name="options"></param> public void AddOption(params String[] options) { GCHandle handle = GCHandle.Alloc(Encoding.UTF8.GetBytes(String.Join(" ", options)), GCHandleType.Pinned); _addOptionFunction.Delegate(InstancePointer, handle.AddrOfPinnedObject()); handle.Free(); }
/// <summary> /// 向一个媒体通过可配置的标志添加一个选项,这个选项将会确定媒体播放器将如何读取介质, /// </summary> /// <param name="options"></param> /// <param name="flag"></param> public void AddOptionFlag(String options, MediaOption flag) { GCHandle handle = GCHandle.Alloc(Encoding.UTF8.GetBytes(options), GCHandleType.Pinned); _addOptionFlagFunction.Delegate(InstancePointer, handle.AddrOfPinnedObject(), flag); handle.Free(); }
public void SetVideoFormat(String chroma, uint width, uint height, uint pitch) { var handle = InteropHelper.StringToPtr(chroma); _setVideoFormatFunction.Delegate(InstancePointer, handle.AddrOfPinnedObject(), width, height, pitch); handle.Free(); }
/// <summary> /// 设置 Audio 的格式 /// </summary> /// <param name="format">格式字符串,一个四字符的字符串</param> /// <param name="rate">采样率</param> /// <param name="channels">通道数</param> public void SetAudioFormat(String format, uint rate, uint channels) { var fmt = BitConverter.ToUInt32(new[] { (byte)format[0], (byte)format[1], (byte)format[2], (byte)format[3] }, 0); _setAudioFormatFunction.Delegate(InstancePointer, fmt, rate, channels); }
/// <summary> /// Selects an audio output module. /// Any change will take be effect only after playback is stopped and restarted. Audio output cannot be changed while /// playing. /// </summary> /// <param name="audioOutput"></param> /// <returns></returns> public bool SetAudioOutput(AudioOutput audioOutput) { var handle = InteropHelper.StringToPtr(audioOutput.Name); var result = _setAudioOutputFunction.Delegate(InstancePointer, handle.AddrOfPinnedObject()); handle.Free(); return(result == 0); }
/// <summary> /// 通过名称创建一个新的 VlcMedia /// </summary> /// <param name="vlc">Vlc 对象</param> /// <param name="name">媒体名称</param> public static VlcMedia CreateAsNewNode(Vlc vlc, String name) { GCHandle handle = GCHandle.Alloc(Encoding.UTF8.GetBytes(name), GCHandleType.Pinned); var madia = new VlcMedia(_createMediaAsNewNodeFunction.Delegate(vlc.InstancePointer, handle.AddrOfPinnedObject())); handle.Free(); return(madia); }
/// <summary> /// 通过给定的文件路径创建一个新的 VlcMedia /// </summary> /// <param name="vlc">Vlc 对象</param> /// <param name="path">文件路径</param> public static VlcMedia CreateFormPath(Vlc vlc, String path) { GCHandle handle = GCHandle.Alloc(Encoding.UTF8.GetBytes(path), GCHandleType.Pinned); var media = new VlcMedia(_createMediaFormPathFunction.Delegate(vlc.InstancePointer, handle.AddrOfPinnedObject())); handle.Free(); return(media); }
public bool AddInterface(String name) { var handle = GCHandle.Alloc(Encoding.UTF8.GetBytes(name), GCHandleType.Pinned); var result = _addInterfaceFunction.Delegate(InstancePointer, handle.AddrOfPinnedObject()) == 0; handle.Free(); return(result); }
/// <summary> /// 设置一个用户代理字符串,当一个协议需要它的时候,将会提供该字符串 /// </summary> /// <param name="name">应用程序名称,类似于 "FooBar player 1.2.3",实际上只要能标识应用程序,任何字符串都是可以的</param> /// <param name="http">HTTP 用户代理,类似于 "FooBar/1.2.3 Python/2.6.0"</param> public void SetUserAgent(String name, String http) { var nameHandle = GCHandle.Alloc(Encoding.UTF8.GetBytes(name), GCHandleType.Pinned); var httpHandle = GCHandle.Alloc(Encoding.UTF8.GetBytes(http), GCHandleType.Pinned); _setUserAgentFunction.Delegate(InstancePointer, nameHandle.AddrOfPinnedObject(), httpHandle.AddrOfPinnedObject()); nameHandle.Free(); httpHandle.Free(); }
/// <summary> /// Gets a list of audio output devices for a given audio output module. /// </summary> /// <param name="audioOutput"></param> /// <returns></returns> public AudioDeviceList GetAudioDeviceList(AudioOutput audioOutput) { var handle = InteropHelper.StringToPtr(audioOutput.Name); var result = new AudioDeviceList(_getAudioDeviceListFunction.Delegate(VlcInstance.InstancePointer, handle.AddrOfPinnedObject())); handle.Free(); return(result); }
public bool VlmPause(String name) { var nameHandle = InteropHelper.StringToPtr(name); var result = _pauseNamedBroadcastFunction.Delegate(InstancePointer, nameHandle.AddrOfPinnedObject()) == 0; nameHandle.Free(); return(result); }
public int VlmGetRate(String name, int id) { var nameHandle = InteropHelper.StringToPtr(name); var result = _getMediaBackRateFunction.Delegate(InstancePointer, nameHandle.AddrOfPinnedObject(), id); nameHandle.Free(); return(result); }
public bool VlmSetEnable(String name, int enable) { var nameHandle = InteropHelper.StringToPtr(name); var result = _mediaSwitchFunction.Delegate(InstancePointer, nameHandle.AddrOfPinnedObject(), enable) == 0; nameHandle.Free(); return(result); }
public bool VlmDeleteMedia(String name) { var nameHandle = InteropHelper.StringToPtr(name); var result = _delBoroadcastOrOvdFunction.Delegate(InstancePointer, nameHandle.AddrOfPinnedObject()) == 0; nameHandle.Free(); return(result); }
public bool VlmSetLoop(String name, int loop) { var nameHandle = InteropHelper.StringToPtr(name); var result = _setMediaLoopFunction.Delegate(InstancePointer, nameHandle.AddrOfPinnedObject(), loop) == 0; nameHandle.Free(); return(result); }
public String VlmGetInfomation(String name) { var nameHandle = InteropHelper.StringToPtr(name); var result = _returnJsonMessageFunction.Delegate(InstancePointer, nameHandle.AddrOfPinnedObject()); nameHandle.Free(); return(InteropHelper.PtrToString(result)); }
/// <summary> /// 设置一些元信息关于该应用程序 /// </summary> /// <param name="id">Java 风格的应用标识符,类似于 "com.acme.foobar"</param> /// <param name="version">应用程序版本,类似于 "1.2.3"</param> /// <param name="icon">应用程序图标,类似于 "foobar"</param> public void SetAppId(String id, String version, String icon) { var idHandle = GCHandle.Alloc(Encoding.UTF8.GetBytes(id), GCHandleType.Pinned); var versionHandle = GCHandle.Alloc(Encoding.UTF8.GetBytes(version), GCHandleType.Pinned); var iconHandle = GCHandle.Alloc(Encoding.UTF8.GetBytes(icon), GCHandleType.Pinned); _setAppIdFunction.Delegate(InstancePointer, idHandle.AddrOfPinnedObject(), versionHandle.AddrOfPinnedObject(), iconHandle.AddrOfPinnedObject()); idHandle.Free(); versionHandle.Free(); iconHandle.Free(); }
protected void Dispose(bool disposing) { if (_disposed) { return; } //EventManager.Dispose(); HandleManager.Remove(this); EventManager.Detach(EventTypes.MediaPlayerPlaying, _onPlaying, IntPtr.Zero); EventManager.Detach(EventTypes.MediaPlayerPaused, _onPaused, IntPtr.Zero); EventManager.Detach(EventTypes.MediaPlayerOpening, _onOpening, IntPtr.Zero); EventManager.Detach(EventTypes.MediaPlayerBuffering, _onBuffering, IntPtr.Zero); EventManager.Detach(EventTypes.MediaPlayerStopped, _onStoped, IntPtr.Zero); EventManager.Detach(EventTypes.MediaPlayerForward, _onForward, IntPtr.Zero); EventManager.Detach(EventTypes.MediaPlayerBackward, _onBackward, IntPtr.Zero); EventManager.Detach(EventTypes.MediaPlayerEndReached, _onEndReached, IntPtr.Zero); EventManager.Detach(EventTypes.MediaPlayerMediaChanged, _onMediaChanged, IntPtr.Zero); EventManager.Detach(EventTypes.MediaPlayerNothingSpecial, _onNothingSpecial, IntPtr.Zero); EventManager.Detach(EventTypes.MediaPlayerPausableChanged, _onPausableChanged, IntPtr.Zero); EventManager.Detach(EventTypes.MediaPlayerPositionChanged, _onPositionChanged, IntPtr.Zero); EventManager.Detach(EventTypes.MediaPlayerSeekableChanged, _onSeekableChanged, IntPtr.Zero); EventManager.Detach(EventTypes.MediaPlayerSnapshotTaken, _onSnapshotTaken, IntPtr.Zero); EventManager.Detach(EventTypes.MediaPlayerTimeChanged, _onTimeChanged, IntPtr.Zero); EventManager.Detach(EventTypes.MediaPlayerTitleChanged, _onTitleChanged, IntPtr.Zero); EventManager.Detach(EventTypes.MediaPlayerVideoOutChanged, _onVideoOutChanged, IntPtr.Zero); EventManager.Detach(EventTypes.MediaPlayerLengthChanged, _onLengthChanged, IntPtr.Zero); EventManager.Detach(EventTypes.MediaPlayerEncounteredError, _onEncounteredError, IntPtr.Zero); _onPlayingHandle.Free(); _onPausedHandle.Free(); _onOpeningHandle.Free(); _onBufferingHandle.Free(); _onStopedHandle.Free(); _onForwardHandle.Free(); _onBackwardHandle.Free(); _onEndReachedHandle.Free(); _onMediaChangedHandle.Free(); _onNothingSpecialHandle.Free(); _onPausableChangedHandle.Free(); _onPositionChangedHandle.Free(); _onSeekableChangedHandle.Free(); _onSnapshotTakenHandle.Free(); _onTimeChangedHandle.Free(); _onTitleChangedHandle.Free(); _onVideoOutChangedHandle.Free(); _onLengthChangedHandle.Free(); _onEncounteredErrorHandle.Free(); _releaseMediaPlayerFunction.Delegate(InstancePointer); InstancePointer = IntPtr.Zero; _disposed = true; }
public bool VlmSeek(String name, float percentage) { var nameHandle = InteropHelper.StringToPtr(name); var result = _seekInNamedBroadcastFunction.Delegate(InstancePointer, nameHandle.AddrOfPinnedObject(), percentage) == 0; nameHandle.Free(); return(result); }
protected void Dispose(bool disposing) { if (disposed) { return; } HandleManager.Remove(this); ReleaseInstanceFunction.Delegate(InstancePointer); InstancePointer = IntPtr.Zero; disposed = true; }
/// <summary> /// 提供指定的参数初始化一个 Vlc 实例 /// </summary> /// <param name="argv"></param> public Vlc(String[] argv) { if (!IsLibLoaded) { LoadLibVlc(); } if (argv == null) { InstancePointer = NewInstanceFunction.Delegate(0, IntPtr.Zero); } else { InstancePointer = NewInstanceFunction.Delegate(argv.Length, InteropHelper.StringArrayToPtr(argv)); } if (InstancePointer == IntPtr.Zero) { String ex = VlcError.GetErrorMessage(); throw new Exception(ex); } HandleManager.Add(this); }
public bool VlmSetOutput(String name, String output) { var nameHandle = InteropHelper.StringToPtr(name); var outputHandle = InteropHelper.StringToPtr(output); var result = _setMediaOutputFunction.Delegate(InstancePointer, nameHandle.AddrOfPinnedObject(), outputHandle.AddrOfPinnedObject()) == 0; nameHandle.Free(); outputHandle.Free(); return(result); }
/// <summary> /// Configures an explicit audio output device. If the module paramater is NULL, /// audio output will be moved to the device specified by the device identifier string immediately. /// This is the recommended usage. A list of adequate potential device strings can be obtained with /// <see cref="EnumAudioDeviceList" />. /// However passing NULL is supported in LibVLC version 2.2.0 and later only; in earlier versions, this function would /// have no effects when the module parameter was NULL. /// If the module parameter is not NULL, the device parameter of the corresponding audio output, if it exists, will be /// set to the specified string. /// Note that some audio output modules do not have such a parameter (notably MMDevice and PulseAudio). /// A list of adequate potential device strings can be obtained with <see cref="GetAudioDeviceList" />. /// </summary> public void SetAudioDevice(AudioOutput audioOutput, AudioDevice audioDevice) { var outputHandle = audioOutput == null ? null : new GCHandle?(InteropHelper.StringToPtr(audioOutput.Name)); var deviceHandle = InteropHelper.StringToPtr(audioDevice.Device); _setAudioDeviceFunction.Delegate(InstancePointer, outputHandle == null ? IntPtr.Zero : outputHandle.Value.AddrOfPinnedObject(), deviceHandle.AddrOfPinnedObject()); if (outputHandle.HasValue) { outputHandle.Value.Free(); } deviceHandle.Free(); }
public bool VlmAddInput(String name, String input) { var nameHandle = InteropHelper.StringToPtr(name); var inputHandle = InteropHelper.StringToPtr(input); var result = _addMediaInputFunction.Delegate(InstancePointer, nameHandle.AddrOfPinnedObject(), inputHandle.AddrOfPinnedObject()) == 0; nameHandle.Free(); inputHandle.Free(); return(result); }
public bool VlmSetMuxer(String name, String muxer) { var nameHandle = InteropHelper.StringToPtr(name); var muxerHandle = InteropHelper.StringToPtr(muxer); var result = _setVodMuxerFunction.Delegate(InstancePointer, nameHandle.AddrOfPinnedObject(), muxerHandle.AddrOfPinnedObject()) == 0; nameHandle.Free(); muxerHandle.Free(); return(result); }
/// <summary> /// 获取媒体的基本流的描述,注意,在调用该方法之前你需要首先调用 <see cref="ParseMedia"/> 方法,或者至少播放一次. /// 否则,你将的得到一个空数组 /// </summary> /// <returns>一个 <see cref="MediaTrackInfo"/> 数组</returns> public MediaTrackInfo[] GetTrackInfo() { IntPtr pointer; var count = _getTracksInfoFunction.Delegate(InstancePointer, out pointer); var result = new MediaTrackInfo[count]; var temp = pointer; for (var i = 0; i < count; i++) { result[i] = (MediaTrackInfo)Marshal.PtrToStructure(temp, typeof(MediaTrackInfo)); temp = (IntPtr)((int)temp + Marshal.SizeOf(typeof(MediaTrackInfo))); } Vlc.Free(pointer); return(result); }
public bool VlmAddVod(String name, String input, int options, String[] additionalOptions, int enable, String muxer) { var nameHandle = InteropHelper.StringToPtr(name); var inputHandle = InteropHelper.StringToPtr(input); var muxerHandle = InteropHelper.StringToPtr(muxer); var result = _newVodInputFunction.Delegate(InstancePointer, nameHandle.AddrOfPinnedObject(), inputHandle.AddrOfPinnedObject(), options, InteropHelper.StringArrayToPtr(additionalOptions), enable, muxerHandle.AddrOfPinnedObject()) == 0; nameHandle.Free(); inputHandle.Free(); muxerHandle.Free(); return(result); }
public bool VlmAddBroadcast(String name, String input, String output, int options, String[] additionalOptions, int enable, int loop) { var nameHandle = InteropHelper.StringToPtr(name); var inputHandle = InteropHelper.StringToPtr(input); var outputHandle = InteropHelper.StringToPtr(output); var result = _newBroadCastInputFunction.Delegate(InstancePointer, nameHandle.AddrOfPinnedObject(), inputHandle.AddrOfPinnedObject(), outputHandle.AddrOfPinnedObject(), options, InteropHelper.StringArrayToPtr(additionalOptions), enable, loop) == 0; nameHandle.Free(); inputHandle.Free(); outputHandle.Free(); return(result); }
/// <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; } }
/// <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; } }