WEB开发网
开发学院操作系统windows 2008 vlc的应用之三:动态调用vlc-0.9.4的libvlc.dll 阅读

vlc的应用之三:动态调用vlc-0.9.4的libvlc.dll

 2009-10-24 00:00:00 来源:WEB开发网   
核心提示: 5. MediaPlayerHandle和MediaPlayer类usingSystem;usingSystem.Runtime.InteropServices;namespaceMyOwnPlayer{classMediaPlayerHandle:SafeHandle{//构造方法public

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);
        }
}

上一页  1 2 3 4  下一页

Tags:vlc 应用 动态

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接