vlc的应用之三:动态调用vlc-0.9.4的libvlc.dll
2009-10-24 00:00:00 来源:WEB开发网vlc-0.9.4提供的libvlc.dll是可以动态调用的,Jeremiah这一篇博客就介绍下如何用C#和WinForm框架调用libvlc.dll作个简易播放器。
1. vs2005新建工程,将vlc-0.9.4的libvlc.dll,libvlccore.dll,plugins目录全部拷贝到工程目录下面\bin\Debug中。
2. 创建异常结构体
using System;
using System.Collections.Generic;
using System.Text;
namespace MyOwnPlayer
{
//异常结构体
public struct ExceptionStruct
{
private int raised;
private int code;
private string message;
}
class MediaException
{
}
}
3. CoreHandle和Core类
using System;
using System.Runtime.InteropServices;
namespace MyOwnPlayer
{
class CoreHandle : SafeHandle
{
//构造方法
public CoreHandle()
: base(IntPtr.Zero, true)
{
}
//重写的方法
public override bool IsInvalid
{
get { return handle == IntPtr.Zero; }
}
protected override bool ReleaseHandle()
{
if (!IsInvalid)
{
libvlc_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_release(CoreHandle coreHandle);
}
}
using System;
using System.Runtime.InteropServices;
namespace MyOwnPlayer
{
class Core
{
//coreHandle字段和属性
private CoreHandle coreHandle;
public CoreHandle CoreHandle
{
get { return coreHandle; }
}
//构造方法
public Core(string[] argv, ref ExceptionStruct ex)
{
coreHandle = libvlc_new(argv.Length, argv, ref ex);
}
//Dll动态导入
[DllImport("libvlc")]
private static extern CoreHandle libvlc_new(int argc, string[] args, ref ExceptionStruct ex);
}
}
赞助商链接