Table of Contents

Class Media

Namespace
LibVLCSharp.Shared
Assembly
LibVLCSharp.dll

Media is an abstract representation of a playable media. It can be a network stream or a local video/audio file.

public class Media : Internal, IDisposable
Inheritance
Media
Implements
Inherited Members

Constructors

Media(LibVLC, MediaInput, params string[])

Create a media from a MediaInput requires libvlc 3.0 or higher

public Media(LibVLC libVLC, MediaInput input, params string[] options)

Parameters

libVLC LibVLC

the libvlc instance

input MediaInput

the media to be used by libvlc. LibVLCSharp will NOT dispose or close it. Use StreamMediaInput or implement your own.

options string[]

the libvlc options, in the form of ":your-option"

Media(LibVLC, int, params string[])

Create a media for an already open file descriptor. The file descriptor shall be open for reading(or reading and writing).

Regular file descriptors, pipe read descriptors and character device descriptors(including TTYs) are supported on all platforms. Block device descriptors are supported where available. Directory descriptors are supported on systems that provide fdopendir(). Sockets are supported on all platforms where they are file descriptors, i.e.all except Windows.

\note This library will not automatically close the file descriptor under any circumstance.Nevertheless, a file descriptor can usually only be rendered once in a media player.To render it a second time, the file descriptor should probably be rewound to the beginning with lseek().

public Media(LibVLC libVLC, int fd, params string[] options)

Parameters

libVLC LibVLC

A libvlc instance

fd int

open file descriptor

options string[]

the libvlc options, in the form of ":your-option"

Media(LibVLC, string, FromType, params string[])

Media Constructs a libvlc Media instance

public Media(LibVLC libVLC, string mrl, FromType type = FromType.FromPath, params string[] options)

Parameters

libVLC LibVLC

A libvlc instance

mrl string

A path, location, or node name, depending on the 3rd parameter

type FromType

The type of the 2nd argument.

options string[]

the libvlc options, in the form of ":your-option"

Media(LibVLC, Uri, params string[])

Media Constructs a libvlc Media instance

public Media(LibVLC libVLC, Uri uri, params string[] options)

Parameters

libVLC LibVLC

A libvlc instance

uri Uri

The absolute URI of the resource.

options string[]

the libvlc options, in the form of ":your-option"

Media(MediaList)

Create a media from a media list

public Media(MediaList mediaList)

Parameters

mediaList MediaList

media list to create media from

Properties

Duration

Get duration (in ms) of media descriptor object item.

public long Duration { get; }

Property Value

long

duration of media item or -1 on error

IsParsed

Return true is the media descriptor object is parsed

public bool IsParsed { get; }

Property Value

bool

true if media object has been parsed otherwise it returns false

Mrl

Get the media resource locator (mrl) from a media descriptor object

public string Mrl { get; }

Property Value

string

ParsedStatus

Get Parsed status for media descriptor object.

public MediaParsedStatus ParsedStatus { get; }

Property Value

MediaParsedStatus

a value of the libvlc_media_parsed_status_t enum

Remarks

libvlc_MediaParsedChanged

libvlc_media_parsed_status_t

LibVLC 3.0.0 or later

Slaves

Get a media descriptor's slave list

public MediaSlave[] Slaves { get; }

Property Value

MediaSlave[]

the number of slaves (zero on error)

Remarks

The list will contain slaves parsed by VLC or previously added by

libvlc_media_slaves_add(). The typical use case of this function is to save

a list of slave in a database for a later use.

LibVLC 3.0.0 and later.

libvlc_media_slaves_add

State

Get current VLCState of media descriptor object.

public VLCState State { get; }

Property Value

VLCState

Statistics

Get the current statistics about the media structure that contain the statistics about the media

public MediaStats Statistics { get; }

Property Value

MediaStats

SubItems

Get subitems of media descriptor object. This will increment

the reference count of supplied media descriptor object. Use

libvlc_media_list_release() to decrement the reference counting.

public MediaList SubItems { get; }

Property Value

MediaList

list of media descriptor subitems or NULL

Tracks

Get media descriptor's elementary streams description

address to store an allocated array of Elementary Streams

descriptions (must be freed with libvlc_media_tracks_release

by the caller) [OUT]

the number of Elementary Streams (zero on error)

Note, you need to call libvlc_media_parse() or play the media at least once

before calling this function.

Not doing this will result in an empty array.

LibVLC 2.1.0 and later.

public MediaTrack[] Tracks { get; }

Property Value

MediaTrack[]

Type

The type of the media

public MediaType Type { get; }

Property Value

MediaType

Methods

AddOption(MediaConfiguration)

Convenience method for crossplatform media configuration

public void AddOption(MediaConfiguration mediaConfiguration)

Parameters

mediaConfiguration MediaConfiguration

mediaConfiguration translate to strings parsed by the vlc engine, some are platform specific

AddOption(string)

Add an option to the media.

        <pre><code class="lang-csharp">// example 
        media.AddOption(":no-audio");</code></pre>
        </example>
public void AddOption(string option)

Parameters

option string

the media option, in the form of ":your-option"

Remarks

This option will be used to determine how the media_player will

read the media. This allows to use VLC's advanced

reading/streaming options on a per-media basis.

The options are listed in 'vlc --long-help' from the command line,

e.g. "-sout-all". Keep in mind that available options and their semantics

vary across LibVLC versions and builds.

Not all options affects libvlc_media_t objects:

Specifically, due to architectural issues most audio and video options,

such as text renderer options, have no effects on an individual media.

These options must be set through libvlc_new() instead.

AddOptionFlag(string, uint)

Add an option to the media with configurable flags.

public void AddOptionFlag(string option, uint flags)

Parameters

option string

the media option

flags uint

the flags for this option

Remarks

This option will be used to determine how the media_player will

read the media. This allows to use VLC's advanced

reading/streaming options on a per-media basis.

The options are detailed in vlc --long-help, for instance

"--sout-all". Note that all options are not usable on medias:

specifically, due to architectural issues, video-related options

such as text renderer options cannot be set on a single media. They

must be set on the whole libvlc instance instead.

AddSlave(MediaSlaveType, uint, string)

Add a slave to the current media.

public bool AddSlave(MediaSlaveType type, uint priority, string uri)

Parameters

type MediaSlaveType

subtitle or audio

priority uint

from 0 (low priority) to 4 (high priority)

uri string

Uri of the slave (should contain a valid scheme).

Returns

bool

true on success, false on error.

Remarks

A slave is an external input source that may contains an additional subtitle

track (like a .srt) or an additional audio track (like a .ac3).

This function must be called before the media is parsed (via

libvlc_media_parse_with_options()) or before the media is played (via

libvlc_media_player_play())

LibVLC 3.0.0 and later.

AddSlave(MediaSlaveType, uint, Uri)

Add a slave to the current media.

public bool AddSlave(MediaSlaveType type, uint priority, Uri uri)

Parameters

type MediaSlaveType

subtitle or audio

priority uint

from 0 (low priority) to 4 (high priority)

uri Uri

Uri of the slave (should contain a valid scheme).

Returns

bool

true on success, false on error.

Remarks

A slave is an external input source that may contains an additional subtitle

track (like a .srt) or an additional audio track (like a .ac3).

This function must be called before the media is parsed (via

libvlc_media_parse_with_options()) or before the media is played (via

libvlc_media_player_play())

LibVLC 3.0.0 and later.

ClearSlaves()

Clear all slaves previously added by libvlc_media_slaves_add() or

internally.

public void ClearSlaves()

Remarks

LibVLC 3.0.0 and later.

CodecDescription(TrackType, uint)

Get a media's codec description

public string CodecDescription(TrackType type, uint codec)

Parameters

type TrackType

The type of the track

codec uint

the codec or fourcc

Returns

string

the codec description

Duplicate()

Duplicate a media descriptor object.

public Media Duplicate()

Returns

Media

Equals(object?)

Equality override for this media instance

public override bool Equals(object? obj)

Parameters

obj object

the media to compare this one with

Returns

bool

GetHashCode()

Custom hascode implemenation for this Media instance

public override int GetHashCode()

Returns

int

the hashcode for this Media instance

Meta(MetadataType)

Read the meta of the media.

public string? Meta(MetadataType metadataType)

Parameters

metadataType MetadataType

the meta to read

Returns

string

the media's meta

Remarks

If the media has not yet been parsed this will return NULL.

Parse(MediaParseOptions, int, CancellationToken)

Parse the media asynchronously with options.
It uses a flag to specify parse options (see MediaParseOptions). All these flags can be combined. By default, the media is parsed only if it's a local file.

Note: Parsing can be aborted with ParseStop().
public Task<MediaParsedStatus> Parse(MediaParseOptions options = MediaParseOptions.ParseLocal, int timeout = -1, CancellationToken cancellationToken = default)

Parameters

options MediaParseOptions

Parse options flags. They can be combined

timeout int

maximum time allowed to preparse the media.

If -1, the default "preparse-timeout" option will be used as a timeout.

If 0, it will wait indefinitely. If > 0, the timeout will be used (in milliseconds).
cancellationToken CancellationToken

token to cancel the operation

Returns

Task<MediaParsedStatus>

the parse status of the media

ParseStop()

Stop the parsing of the media

public void ParseStop()

Remarks

When the media parsing is stopped, the libvlc_MediaParsedChanged event will

be sent with the libvlc_media_parsed_status_timeout status.

libvlc_media_parse_with_options

LibVLC 3.0.0 or later

SaveMeta()

Save the meta previously set

public bool SaveMeta()

Returns

bool

true if the write operation was successful

SetMeta(MetadataType, string)

Set the meta of the media (this function will not save the meta, call

libvlc_media_save_meta in order to save the meta)

public void SetMeta(MetadataType metadataType, string metaValue)

Parameters

metadataType MetadataType

the MetadataType to write

metaValue string

the media's meta

Events

DurationChanged

The duration of the media changed

public event EventHandler<MediaDurationChangedEventArgs> DurationChanged

Event Type

EventHandler<MediaDurationChangedEventArgs>

MediaFreed

The media was freed on the native side

public event EventHandler<MediaFreedEventArgs> MediaFreed

Event Type

EventHandler<MediaFreedEventArgs>

MetaChanged

The meta information changed

public event EventHandler<MediaMetaChangedEventArgs> MetaChanged

Event Type

EventHandler<MediaMetaChangedEventArgs>

ParsedChanged

The parsing status changed

public event EventHandler<MediaParsedChangedEventArgs> ParsedChanged

Event Type

EventHandler<MediaParsedChangedEventArgs>

StateChanged

The media state changed

public event EventHandler<MediaStateChangedEventArgs> StateChanged

Event Type

EventHandler<MediaStateChangedEventArgs>

SubItemAdded

A sub item was added to this media's MediaList

public event EventHandler<MediaSubItemAddedEventArgs> SubItemAdded

Event Type

EventHandler<MediaSubItemAddedEventArgs>

SubItemTreeAdded

A sub item tree was added to this media

public event EventHandler<MediaSubItemTreeAddedEventArgs> SubItemTreeAdded

Event Type

EventHandler<MediaSubItemTreeAddedEventArgs>