WPF使用VLC播放本地和流媒体视频 循环播放

您所在的位置:网站首页 vlc流媒体卡顿 WPF使用VLC播放本地和流媒体视频 循环播放

WPF使用VLC播放本地和流媒体视频 循环播放

2024-05-07 23:03| 来源: 网络整理| 查看: 265

1、创建wpf项目

 

 

 2、使用Nuget安装vlc,选择vlc.docnet.wpf

 

 3、xaml中添加vlc

 

 4、编写cs代码

 

 trsp协议的视频源 公开的不好找,网上有的基本没法使用,可以自己找个视频用VLC软件输出一个rtsp协议的视频流进行测试。

5、注意事项

首先 需要安装VLC,然后将VLC整体拷贝到项目的输出目录,比如debug目录下;

 

 

 

 

另外,下载安装时,一定要注意VLC的版本,如果你的项目是默认anycpu,那么就需要安装32位的VLC,

如果指定输出64位,那么久安装64位的VLC

 

 最后源码

MainWindow.xaml

1 10 11 12 13 View Code

MainWindow.xaml.cs

1 using System; 2 using System.Collections.Generic; 3 using System.IO; 4 using System.Linq; 5 using System.Text; 6 using System.Threading.Tasks; 7 using System.Windows; 8 using System.Windows.Controls; 9 using System.Windows.Data; 10 using System.Windows.Documents; 11 using System.Windows.Input; 12 using System.Windows.Media; 13 using System.Windows.Media.Imaging; 14 using System.Windows.Navigation; 15 using System.Windows.Shapes; 16 17 namespace wpfVlcDemo 18 { 19 /// 20 /// MainWindow.xaml 的交互逻辑 21 /// 22 public partial class MainWindow : Window 23 { 24 //获取输出目录 25 private static string appPath = AppDomain.CurrentDomain.BaseDirectory; 26 //vlc文件的地址 27 private DirectoryInfo vlcLibDirectory = new DirectoryInfo(appPath + @"VLC"); 28 //配置项 29 string[] options = new string[] 30 { 31 // VLC options can be given here. Please refer to the VLC command line documentation. 32 }; 33 public MainWindow() 34 { 35 InitializeComponent(); 36 //创建播放器 37 this.vlcControl.SourceProvider.CreatePlayer(vlcLibDirectory, options); 38 //http协议视频流 39 //this.vlcControl.SourceProvider.MediaPlayer.Play(new Uri("http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8")); 40 //rtmp协议 41 //this.vlcControl.SourceProvider.MediaPlayer.Play(new Uri("rtmp://58.200.131.2:1935/livetv/hunantv")); 42 //本地视频 43 this.vlcControl.SourceProvider.MediaPlayer.Play(new Uri("d:/1.avi")); 44 //添加播放结束事件 45 //其他事件 请自行查看 46 this.vlcControl.SourceProvider.MediaPlayer.EndReached += MediaPlayerEndEvent; 47 48 } 49 private void MediaPlayerEndEvent(object sender,Vlc.DotNet.Core.VlcMediaPlayerEndReachedEventArgs e) 50 { 51 //播放结束,循环播放本地视频 52 Task.Factory.StartNew(() => { 53 this.vlcControl.Dispose(); 54 Application.Current.Dispatcher.BeginInvoke(new Action(() => { 55 this.vlcControl.SourceProvider.CreatePlayer(vlcLibDirectory); 56 this.vlcControl.SourceProvider.MediaPlayer.Play(new Uri("d:/1.avi")); 57 this.vlcControl.SourceProvider.MediaPlayer.EndReached += MediaPlayerEndEvent; 58 })); 59 }); 60 } 61 } 62 } View Code


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3