-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
101 lines (87 loc) · 3.2 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.IO;
using System.Reflection;
using System.Windows;
using Vlc.DotNet.Core;
using Vlc.DotNet.Wpf;
namespace VLC.NetTest
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
// a reference to the VLC control
private VlcControl control;
// A path to the VLC files
private DirectoryInfo VlcLibDirectory = GetVlcLibDirectory();
// A default internet location for stream testing
private string internetStreamPath = @"rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov";
public MainWindow()
{
InitializeComponent();
// Instantiate the player
SetupNewVlcPlayer();
// Hook up the media events for error handling
HookPlayerEvents();
// Add it to the UI
mainGrid.Children.Add(control);
// Start playing
PlayStream(internetStreamPath);
}
private void HookPlayerEvents()
{
this.control.SourceProvider.MediaPlayer.EncounteredError += MediaPlayer_EncounteredError; ;
this.control.SourceProvider.MediaPlayer.EndReached += MediaPlayer_EndReached; ;
}
private void MediaPlayer_EndReached(object sender, VlcMediaPlayerEndReachedEventArgs e)
{
throw new NotImplementedException();
}
private void MediaPlayer_EncounteredError(object sender, VlcMediaPlayerEncounteredErrorEventArgs e)
{
throw new NotImplementedException();
}
private void SetupNewVlcPlayer()
{
// Set up the objects
this.control = new VlcControl();
this.control.Background = System.Windows.Media.Brushes.Transparent;
var options = new string[]
{
"--file-logging",
"-vvv",
"--extraintf=logger",
"--logfile=Logs.log"
};
this.control.SourceProvider.CreatePlayer(this.VlcLibDirectory, options);
this.control.SourceProvider.MediaPlayer.Audio.Volume = 0;
}
public void PlayStream(string mediaPath)
{
if (this.control.SourceProvider.MediaPlayer != null)
{
// Restart if you reach the end of the media
//string[] mediaOptions = { "input-repeat=65535" };
string[] mediaOptions = { };
Uri mediaUri;
try
{
mediaUri = new Uri(mediaPath);
this.control.SourceProvider.MediaPlayer.SetMedia(mediaUri, mediaOptions);
this.control.SourceProvider.MediaPlayer.Play();
}
catch
{
return;
}
}
}
private static DirectoryInfo GetVlcLibDirectory()
{
var currentDirectory = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
var libDirectory = new DirectoryInfo(System.IO.Path.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64"));
return libDirectory;
}
}
}