]> git.sesse.net Git - vlc/blob - bindings/cil/src/media.cs
60a61d9bee03055e5ac87eb91cf87605925a8767
[vlc] / bindings / cil / src / media.cs
1 /**
2  * @file media.cs
3  * @brief Media descriptor class
4  * @ingroup API
5  */
6
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.                                   *
13  *                                                                    *
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.              *
18  *                                                                    *
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  **********************************************************************/
23
24 using System;
25 //using System.Collections.Generic;
26 using System.Runtime.InteropServices;
27
28 namespace VideoLAN.LibVLC
29 {
30     /**
31      * @brief MediaHandle: unmanaged LibVLC media pointer
32      * @ingroup Internals
33      */
34     internal sealed class MediaHandle : NonNullHandle
35     {
36         /**
37          * NonNullHandle.Destroy
38          */
39         protected override void Destroy ()
40         {
41             LibVLC.MediaRelease (handle);
42         }
43     };
44
45     /**
46      * @brief State: media/player state
47      *
48      * Media and Player objects are always in one of these state.
49      * @see Media::State and @see Player::State.
50      */
51     public enum State
52     {
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 */
60         Error, /**< Failed */
61     };
62
63     /**
64      * @brief Media: a source media
65      * @ingroup API
66      * Each media object represents an input media, such as a file or an URL.
67      */
68     public class Media : BaseObject, ICloneable
69     {
70         internal MediaHandle Handle
71         {
72             get
73             {
74                 return handle as MediaHandle;
75             }
76         }
77
78         /**
79          * Creates a Media object.
80          *
81          * @param instance VLC instance
82          * @param mrl Media Resource Locator (file path or URL)
83          */
84         public Media (VLC instance, string mrl)
85         {
86             U8String umrl = new U8String (mrl);
87
88             handle = LibVLC.MediaCreate (instance.Handle, umrl, ex);
89             Raise ();
90         }
91
92         /**
93          * Add VLC input item options to the media.
94          * @code
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);
98          * @endcode
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
105          */
106         public void AddOptions (string options, bool trusted)
107         {
108             U8String uopts = new U8String (options);
109
110             if (trusted)
111                 LibVLC.MediaAddOption (Handle, uopts, ex);
112             else
113                 LibVLC.MediaAddUntrustedOption (Handle, uopts, ex);
114             Raise ();
115         }
116
117         /**
118          * The media location (file path, URL, ...).
119          * @version VLC 1.0
120          */
121         public string Location
122         {
123             get
124             {
125                 StringHandle str = LibVLC.MediaGetMRL (Handle, ex);
126                 Raise ();
127                 return str.Transform ();
128             }
129         }
130
131         private Media (MediaHandle handle)
132         {
133             this.handle = handle;
134         }
135
136         /**
137          * Duplicates a media object.
138          */
139         public object Clone ()
140         {
141             return new Media (LibVLC.MediaDuplicate (Handle));
142         }
143
144         /**
145          * Current state of the media.
146          */
147         public State State
148         {
149             get
150             {
151                 State ret = LibVLC.MediaGetState (Handle, ex);
152                 Raise ();
153                 return ret;
154             }
155         }
156
157         /**
158          * Duration of the media in microseconds. The precision of the result
159          * depends on the input stram protocol and file format. The value
160          * might be incorrect and unknown (VLC usually returns 0 or -1 then).
161          */
162         public long Duration
163         {
164             get
165             {
166                 long duration = LibVLC.MediaGetDuration (Handle, ex);
167                 Raise ();
168                 return duration;
169             }
170         }
171
172         /**
173          * Whether the media was "preparsed". If true, the meta-infos were
174          * extracted, even before the media was played. This is normally only
175          * available if the input files is stored on a local filesystem.
176          */
177         public bool IsPreparsed
178         {
179             get
180             {
181                 int preparsed = LibVLC.MediaIsPreparsed (Handle, ex);
182                 Raise ();
183                 return preparsed != 0;
184             }
185         }
186     };
187 };