Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Martin Finkel
libvlcsharp-samples
Commits
a1b4974f
Commit
a1b4974f
authored
Oct 09, 2018
by
Martin Finkel
Browse files
update HLS sample
parent
986288b8
Changes
2
Hide whitespace changes
Inline
Side-by-side
RecordHLS/RecordHLS/Program.cs
View file @
a1b4974f
...
...
@@ -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
Core
.
Initialize
();
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
,
"http://hls1.addictradio.net/addictrock_aac_hls/playlist.m3u8"
,
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
+
"}"
);
media
.
AddOption
(
":sout-keep"
);
mediaPlayer
.
TimeChanged
+=
MediaPlayer_TimeChanged
;
mediaPlayer
.
Opening
+=
MediaPlayer_Opening
;
mediaPlayer
.
PositionChanged
+=
MediaPlayer_PositionChanged
;
mediaPlayer
.
EndReached
+=
MediaPlayer_EndReached
;
// Start recording
mediaPlayer
.
Play
(
media
);
Console
.
WriteLine
(
$"Recording in
{
destination
}
"
);
...
...
@@ -33,25 +38,5 @@ namespace RecordHLS
Console
.
ReadKey
();
}
}
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
RecordHLS/RecordHLS/RecordHLS.csproj
View file @
a1b4974f
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<RuntimeIdentifiers>win7-x64;win7-x86</RuntimeIdentifiers>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<TargetFramework>netcoreapp2.1</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LibVLCSharp" Version="0.0.2" />
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="3.0.0-alpha3" />
</ItemGroup>
</Project>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment