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

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

 2009-10-24 00:00:00 来源:WEB开发网   
核心提示: 3. MediaHandle和Media类,注意里面的非英文路径处理方法,vlc的应用之三:动态调用vlc-0.9.4的libvlc.dll(2),usingSystem;usingSystem.Runtime.InteropServices;namespaceMyOwnPlayer{class

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

上一页  1 2 3 4  下一页

Tags:vlc 应用 动态

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