vlc的应用之三:动态调用vlc-0.9.4的libvlc.dll
2009-10-24 00:00:00 来源:WEB开发网3. MediaHandle和Media类,注意里面的非英文路径处理方法。
using System;
using System.Runtime.InteropServices;
namespace MyOwnPlayer
{
class MediaHandle : SafeHandle
{
//构造方法
public MediaHandle()
: base(IntPtr.Zero, true)
{
}
//重写的方法
public override bool IsInvalid
{
get { return handle == IntPtr.Zero; }
}
protected override bool ReleaseHandle()
{
if (!IsInvalid)
{
libvlc_media_release(this);
handle = IntPtr.Zero;
}
return true;
}
protected override void Dispose(bool disposing)
{
ReleaseHandle();
base.Dispose(disposing);
}
//Dll动态导入
[DllImport("libvlc")]
private static extern void libvlc_media_release(MediaHandle mediaHandle);
}
}
using System;
using System.Text;
using System.Runtime.InteropServices;
namespace MyOwnPlayer
{
class Media
{
//mediaHandle字段和属性
private MediaHandle mediaHandle;
public MediaHandle MediaHandle
{
get { return mediaHandle; }
}
//构造方法
public Media(CoreHandle coreHandle, String filename, ref ExceptionStruct ex)
{
//c#为UTF-16编码, libvlc.dll为UTF-8编码, 需要转换.
UTF8Encoding utf8 = new UTF8Encoding();
mediaHandle = libvlc_media_new(coreHandle, utf8.GetBytes(filename), ref ex);
}
//Dll动态导入
[DllImport("libvlc")]
private static extern MediaHandle libvlc_media_new
(CoreHandle coreHandle, [MarshalAs(UnmanagedType.LPArray)] byte[] link, ref ExceptionStruct ex);
}
}
更多精彩
赞助商链接