vlc的应用之三:动态调用vlc-0.9.4的libvlc.dll
2009-10-24 00:00:00 来源:WEB开发网5. MediaPlayerHandle和MediaPlayer类
using System;
using System.Runtime.InteropServices;
namespace MyOwnPlayer
{
class MediaPlayerHandle : SafeHandle
{
//构造方法
public MediaPlayerHandle()
: base(IntPtr.Zero, true)
{
}
//重写的方法
public override bool IsInvalid
{
get { return handle == IntPtr.Zero; }
}
protected override bool ReleaseHandle()
{
if (!IsInvalid)
{
libvlc_media_player_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_player_release(MediaPlayerHandle mediaPlayerHandle);
}
}
using System;
using System.Runtime.InteropServices;
namespace MyOwnPlayer
{
class MediaPlayer
{
//mediaPlayerHandle字段和属性
private MediaPlayerHandle mediaPlayerHandle;
public MediaPlayerHandle MediaPlayerHandle
{
get { return mediaPlayerHandle; }
}
//构造方法
public MediaPlayer(MediaHandle mediaHandle, ref ExceptionStruct ex)
{
mediaPlayerHandle = libvlc_media_player_new_from_media(mediaHandle, ref ex);
}
//设置父窗口
public void VedioSetParent(CoreHandle coreHandle, IntPtr hDT, ref ExceptionStruct ex)
{
libvlc_video_set_parent(coreHandle, hDT, ref ex);
}
//播放
public void Play(ref ExceptionStruct ex)
{
libvlc_media_player_play(mediaPlayerHandle, ref ex);
}
//停止
public void Stop(ref ExceptionStruct ex)
{
libvlc_media_player_stop(mediaPlayerHandle, ref ex);
}
//Dll动态导入
[DllImport("libvlc")]
private static extern MediaPlayerHandle libvlc_media_player_new_from_media(MediaHandle libvlc_media_handle, ref ExceptionStruct ex);
[DllImport("libvlc")]
private static extern void libvlc_video_set_parent(CoreHandle coreHandle, IntPtr hDT, ref ExceptionStruct ex);
[DllImport("libvlc")]
private static extern void libvlc_media_player_play(MediaPlayerHandle mediaPlayerHandle, ref ExceptionStruct ex);
[DllImport("libvlc")]
private static extern void libvlc_media_player_stop(MediaPlayerHandle mediaPlayerHandle, ref ExceptionStruct ex);
}
}
更多精彩
赞助商链接