/// <summary> /// Parse the media asynchronously with options. /// It uses a flag to specify parse options (see <see cref="MediaParseOptions"/>). All these flags can be combined. By default, the media is parsed only if it's a local file. /// <para/> Note: Parsing can be aborted with ParseStop(). /// </summary> /// <param name="options">Parse options flags. They can be combined</param> /// <param name="timeout">maximum time allowed to preparse the media. /// <para/>If -1, the default "preparse-timeout" option will be used as a timeout. /// <para/>If 0, it will wait indefinitely. If > 0, the timeout will be used (in milliseconds). /// </param> /// <param name="cancellationToken">token to cancel the operation</param> /// <returns>the parse status of the media</returns> public async Task <MediaParsedStatus> Parse(MediaParseOptions options = MediaParseOptions.ParseLocal, int timeout = -1, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); var tcs = new TaskCompletionSource <MediaParsedStatus>(); var cancellationTokenRegistration = cancellationToken.Register(() => { ParsedChanged -= OnParsedChanged; Native.LibVLCMediaParseStop(NativeReference); tcs.TrySetCanceled(); }); void OnParsedChanged(object sender, MediaParsedChangedEventArgs mediaParsedChangedEventArgs) => tcs.TrySetResult(mediaParsedChangedEventArgs.ParsedStatus); try { ParsedChanged += OnParsedChanged; var result = Native.LibVLCMediaParseWithOptions(NativeReference, options, timeout); if (result == -1) { tcs.TrySetResult(MediaParsedStatus.Failed); } return(await tcs.Task.ConfigureAwait(false)); } finally { cancellationTokenRegistration.Dispose(); ParsedChanged -= OnParsedChanged; } }
internal static extern int LibVLCMediaParseWithOptions(IntPtr media, MediaParseOptions mediaParseOptions, int timeout);
/// <summary>Parse the media asynchronously with options.</summary> /// <param name="parseOptions">parse options</param> /// <param name="timeout"> /// <para>maximum time allowed to preparse the media. If -1, the</para> /// <para>default "preparse-timeout" option will be used as a timeout. If 0, it will</para> /// <para>wait indefinitely. If > 0, the timeout will be used (in milliseconds).</para> /// </param> /// <returns>-1 in case of error, 0 otherwise</returns> /// <remarks> /// <para>This fetches (local or network) art, meta data and/or tracks information.</para> /// <para>This method is the extended version of libvlc_media_parse_with_options().</para> /// <para>To track when this is over you can listen to libvlc_MediaParsedChanged</para> /// <para>event. However if this functions returns an error, you will not receive any</para> /// <para>events.</para> /// <para>It uses a flag to specify parse options (see libvlc_media_parse_flag_t). All</para> /// <para>these flags can be combined. By default, media is parsed if it's a local</para> /// <para>file.</para> /// <para>Parsing can be aborted with libvlc_media_parse_stop().</para> /// <para>libvlc_MediaParsedChanged</para> /// <para>libvlc_media_get_meta</para> /// <para>libvlc_media_tracks_get</para> /// <para>libvlc_media_get_parsed_status</para> /// <para>libvlc_media_parse_flag_t</para> /// <para>LibVLC 3.0.0 or later</para> /// </remarks> public bool ParseWithOptions(MediaParseOptions parseOptions, int timeout = -1) { return(Internal.LibVLCMediaParseWithOptions(NativeReference, parseOptions, timeout) != 0); }