]> git.sesse.net Git - vlc/blob - bindings/cil/src/player.cs
Version informations
[vlc] / bindings / cil / src / player.cs
1 /**
2  * @file player.cs
3  * @brief Media player class
4  * @ingroup API
5  *
6  * @defgroup API Managed interface to LibVLC
7  * This is the primary class library for .NET applications
8  * to embed and control LibVLC.
9  *
10  * @defgroup Internals LibVLC internals
11  * This covers internal marshalling functions to use the native LibVLC.
12  * Only VLC developpers should need to read this section.
13  */
14
15 /**********************************************************************
16  *  Copyright (C) 2009 RĂ©mi Denis-Courmont.                           *
17  *  This program is free software; you can redistribute and/or modify *
18  *  it under the terms of the GNU General Public License as published *
19  *  by the Free Software Foundation; version 2 of the license, or (at *
20  *  your option) any later version.                                   *
21  *                                                                    *
22  *  This program is distributed in the hope that it will be useful,   *
23  *  but WITHOUT ANY WARRANTY; without even the implied warranty of    *
24  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.              *
25  *  See the GNU General Public License for more details.              *
26  *                                                                    *
27  *  You should have received a copy of the GNU General Public License *
28  *  along with this program; if not, you can get it from:             *
29  *  http://www.gnu.org/copyleft/gpl.html                              *
30  **********************************************************************/
31
32 using System;
33 using System.Runtime.InteropServices;
34
35 namespace VideoLAN.LibVLC
36 {
37    /**
38      * @brief PlayerHandle: unmanaged LibVLC media player pointer
39      * @ingroup Internals
40      */
41     internal sealed class PlayerHandle : NonNullHandle
42     {
43         protected override void Destroy ()
44         {
45             LibVLC.PlayerRelease (handle);
46         }
47     };
48
49     /**
50      * @brief MediaPlayer: a simple media player
51      * @ingroup API
52      * Use this class to play a media.
53      */
54     public class Player : BaseObject
55     {
56         internal PlayerHandle Handle
57         {
58             get
59             {
60                 return handle as PlayerHandle;
61             }
62         }
63
64         Media media; /**< Active media */
65         /**
66          * The Media object that the MediaPlayer is using,
67          * or null if there is none.
68          */
69         public Media Media
70         {
71             get
72             {
73                 return media;
74             }
75             set
76             {
77                 MediaHandle mh = (value != null) ? value.Handle : null;
78
79                 LibVLC.PlayerSetMedia (Handle, mh, null);
80                 media = value;
81             }
82         }
83
84         /**
85          * Creates a player with no medias.
86          * An input media will be needed before this media player can be used.
87          *
88          * @param instance VLC instance
89          */
90         public Player (VLC instance)
91         {
92             this.media = null;
93             handle = LibVLC.PlayerCreate (instance.Handle, ex);
94             Raise ();
95         }
96
97         /**
98          * Creates a player object for a given a media.
99          *
100          * @param media media object
101          */
102         public Player (Media media)
103         {
104             this.media = media;
105             handle = LibVLC.PlayerCreateFromMedia (media.Handle, ex);
106             Raise ();
107         }
108
109         /**
110          * Whether the player is currently active.
111          * @version VLC 1.0
112          */
113         public bool IsPlaying
114         {
115             get
116             {
117                 int ret = LibVLC.PlayerIsPlaying (Handle, ex);
118                 Raise ();
119                 return ret != 0;
120             }
121         }
122
123         /**
124          * Starts playing the selected media.
125          */
126         public void Play ()
127         {
128             LibVLC.PlayerPlay (Handle, ex);
129             Raise ();
130         }
131
132         /**
133          * Pauses the playback.
134          */
135         public void Pause ()
136         {
137             LibVLC.PlayerPause (Handle, ex);
138             Raise ();
139         }
140
141         /**
142          * Stops the playback.
143          */
144         public void Stop ()
145         {
146             LibVLC.PlayerStop (Handle, ex);
147             Raise ();
148         }
149
150         /**
151          * The 32-bits identifier of an X Window System window,
152          * or 0 if not specified.
153          * Video will be rendered inside that window, if the underlying VLC
154          * supports X11. Note that X pixmaps are <b>not</b> supported.
155          * Also note that you should set/change/unset the window while
156          * playback is not started or stopped; live reparenting might not
157          * work.
158          *
159          * @warning If the identifier is invalid, Xlib might abort the process.
160          * @version VLC 1.0
161          */
162         public int XWindow
163         {
164             get
165             {
166                 return LibVLC.PlayerGetXWindow (Handle);
167             }
168             set
169             {
170                 LibVLC.PlayerSetXWindow (Handle, value, ex);
171                 Raise ();
172             }
173         }
174
175         /**
176          * The handle of a window (HWND) from the Win32 API,
177          * or NULL if unspecified.
178          * Video will be rendered inside that window, if the underlying VLC
179          * supports one of DirectDraw, Direct3D, GDI or OpenGL/Win32.
180          * Note that you should set/change/unset the window while playback is
181          * not started or stopped; live reparenting might not work.
182          * @version VLC 1.0
183          */
184         public SafeHandle HWND
185         {
186             get
187             {
188                 return LibVLC.PlayerGetHWND (Handle);
189             }
190             set
191             {
192                 LibVLC.PlayerSetHWND (Handle, value, ex);
193                 Raise ();
194             }
195         }
196
197         /**
198          * Total length in milliseconds of the playback (if known).
199          */
200         public long Length
201         {
202             get
203             {
204                 long ret = LibVLC.PlayerGetLength (Handle, ex);
205                 Raise ();
206                 return ret;
207             }
208         }
209
210         /**
211          * Playback position in milliseconds from the start (if applicable).
212          * Setting this value might not work depending on the underlying
213          * media capability and file format.
214          *
215          * Changing the Time will also change the Position.
216          */
217         public long Time
218         {
219             get
220             {
221                 long ret = LibVLC.PlayerGetTime (Handle, ex);
222                 Raise ();
223                 return ret;
224             }
225             set
226             {
227                 LibVLC.PlayerSetTime (Handle, value, ex);
228                 Raise ();
229             }
230         }
231
232         /**
233          * Playback position as a fraction of the total (if applicable).
234          * At start, this is 0; at the end, this is 1.
235          * Setting this value might not work depending on the underlying
236          * media capability and file format.
237          *
238          * Changing the Position will also change the Time.
239          */
240         public float Position
241         {
242             get
243             {
244                 float ret = LibVLC.PlayerGetPosition (Handle, ex);
245                 Raise ();
246                 return ret;
247             }
248             set
249             {
250                 LibVLC.PlayerSetPosition (Handle, value, ex);
251                 Raise ();
252             }
253         }
254
255         /**
256          * Number of the current chapter (within the current title).
257          * This is mostly used for DVDs and the likes.
258          */
259         public int Chapter
260         {
261             get
262             {
263                 int ret = LibVLC.PlayerGetChapter (Handle, ex);
264                 Raise ();
265                 return ret;
266             }
267             set
268             {
269                 LibVLC.PlayerSetChapter (Handle, value, ex);
270                 Raise ();
271             }
272         }
273
274         /**
275          * Number of chapters within the current title,
276          */
277         public int ChapterCount
278         {
279             get
280             {
281                 int ret = LibVLC.PlayerGetChapterCount (Handle, ex);
282                 Raise ();
283                 return ret;
284             }
285         }
286
287         /**
288          * Gets the number of chapters within a given title.
289          * @param title media title number
290          * @version VLC 1.0
291          */
292         public int GetChapterCountByTitle (int title)
293         {
294             int ret = LibVLC.PlayerGetChapterCountForTitle (Handle, title, ex);
295             Raise ();
296             return ret;
297         }
298
299         /**
300          * Number of the current title.
301          * @version VLC 1.0
302          */
303         public int Title
304         {
305             get
306             {
307                 int ret = LibVLC.PlayerGetTitle (Handle, ex);
308                 Raise ();
309                 return ret;
310             }
311             set
312             {
313                 LibVLC.PlayerSetTitle (Handle, value, ex);
314                 Raise ();
315             }
316         }
317
318         /**
319          * Total number of titles.
320          * @version VLC 1.0
321          */
322         public int TitleCount
323         {
324             get
325             {
326                 int ret = LibVLC.PlayerGetTitleCount (Handle, ex);
327                 Raise ();
328                 return ret;
329             }
330         }
331
332         /**
333          * Skips to the beginning of the next chapter.
334          * @version VLC 1.0
335          */
336         public void NextChapter ()
337         {
338             LibVLC.PlayerNextChapter (Handle, ex);
339             Raise ();
340         }
341
342         /**
343          * Rewinds to the previous chapter.
344          * @version VLC 1.0
345          */
346         public void PreviousChapter ()
347         {
348             LibVLC.PlayerPreviousChapter (Handle, ex);
349             Raise ();
350         }
351
352         /**
353          * Media playback rate.
354          * 1.0 is the nominal rate.
355          * Less than one is slower than nominal.
356          * More than one is faster than nominal.
357          */
358         public float Rate
359         {
360             get
361             {
362                 float ret = LibVLC.PlayerGetRate (Handle, ex);
363                 Raise ();
364                 return ret;
365             }
366             set
367             {
368                 LibVLC.PlayerSetRate (Handle, value, ex);
369                 Raise ();
370             }
371         }
372
373         /**
374          * Current state of the player.
375          */
376         public State State
377         {
378             get
379             {
380                 State ret = LibVLC.PlayerGetState (Handle, ex);
381                 Raise ();
382                 return ret;
383             }
384         }
385
386         /**
387          * Frame rate in unit/seconds.
388          */
389         public float FramePerSeconds
390         {
391             get
392             {
393                 float ret = LibVLC.PlayerGetFPS (Handle, ex);
394                 Raise ();
395                 return ret;
396             }
397         }
398
399         /**
400          * Whether a video track is currently active.
401          * This is false if there is no video track, or if video is discarded.
402          */
403         public bool HasVideo
404         {
405             get
406             {
407                 int ret = LibVLC.PlayerHasVout (Handle, ex);
408                 Raise ();
409                 return ret != 0;
410             }
411         }
412
413         /**
414          * Whether the media supports seeking.
415          * Note that this tells nothing about the seeking precision.
416          */
417         public bool CanSeek
418         {
419             get
420             {
421                 int ret = LibVLC.PlayerIsSeekable (Handle, ex);
422                 Raise ();
423                 return ret != 0;
424             }
425         }
426
427         /**
428          * Whether the media supports pausing.
429          * Live content cannot be paused, unless timeshifting is enabled.
430          */
431         public bool CanPause
432         {
433             get
434             {
435                 int ret = LibVLC.PlayerCanPause (Handle, ex);
436                 Raise ();
437                 return ret != 0;
438             }
439         }
440     };
441 };