WPF播放器
最近由于工作需要,需要做一个播放软件,在网上参考了很多例子,园子里有很多代码。其中最多的就是wpf自带的MediaElement控件,或者VLC视频播放器。
先附我自己查询资料的链接:
MediaEmelent控件例子
http://www.cnblogs.com/gnielee/archive/2010/05/06/wpf4-media-player-mediaelement.html
http://blog.zhigui.org/2011/04/wpf-simple-player/
VLC
http://www.cnblogs.com/Gavin001/archive/2013/05/01/3053465.html
由于我电脑可能是Ghost系统 或者由于被优化了。我发现我的MediaElement无法播放任何视频。通过控制面板关闭媒体中心之后,再也打不开了。真是坑!!!
只能放弃自带控件,查到有一个VLC的NET版。so。。。
附vlc.dotnet的github链接
https://github.com/ZeBobo5/Vlc.DotNet
首先,自己在nuget里面下载所需要的扩展:
完成之后 就看示例代码咯,github里面是有example的
<Window x:Class="Vlc.DotNet.Wpf.Samples.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Vlc.DotNet.Wpf.Samples"
xmlns:wpf="clr-namespace:Vlc.DotNet.Wpf;assembly=Vlc.DotNet.Wpf"
mc:Ignorable="d"
Title="MainWindow" Height="" Width="">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions> <wpf:VlcControl Grid.Row="" x:Name="myControl"/> <Button Grid.Row="" Click="OnPlayButtonClick">Play</Button>
<Button Grid.Row="" Click="OnForwardButtonClick" x:Name="Forward">Forward</Button>
<Button Grid.Row="" Click="GetLength_Click" x:Name="GetLength">Get Length</Button>
<Button Grid.Row="" Click="GetCurrentTime_Click" x:Name="GetCurrentTime">Get Current Time</Button>
<Button Grid.Row="" Click="SetCurrentTime_Click" x:Name="SetCurrentTime">Set Current Time to 5s</Button>
</Grid>
</Window>
首先加上 xmlns:wpf="clr-namespace:Vlc.DotNet.Wpf;assembly=Vlc.DotNet.Wpf"
然后加上 <wpf:VlcControl Grid.Row="0" x:Name="myControl"/>
using System;
using System.IO;
using System.Reflection;
using System.Windows; namespace Vlc.DotNet.Wpf.Samples
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
myControl.MediaPlayer.VlcLibDirectoryNeeded += OnVlcControlNeedsLibDirectory;
} private void OnVlcControlNeedsLibDirectory(object sender, Forms.VlcLibDirectoryNeededEventArgs e)
{
var currentAssembly = Assembly.GetEntryAssembly();
var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;
if (currentDirectory == null)
return;
if (AssemblyName.GetAssemblyName(currentAssembly.Location).ProcessorArchitecture == ProcessorArchitecture.X86)
//vlc的dll路径,自己下载vlc播放器里面的libvlc.dll libvlccore.dll以及plugins文件夹
e.VlcLibDirectory = new DirectoryInfo(Path.Combine(currentDirectory, @"..\..\..\lib\x86\"));
else
e.VlcLibDirectory = new DirectoryInfo(Path.Combine(currentDirectory, @"..\..\..\lib\x64\"));
} private void OnPlayButtonClick(object sender, RoutedEventArgs e)
{
myControl.MediaPlayer.Play(new Uri("http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_surround-fix.avi"));
//myControl.MediaPlayer.Play(new FileInfo(@"..\..\..\Vlc.DotNet\Samples\Videos\BBB trailer.mov"));
} private void OnForwardButtonClick(object sender, RoutedEventArgs e)
{
myControl.MediaPlayer.Rate = ;
} private void GetLength_Click(object sender, RoutedEventArgs e)
{
GetLength.Content = myControl.MediaPlayer.Length + " ms";
} private void GetCurrentTime_Click(object sender, RoutedEventArgs e)
{
GetCurrentTime.Content = myControl.MediaPlayer.Time + " ms";
} private void SetCurrentTime_Click(object sender, RoutedEventArgs e)
{
myControl.MediaPlayer.Time = ;
SetCurrentTime.Content = myControl.MediaPlayer.Time + " ms";
}
}
}
代码地址为:https://github.com/ZeBobo5/Vlc.DotNet/blob/master/src/Samples/Vlc.DotNet.Wpf.Samples/
WPF播放器的更多相关文章
- 基于<MediaElement>的WPF视频播放器(可拖拽进度条播放)【1】
一.前言 前两天上峰要求做一个软件使用向导,使用WPF制作.这不,这两天从一张白纸开始学起,做一个播放演示视频的使用向导.以下是粗设计的原型代码: 二.效果图 三.代码 前台代码: < ...
- WPF技术触屏上的应用系列(四): 3D效果图片播放器(图片立体轮放、图片立体轮播、图片倒影立体滚动)效果实现
原文:WPF技术触屏上的应用系列(四): 3D效果图片播放器(图片立体轮放.图片立体轮播.图片倒影立体滚动)效果实现 去年某客户单位要做个大屏触屏应用,要对档案资源进行展示之用.客户端是Window7 ...
- 将WPF版的弹幕播放器给优化了一下
年前较闲的时候研究了一下WPF的性能优化,练手的时将之前写的弹幕播放器给重新写了一下.年前的时间不大够,没有写完,这两天接着弄了一下,基本上弄得差不多了. 主要重写了底层的渲染算法,优化后效果还是非常 ...
- 用WPF写了一个弹幕播放器
看弹幕视频的时候,如果不发弹幕,一个本地的弹幕播放器往往能带来更好的体验.目前已经有一些实现了,最初用过一个MukioPlayer, 后来又用过一个用C++写的BiliLocal,这个程序能自动下载弹 ...
- 简易音乐播放器主界面设计 - .NET CORE(C#) WPF开发
微信公众号:Dotnet9,网站:Dotnet9,问题或建议:请网站留言, 如果对您有所帮助:欢迎赞赏. 简易音乐播放器主界面设计 - .NET CORE(C#) WPF开发 阅读导航 本文背景 代码 ...
- 使用vlc进行二次开发做自己的播放器
可参考: 使用vlc播放器做rtsp服务器 使用vlc播放器播放rtsp视频 web网页中使用vlc插件播放相机rtsp流视频 使用 https://github.com/ZeBobo5/Vlc.Do ...
- WPF播放视频
在现在的项目中需要使用到播放视频的功能,本来打算使用VLC来做的.后来发现WPF 4.0之后新增了MediaElement类,可以实现视频播放. <Grid> <Grid.RowDe ...
- AR播放器
一.项目需求 AR播放器:将一系列带透明通道的图片以一定的帧率连续显示,叠加载摄像头采集的画面之上,并播放声音. 此为最初级的AR技术,因为画面是事先渲染好的,固定不变的,所以实际上并不能实现“互动” ...
- 基于VLC的播放器开发
VLC的C++封装 因为工作需要,研究了一段时间的播放器开发,如果从头开始做,可以学习下FFmpeg(http://www.ffmpeg.org/),很多播放器都是基于FFmpeg开发的,但是这样工作 ...
随机推荐
- Python 内置函数 day4
import random s = 'abczfg' st= {3,4,9,1,8} print(dir(random))#打印模块内的方法,输出模块/变量可以调用的方法 print(dir(s))# ...
- JSONP代码收藏
摘抄自jQuery,用于JSONP请求. var callback = 'callback_' + (new Date() - 0), url = 'http://localhost/', scrip ...
- Codeforces 939D - Love Rescue
传送门:http://codeforces.com/contest/939/problem/D 本题是一个数据结构问题——并查集(Disjoint Set). 给出两个长度相同,且仅由小写字母组成的字 ...
- random随机库
random库是用于产生并运用随机数的标准库 主要包含的有9个随机函数,分别是: seed(), random(), randint(), getrandbits(), randrange(), un ...
- 【Codeforces 1114C】Trailing Loves (or L'oeufs?)
[链接] 我是链接,点我呀:) [题意] 问你n!的b进制下末尾的0的个数 [题解] 证明:https://blog.csdn.net/qq_40679299/article/details/8116 ...
- Tomcat 7源码学习笔记 -9 tomcat重启后session仍然保留
使用Tomcat 7缺省的配置,tomcat关闭后重新启动,发现原来的session没有被删掉,用原来的request获取session仍然可以取到.但是并没有配置session持久化. 原因如下: ...
- Openfire:通过Servlet群发消息
在Openfire中自带有Broadcase插件,可以让我们群发消息给全部用户或者组.不过如果是我们通过Servlet来实现这一功能,那么是能够增加一定的灵活性的.具体做法直接看Demo代码: pub ...
- UVA 10891 区间DP+博弈思想
很明显带有博弈的味道.让A-B最大,由于双方都采用最佳策略,在博弈中有一个要求时,让一方的值尽量大.而且由于是序列,所以很容易想到状态dp[i][j],表示序列从i到j.结合博弈中的思想,表示初始状态 ...
- ASP.NET MVC 4源代码分析之怎样定位控制器
利用少有的空余时间.具体的浏览了下ASP.NET MVC 4的源代码.照着之前的步伐继续前进(尽管博客园已经存在非常多大牛对MVC源代码分析的博客,可是从个人出发.还是希望自己可以摸索出这些). 首先 ...
- GPS-Graph Processing System 改动源代码经验总结 (四)
HamaWhite原创,转载请注明出处.欢迎大家增加Giraph 技术交流群: 228591158 本文目的:在改动GPS源代码后,具体描写叙述怎样编译和分发到各Worker节点上. 以下以Graph ...