Commit a1b4974f authored by Martin Finkel's avatar Martin Finkel
Browse files

update HLS sample

parent 986288b8
......@@ -9,23 +9,28 @@ namespace RecordHLS
static void Main(string[] args)
// Record in a file "record.ts" located in the bin folder next to the app
var currentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
var destination = Path.Combine(currentDirectory, "record.ts");
// Load native libvlc library
using (var libvlc = new LibVLC())
using (var mediaPlayer = new MediaPlayer(libvlc))
// Redirect log output to the console
libvlc.Log += (sender, e) => Console.WriteLine($"[{e.Level}] {e.Module}:{e.Message}");
// Create new media with HLS link
var media = new Media(libvlc, "", Media.FromType.FromLocation);
// Define stream output options.
// In this case stream to a file with given path and play locally the stream while streaming it.
media.AddOption(":sout=#file{dst=" + destination + "}");
mediaPlayer.TimeChanged += MediaPlayer_TimeChanged;
mediaPlayer.Opening += MediaPlayer_Opening;
mediaPlayer.PositionChanged += MediaPlayer_PositionChanged;
mediaPlayer.EndReached += MediaPlayer_EndReached;
// Start recording
Console.WriteLine($"Recording in {destination}");
......@@ -33,25 +38,5 @@ namespace RecordHLS
private static void MediaPlayer_EndReached(object sender, EventArgs e)
Console.WriteLine("End reached");
private static void MediaPlayer_PositionChanged(object sender, MediaPlayerPositionChangedEventArgs e)
Console.WriteLine($"position: {e.Position}");
private static void MediaPlayer_Opening(object sender, EventArgs e)
Console.WriteLine("Opening... ");
private static void MediaPlayer_TimeChanged(object sender, MediaPlayerTimeChangedEventArgs e)
Console.WriteLine($"time: {e.Time}");
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PackageReference Include="LibVLCSharp" Version="0.0.2" />
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="3.0.0-alpha3" />
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment