libvlc media player in C# (part 1)
原文 http://www.helyar.net/2009/libvlc-media-player-in-c/
There seems to be a massive misconception about using VLC inside an application and many, many large wrapper libraries have been written. These are often harder to use than libvlc itself, buggy or just downright don’t work (at least not in what will be “the latest” version of VLC at the time you want to write anything).
Using the libvlc documentation directly and the libvlc example I wrote a simple wrapper class that performs the basics needed to play, pause and stop media. Because it is libvlc, things like resizing the video, toggling full screen by double clicking the video output or streaming media from a source device or network are handled automatically.
This code was all written and tested with VLC 0.98a but because it is taken from the documentation and example, it should work for all versions 0.9x and later with only minor changes. Because it is so simple, these changes should be easy to make. Most of the time, these changes will just be slight function name changes and no new re-structuring is needed.
The first thing to note is that there is no version of libvlc for Windows x64. All developers should set their CPU type to x86, even if they have a 32bit machine. If you set it to “Any CPU” then 64bit users will not be able to load libvlc.dll and will crash out. If you are compiling from the command line, this should look something like csc /platform:x86 foobar.cs
The second thing to note, which trips up a lot of users, is that you must specify VLC’s plugin directory. This may make distribution a nightmare, as the plugin directory is a large directory full of DLLs. It may be possible to narrow down these DLLs to just the ones your application actually needs but I don’t know if videolan have any advice about or licensing for redistribution of these.
libvlc is made up of several modules. For the sake of simplicity in this example, I will use 1 static class to contain every exported C function and split them up visually by module with #region
.
The nicest thing about VLC, as far as interop with C# goes, is that all memory management is handled internally by libvlc and functions are provided for doing anything that you would need to do to their members. This means that using an IntPtr is suitable for almost everything. You just need to make sure that you pass the correct IntPtr into each function but another layer of C# encapsulating this would easily be able to make sure of that, as discussed in part 2. The only structure that you need to define is an exception, which is very simple. You then simply always pass in references to these structs with ref ex
.
The code listing for the wrapper class is as follows:
|
For a sample application to use this simple wrapper, I just created a new Windows form and added a play button, stop button and a panel for viewing the video. In this example, the stop button also cleans everything up so you should make sure to press it before closing the form.
At one point during this code, libvlc can optionally be given a HWND to draw to. If you don’t give it one, it pops up a new player. However, people seem to be confused over how simple this is to do in C# and have been making large amounts of interop calls to the Win32 API to get handles. This is not necessary, as System.Windows.Forms.Control.Handle allows you go get the window handle (HWND) to any component that inherits from the Control class. This includes the Form class and the Panel class (and even the Button class) so all you actually need to pass it is this.Handle (for the handle to the form itself) or panel.Handle (for a Panel called panel). If you want it to start fullscreen, add the command line argument “-f” rather than using the Win32 function GetDesktopWindow().
Because I will be using this to display PAL video, which is interlaced at 576i, I have added some deinterlacing options to the command line. These are --vout-filter=deinterlace
and --deinterlace-mode=blend
.
Without further ado, here is the code listing for the partial windows form class:
|
Note that this section of code is deprecated and the code from part 2 should be used instead.
Adding a pause button is similar to the stop button but without the cleanup.
Here is an example slightly further on down the line but using the same code:
转载于:https://www.cnblogs.com/lonelyxmas/p/3984769.html
libvlc media player in C# (part 1)相关推荐
- 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 play ...
- 【流媒体开发】VLC Media Player - Android 平台源码编译 与 二次开发详解 (提供详细800M下载好的编译源码及eclipse可调试播放器源码下载)
作者 : 韩曙亮 博客地址 : http://blog.csdn.net/shulianghan/article/details/42707293 转载请注明出处 : http://blog.csd ...
- Unity3d C# 使用Universal Media Player(ump)插件播放视频的众坑之无法播放视频和VLC播放器依赖的问题
前言 Ump播放视频的坑,相信很多人都踩过了很多了,这个问题是必须VLC播放器的问题,我默认导入UMP Pro Win Mac Linux WebGL 2.0.3后,设置界面是这样的: 并且无法去除U ...
- VLC media player ActiveX控件制作
昨天折腾折腾这个折腾了一天.大致干了这几件事: 一,重新制作VLC安装包,去掉一些不必要的东东,设置一些必要的东东 二,制作ActiveX cab包 三,给CAB包加数字签名 四,调用代码 一,重新制 ...
- 用Windows Media Player截图的方法
视频截图方法: 关闭"视频加速功能即可". 以Windows Media Player 9.0为例,选择菜单"工具→选项",找到"性能"选项 ...
- 【Qt】Qt再学习(八):Media Player(Qt实现多媒体播放器)
1.简介 Media Player演示了一个简单的多媒体播放器,该播放器可以使用各种编解码器播放音频和/或视频文件. 涉及到的类有 QMediaPlayer.QMediaPlaylist.QVideo ...
- Media Player网页播放音频,视频,图片总汇
播放MP3 url为MP3文件的路径,width,height为播放器大小 1 privatestring mp3(string url,intwidth,intheight)2 {3 return@ ...
- Windows Media Player 损坏提示“出现了内部应用程序错误解决方法
在线看电影的时候图像花屏,更换浏览器都无法解决.每次开启在线电影的时候提示Windows Media Player 损坏提示"出现了内部应用程序错误".笔者尝试在Windows组件 ...
- [Winform]Media Player组件全屏播放的设置
摘要 在设置程序开始运行时,让视频全屏播放时,直接设置 windowsMediaPlay.fullScreen = true; 会报错,代码如下 windowsMediaPlay.URL =_vide ...
最新文章
- SpringMVC_实现简单的增删改查
- mac设置linux环境,如何在mac或者linux配置oh-my-zsh
- UA MATH567 高维统计IV Lipschitz组合4 对称群上的均匀分布
- mybatis$和#的区别
- 牛客挑战赛53G-同源数组(Easy Version)【NTT】
- GC对吞吐量和延迟的影响
- mysql inode_Linux中inode的大小、作用讲述
- SQL自动检查神器,再也不用担心SQL出错了,自动补全、回滚等功能大全
- SolarWinds 攻击者开发的新后门 FoggyWeb
- ip地址理解 192.168.19.255/20
- 计算机离散数学视频教程,离散数学(全105讲)【理工学社】
- 什么是串行接口和并行接口
- 接触式光电位移传感器的原理是
- 西瓜视频稳定性治理体系建设三:Sliver 原理及实践
- 微信浏览器中进行支付宝支付
- Python 每日一记217根据词频生成词云图
- 电镀清洗水中提取黄金的方法?
- C#零基础运动控制教程--运动控制卡低速高速运动实验
- UA OPTI501 电磁波 求解麦克斯韦方程组的Fourier方法1 在频域中讨论麦克斯韦方程组
- des加解密(JavaScriptJava)
热门文章
- mysql的time格式化_【mysql格式化日期】
- php岗位专业技能,PHP简历专业技能怎么写
- css代码总结,css属性代码大全总结(一)
- 接口规范 11. 串流相关接口
- java 排序 1和1_新手入门-冒泡排序和选择排序第一节排序1.1排序概述排序(
- java中string类相等_Java中String类的常见面试题
- C语言 const、volatile、const volatile限定符理解
- notepad++查看16进制文件
- keras笔记(4)-使用Keras训练大规模数据集
- Spring源码分析之ProxyFactoryBean方式实现Aop功能的分析