vlc的应用之三:动态调用vlc-0.9.4的libvlc.dll【转】
vlc的应用之三:动态调用vlc-0.9.4的libvlc.dll2008-12-03 17:38:46
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
{
}
}
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);
}
}
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, refExceptionStruct ex);
}
}
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, refExceptionStruct 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);
}
}
private void button1_Click(object sender, EventArgs e)
{
//要播放的文件的uri
string uri = this.textBox1.Text; 
//进行播放的控件的句柄
IntPtr hdl = this.panel1.Handle; 
//播放参数
string[] argv = new string[] { "-I", "--ignore-config" }; 
//vlc对象的创建
ExceptionStruct ex = new ExceptionStruct();
Core core = new Core(argv, ref ex);
Media media = new Media(core.CoreHandle, uri, ref ex);
MediaPlayer player = new MediaPlayer(media.MediaHandle, ref ex); 
//垃圾回收
GC.Collect(); 
//播放
player.VedioSetParent(core.CoreHandle, hdl, ref ex);
player.Play(ref ex); 
//继续回收垃圾等相关操作
GC.Collect();
GC.WaitForPendingFinalizers();
}本文出自 “海狗哥的流媒体空间” 博客,请务必保留此出处http://jeremiah.blog.51cto.com/539865/116981
![]() |
![]() |
|
8人
|
了这篇文章 |
vlc的应用之三:动态调用vlc-0.9.4的libvlc.dll【转】的更多相关文章
- C#动态调用C++编写的DLL函数
C#动态调用C++编写的DLL函数 动态加载DLL需要使用Windows API函数:LoadLibrary.GetProcAddress以及FreeLibrary.我们可以使用DllImport在C ...
- 网页IE轻松调用VLC播放器实现监控(组件+方法大全)【转】
公司突发奇想,要把刚买回来的网络监控机用自己内部网站在线监控. 作为网站的开发员,我接下了这个任务. 网络上有很多资料参与,但是都不全都不尽人意,最后经过多次的不同关键字的查找和测试,总算让我成功了. ...
- vlc的应用之二:vlc的ActiveX及cab
请移步https://higoge.github.io/,所有下载资料在那个博客都能找到.谢谢. http://jeremiah.blog.51cto.com/ 2009-05-14补充:8. Act ...
- 动态调用WebService
WebService内容 using Microsoft.CSharp;using System;using System.CodeDom;using System.CodeDom.Compiler; ...
- c# 动态调用WCF方法笔记!
//动态调用wcf方法 string url = "http://localhost:54379/ServiceWCF.svc"; IDoubleService proxy = W ...
- C#动态调用WCF接口,两种方式任你选。
写在前面 接触WCF还是它在最初诞生之处,一个分布式应用的巨作. 从开始接触到现在断断续续,真正使用的项目少之又少,更谈不上深入WCF内部实现机制和原理去研究,最近自己做一个项目时用到了WCF. 从这 ...
- 11月10日上午ajax基础知识、用ajax做登录页面、用ajax验证用户名是否可用、ajax动态调用数据库
1.ajax的基础知识 ajax是结合了jquery.php等几种技术延伸出来的综合运用的技术,不是新的内容.ajax也是写在<script>标签里面的. 如果使用ajax一定是要有1个处 ...
- C# 调用WebService的3种方式 :直接调用、根据wsdl生成webservice的.cs文件及生成dll调用、动态调用
1.直接调用 已知webservice路径,则可以直接 添加服务引用--高级--添加web引用 直接输入webservice URL.这个比较常见也很简单 即有完整的webservice文件目录如下图 ...
- Delphi DLL的创建、静态及动态调用
转载:http://blog.csdn.net/welcome000yy/article/details/7905463 结合这篇博客:http://www.cnblogs.com/xumenger/ ...
随机推荐
- GIT(6)----fork和clone的区别,fetch与pull的区别
参考资料: [1].Git学习笔记:fork和clone的区别,fetch与pull的区别 [2].在Github和Git上fork之简单指南
- vim segment fault when i upgrade to macOS Mojave 103_PollServerReady
系统升级到 macOS Mojave, vim插件YouCompleteMe出错. Vim: Caught deadly signal SEGV Error detected while proces ...
- Reverse Engineering the NC ECU (revisited) -- SH7508
http://forum.miata.net/vb/showthread.php?t=536601 Hey all! About 5 years ago, there was a great thre ...
- jquery的closest方法和parents方法的区别
今天第一次看到closest方法,以前也从来没用过. 该方法从元素本身开始往上查找,返回最近的匹配的祖先元素. 1.closest查找开始于自身,parents开始于元素父级 2.closest向上查 ...
- 绝对定位的div的居中方法,下面的写法兼容IE系列浏览器和火狐浏览器。
详细解说,直接看样式:#dingwei{padding:10px;background-color:#003300;color:#FFFFFF; width:600px;height:300px; d ...
- 国产Linux滋生腐败
回想过去,2002年12月11日至12日,信息产业部与科技部联合主办"Linux软件与应用猜測研讨会".影响中国IT业的重要人士,包含政府决策者.学界权威.主要Linux推动厂商等 ...
- 初次使用SQL调优建议工具--SQL Tuning Advisor
在10g中,Oracle推出了自己的SQL优化辅助工具: SQL优化器(SQL Tuning Advisor :STA),它是新的DBMS_SQLTUNE包. 使用STA一定要保证优化器是CBO模式下 ...
- EntityFramework(EF)贪婪加载和延迟加载的选择和使用
贪婪加载:顾名思议就是把所有要加载的东西一 次性读取 1 using (var context = new MyDbContext()) 2 { 3 var orders = from o in co ...
- Java开发工具全面比较
1.JDK (Java Development Kit)Java开发工具集 从初学者角度来看Java开发工具,采用JDK开发Java程序能够很快理解程序中各部分代码之间的关系,有利于理解Java面向对 ...
- table固定首行(一)
<html> <head> <title>Untitled Document</title> <meta http-equiv="Con ...


Marx_libvlc_wrapper(2).zip