libvlc media player in C# (part 2)
原文 http://www.helyar.net/2009/libvlc-media-player-in-c-part-2/
I gave some simplified VLC media player code in part 1 to show how easy it was to do and how most wrapper libraries make a mountain out of a mole hill. In that entry, I briefly touched on using some classes to make it easier and safer to implement actual programs with this.
The first thing to do is write a wrapper for the exceptions, so that they are handled nicely in C#. For a program using the library, exceptions should be completely transparent and should be handled in the normal try/catch blocks without having to do anything like initialise them or check them.
Another thing to do is to move all of the initialisation functions into constructors and all of the release functions into destuctors or use the System.IDisposable interface.
Here is the code listing for the 4 classes used (VlcInstance, VlcMedia, VlcMediaPlayer and VlcException). Note that the first 3 of these are very similar and that the main difference is that the media player class has some extra functions for doing things like playing and pausing the content.
class VlcInstance : IDisposable |
Using these classes is even easier than before, can use proper exception handling (removed for brevity) and cleans up better at the end. In this example, I have added an OpenFileDialog, which is where the file is loaded.
using System; |
Update:
I have just corrected a minor bug (the wrong release function being called on the player handle) and uploaded the full Visual Studio 2005 project. You can download the full project here (or see 1.1.2 version below). It comes with the libvlc.dll and libvlccore.dll for VLC 1.0.1 in the bin\x86\Debug directory so if you have a version other than this, just overwrite those files.
Update for VLC 1.1.2:
You can now download the VLC 1.1.2 compatible version. There were some changes to the way libvlc handles exceptions that needed to be corrected. Other than that, there were a couple of minor function name changes.
Please use these posts as a starting point to use your own code though. These posts are intended to stoppeople from being reliant on the already existing, large, overcomplicated and quickly outdated libraries. They are not intended to be just another library for people to blindly use without understanding how it works. You can use this to learn how to write your own native interop code on a well designed library then adapt it for your own changes and keep it up to date with whichever version of VLC you want. This also means you never have to use the terrible code on pinvoke.net for other libraries, as you can write your own from the original documentation and it will almost always be better.
Bugfix: VlcException
should use Marshal.PtrToStringAnsi
not Marshal.PtrToStringAuto
libvlc media player in C# (part 2)的更多相关文章
- libvlc media player in C# (part 1)
原文 http://www.helyar.net/2009/libvlc-media-player-in-c/ There seems to be a massive misconception ab ...
- 【流媒体开发】VLC Media Player - Android 平台源码编译 与 二次开发详解 (提供详细800M下载好的编译源码及eclipse可调试播放器源码下载)
作者 : 韩曙亮 博客地址 : http://blog.csdn.net/shulianghan/article/details/42707293 转载请注明出处 : http://blog.csd ...
- 用VLC Media Player搭建简单的流媒体服务器
VLC可以作为播放器使用,也可以搭建服务器. 在经历了Helix Server和Darwin Streaming Server+Perl的失败之后,终于找到了一个搭建流媒体简单好用的方法. 这个网址中 ...
- android错误之MediaPlayer用法的Media Player called in state *,androidmediaplayer
用到Media Player,遇到几个问题,记一下 用法就不说了,使用的时候最好参考一下mediaPlayer的这张图 第一个错误是Media Player called in state 8 这个是 ...
- win7自带windows media player 已停止工作
解决方法如下: 在计算机开始,菜单找到控制面板 ,然后打开程序和功能,选择打开或关闭window功能,媒体功能.再取消windows Media Center Windows MediaPlayer选 ...
- 转:Media Player Classic - HC 源代码分析
VC2010 编译 Media Player Classic - Home Cinema (mpc-hc) Media Player Classic - Home Cinema (mpc-hc)播放器 ...
- Media Player 把光盘中的内容拷贝出来的方法
http://jingyan.baidu.com/article/cb5d610529f0c1005c2fe0b4.html 这个链接是通过Media Player 把光盘中的内容拷贝出来的方法h ...
- 20 Free Open Source Web Media Player Apps
free Media Players (Free MP3, Video, and Music Player ...) are cool because they let web developers ...
- Windows Media Player安装了却不能播放网页上的视频
前段时间遇到Windows Media Player安装了却不能播放网页上的视频的问题,在网上查找资料时,发现大部分资料都没能解决我这个问题.偶尔试了网上一牛人的方法,后来竟然解决了.现在再找那个网页 ...
随机推荐
- 网页显示UIWebView(一个)
1.scalesPageToFit设置为YES,这样web页面会依据屏幕大小进行自己主动缩放. 2.UIWebView的状态监视 //内容读入開始前被调用.将UIWebView,返回no后UIWebV ...
- uva 10635 Prince and Princess(LCS成问题LIS问题O(nlogn))
标题效果:有两个长度p+1和q+1该序列.的各种元素的每个序列不是相互同.并1~n^2之间的整数.个序列的第一个元素均为1. 求出A和B的最长公共子序列长度. 分析:本题是LCS问题,可是p*q< ...
- 理解Android虚拟机体系结构(转)
1 什么是Dalvik虚拟机 Dalvik是Google公司自己设计用于Android平台的Java虚拟机,它是Android平台的重要组成部分,支持dex格式(Dalvik Executable)的 ...
- Cts框架解析(7)-任务运行的调度室
TestInvocation /** * {@inheritDoc} */ @Override public void invoke(ITestDevice device, IConfiguratio ...
- ubuntu安装jdk eclipse mysql等
linux ubuntu下安装java web开发环境,需要安装包: jdk7 eclipse(选择java EE developer) apche-tomcat mysql(workbench可视化 ...
- android
简单的登录
一直都知道WEB通过登录后session拿着回答,如今,安卓不知道怎么弄的. 研究了一下,它记录.直接在代码: server结束: index.jsp <%@page import=" ...
- folat i = 0.1; 警告
今天的用途 float i = 0.1;那么编译器警告实际: #include <iostream> using namespace std; int main() { float k ...
- Android项目打包成APK文件
第一步:右键单击该项目选择Export项目 显演示样例如以下界面:选择Exprot Android Application 第二步:输入项目名称,默认的情况下是原始的项目名称 下一步: 点击 Crea ...
- 解决cocos2d-x-3.1.1新androidproject
下了个cocos2d-x-3.1.1,依照官方文档一步步配置win7下cocos2d-x-3.1.1的android开发环境,结果没有找到create_project.py这个文件.. 现将具体配置步 ...
- 从源码看Android中sqlite是怎么读DB的(转)
执行query 执行SQLiteDatabase类中query系列函数时,只会构造查询信息,不会执行查询. (query的源码追踪路径) 执行move(里面的fillwindow是真正打开文件句柄并分 ...