/// <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))); } LibVlcManager.Free(pointer); return(result); }
/// <summary> /// Convert a pointer of string to manmaged <see cref="String" />. /// </summary> /// <param name="ptr">pointer of string</param> /// <param name="count">count of string, -1 mean auto check the end char</param> /// <param name="toBeFree">free this pointer when convert over</param> /// <param name="encoding">encoding of string</param> /// <returns>result string</returns> public static String PtrToString(IntPtr ptr, int count = -1, bool toBeFree = false, Encoding encoding = null) { if (ptr == IntPtr.Zero) { return(null); } if (encoding == null) { encoding = Encoding.UTF8; } List <byte> buffer = new List <byte>(1024); if (count == -1) { int offset = 0; byte tmp = Marshal.ReadByte(ptr, offset); while (tmp != 0) { buffer.Add(tmp); offset++; tmp = Marshal.ReadByte(ptr, offset); } } else { byte tmp = 0; for (int i = 0; i < count; i++) { tmp = Marshal.ReadByte(ptr, i); buffer.Add(tmp); } } if (toBeFree) { LibVlcManager.Free(ptr); } return(encoding.GetString(buffer.ToArray())); }
/// <summary> /// Release this event manager. /// </summary> /// <exception cref="Exception">A delegate callback throws an exception.</exception> public void Dispose() { HandleManager.Remove(this); LibVlcManager.Free(InstancePointer); InstancePointer = IntPtr.Zero; }