3 * @brief Media descriptor class
7 /**********************************************************************
8 * Copyright (C) 2007-2009 RĂ©mi Denis-Courmont. *
9 * This program is free software; you can redistribute and/or modify *
10 * it under the terms of the GNU General Public License as published *
11 * by the Free Software Foundation; version 2 of the license, or (at *
12 * your option) any later version. *
14 * This program is distributed in the hope that it will be useful, *
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
17 * See the GNU General Public License for more details. *
19 * You should have received a copy of the GNU General Public License *
20 * along with this program; if not, you can get it from: *
21 * http://www.gnu.org/copyleft/gpl.html *
22 **********************************************************************/
25 //using System.Collections.Generic;
26 using System.Runtime.InteropServices;
28 namespace VideoLAN.LibVLC
31 * @brief MediaHandle: unmanaged LibVLC media pointer
34 internal sealed class MediaHandle : NonNullHandle
37 * NonNullHandle.Destroy
39 protected override void Destroy ()
41 LibVLC.MediaRelease (handle);
46 * @brief State: media/player state
48 * Media and Player objects are always in one of these state.
49 * @see Media::State and @see Player::State.
53 NothingSpecial, /**< Nothing going on */
54 Opening, /**< Being opened */
55 Buffering, /**< Buffering before play */
56 Playing, /**< Playing */
57 Paused, /**< Paused */
58 Stopped, /**< Stopped */
59 Ended, /**< Played until the end */
64 * @brief Media: a source media
66 * Each media object represents an input media, such as a file or an URL.
68 public class Media : EventingObject, ICloneable
70 internal MediaHandle Handle
74 return handle as MediaHandle;
79 * Creates a Media object.
81 * @param instance VLC instance
82 * @param mrl Media Resource Locator (file path or URL)
84 public Media (VLC instance, string mrl)
86 U8String umrl = new U8String (mrl);
88 handle = LibVLC.MediaCreate (instance.Handle, umrl, ex);
93 * Add VLC input item options to the media.
95 * Media m = new Media(vlc, "http://www.example.com/music.ogg");
96 * m.AddOptions(":http-user-agent=LibVLC.Net "
97 * + ":http-proxy=proxy:8080", true);
99 * @param options VLC options in VLC input item format
100 * (see example below)
101 * @param trusted whether the options are set by a trusted agent
102 * (e.g. the local computer configuration) or not
103 * (e.g. a downloaded file).
104 * @version VLC 0.9.9 if trusted is false
106 public void AddOptions (string options, bool trusted)
108 U8String uopts = new U8String (options);
111 LibVLC.MediaAddOption (Handle, uopts, ex);
113 LibVLC.MediaAddUntrustedOption (Handle, uopts, ex);
118 * The media location (file path, URL, ...).
121 public string Location
125 StringHandle str = LibVLC.MediaGetMRL (Handle, ex);
127 return str.Transform ();
131 private Media (MediaHandle handle)
133 this.handle = handle;
137 * Duplicates a media object.
139 public object Clone ()
141 return new Media (LibVLC.MediaDuplicate (Handle));
145 * Current state of the media.
151 State ret = LibVLC.MediaGetState (Handle, ex);
157 internal override EventManagerHandle GetManager ()
159 return LibVLC.MediaEventManager (Handle, null);
163 * Duration of the media in microseconds. The precision of the result
164 * depends on the input stram protocol and file format. The value
165 * might be incorrect and unknown (VLC usually returns 0 or -1 then).
171 long duration = LibVLC.MediaGetDuration (Handle, ex);
178 * Whether the media was "preparsed". If true, the meta-infos were
179 * extracted, even before the media was played. This is normally only
180 * available if the input files is stored on a local filesystem.
182 public bool IsPreparsed
186 int preparsed = LibVLC.MediaIsPreparsed (Handle, ex);
188 return preparsed != 0;