]> git.sesse.net Git - vlc/blob - bindings/cil/src/player.cs
Basic tests for the media player, fix time units
[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          */
112         public bool IsPlaying
113         {
114             get
115             {
116                 int ret = LibVLC.PlayerIsPlaying (Handle, ex);
117                 Raise ();
118                 return ret != 0;
119             }
120         }
121
122         /**
123          * Starts playing the selected media.
124          */
125         public void Play ()
126         {
127             LibVLC.PlayerPlay (Handle, ex);
128             Raise ();
129         }
130
131         /**
132          * Pauses the playback.
133          */
134         public void Pause ()
135         {
136             LibVLC.PlayerPause (Handle, ex);
137             Raise ();
138         }
139
140         /**
141          * Stops the playback.
142          */
143         public void Stop ()
144         {
145             LibVLC.PlayerStop (Handle, ex);
146             Raise ();
147         }
148
149         /**
150          * The 32-bits identifier of an X Window System window,
151          * or 0 if not specified.
152          * Video will be rendered inside that window, if the underlying VLC
153          * supports X11. Note that X pixmaps are <b>not</b> supported.
154          * Also note that you should set/change/unset the window while
155          * playback is not started or stopped; live reparenting might not
156          * work.
157          *
158          * <b>Warning:</b>
159          * If the identifier is invalid, Xlib might abort the process.
160          */
161         public int XWindow
162         {
163             get
164             {
165                 return LibVLC.PlayerGetXWindow (Handle);
166             }
167             set
168             {
169                 LibVLC.PlayerSetXWindow (Handle, value, ex);
170                 Raise ();
171             }
172         }
173
174         /**
175          * The handle of a window (HWND) from the Win32 API,
176          * or NULL if unspecified.
177          * Video will be rendered inside that window, if the underlying VLC
178          * supports one of DirectDraw, Direct3D, GDI or OpenGL/Win32.
179          * Note that you should set/change/unset the window while playback is
180          * not started or stopped; live reparenting might not work.
181          */
182         public SafeHandle HWND
183         {
184             get
185             {
186                 return LibVLC.PlayerGetHWND (Handle);
187             }
188             set
189             {
190                 LibVLC.PlayerSetHWND (Handle, value, ex);
191                 Raise ();
192             }
193         }
194
195         /**
196          * Total length in milliseconds of the playback (if known).
197          */
198         public long Length
199         {
200             get
201             {
202                 long ret = LibVLC.PlayerGetLength (Handle, ex);
203                 Raise ();
204                 return ret;
205             }
206         }
207
208         /**
209          * Playback position in milliseconds from the start (if applicable).
210          * Setting this value might not work depending on the underlying
211          * media capability and file format.
212          *
213          * Changing the Time will also change the Position.
214          */
215         public long Time
216         {
217             get
218             {
219                 long ret = LibVLC.PlayerGetTime (Handle, ex);
220                 Raise ();
221                 return ret;
222             }
223             set
224             {
225                 LibVLC.PlayerSetTime (Handle, value, ex);
226                 Raise ();
227             }
228         }
229
230         /**
231          * Playback position as a fraction of the total (if applicable).
232          * At start, this is 0; at the end, this is 1.
233          * Setting this value might not work depending on the underlying
234          * media capability and file format.
235          *
236          * Changing the Position will also change the Time.
237          */
238         public float Position
239         {
240             get
241             {
242                 float ret = LibVLC.PlayerGetPosition (Handle, ex);
243                 Raise ();
244                 return ret;
245             }
246             set
247             {
248                 LibVLC.PlayerSetPosition (Handle, value, ex);
249                 Raise ();
250             }
251         }
252
253         /**
254          * Number of the current chapter (within the current title).
255          * This is mostly used for DVDs and the likes.
256          */
257         public int Chapter
258         {
259             get
260             {
261                 int ret = LibVLC.PlayerGetChapter (Handle, ex);
262                 Raise ();
263                 return ret;
264             }
265             set
266             {
267                 LibVLC.PlayerSetChapter (Handle, value, ex);
268                 Raise ();
269             }
270         }
271
272         /**
273          * Number of chapters within the current title,
274          */
275         public int ChapterCount
276         {
277             get
278             {
279                 int ret = LibVLC.PlayerGetChapterCount (Handle, ex);
280                 Raise ();
281                 return ret;
282             }
283         }
284
285         /**
286          * Gets the number of chapters within a given title.
287          * @param title media title number
288          */
289         public int GetChapterCountByTitle (int title)
290         {
291             int ret = LibVLC.PlayerGetChapterCountForTitle (Handle, title, ex);
292             Raise ();
293             return ret;
294         }
295
296         /**
297          * Number of the current title.
298          */
299         public int Title
300         {
301             get
302             {
303                 int ret = LibVLC.PlayerGetTitle (Handle, ex);
304                 Raise ();
305                 return ret;
306             }
307             set
308             {
309                 LibVLC.PlayerSetTitle (Handle, value, ex);
310                 Raise ();
311             }
312         }
313
314         /**
315          * Total number of titles.
316          */
317         public int TitleCount
318         {
319             get
320             {
321                 int ret = LibVLC.PlayerGetTitleCount (Handle, ex);
322                 Raise ();
323                 return ret;
324             }
325         }
326
327         /**
328          * Skips to the beginning of the next chapter.
329          */
330         public void NextChapter ()
331         {
332             LibVLC.PlayerNextChapter (Handle, ex);
333             Raise ();
334         }
335
336         /**
337          * Rewinds to the previous chapter.
338          */
339         public void PreviousChapter ()
340         {
341             LibVLC.PlayerPreviousChapter (Handle, ex);
342             Raise ();
343         }
344
345         /**
346          * Media playback rate.
347          * 1.0 is the nominal rate.
348          * Less than one is slower than nominal.
349          * More than one is faster than nominal.
350          */
351         public float Rate
352         {
353             get
354             {
355                 float ret = LibVLC.PlayerGetRate (Handle, ex);
356                 Raise ();
357                 return ret;
358             }
359             set
360             {
361                 LibVLC.PlayerSetRate (Handle, value, ex);
362                 Raise ();
363             }
364         }
365
366         /**
367          * Frame rate in unit/seconds.
368          */
369         public float FramePerSeconds
370         {
371             get
372             {
373                 float ret = LibVLC.PlayerGetFPS (Handle, ex);
374                 Raise ();
375                 return ret;
376             }
377         }
378
379         /**
380          * Whether a video track is currently active.
381          * This is false if there is no video track, or if video is discarded.
382          */
383         public bool HasVideo
384         {
385             get
386             {
387                 int ret = LibVLC.PlayerHasVout (Handle, ex);
388                 Raise ();
389                 return ret != 0;
390             }
391         }
392
393         /**
394          * Whether the media supports seeking.
395          * Note that this tells nothing about the seeking precision.
396          */
397         public bool CanSeek
398         {
399             get
400             {
401                 int ret = LibVLC.PlayerIsSeekable (Handle, ex);
402                 Raise ();
403                 return ret != 0;
404             }
405         }
406
407         /**
408          * Whether the media supports pausing.
409          * Live content cannot be paused, unless timeshifting is enabled.
410          */
411         public bool CanPause
412         {
413             get
414             {
415                 int ret = LibVLC.PlayerCanPause (Handle, ex);
416                 Raise ();
417                 return ret != 0;
418             }
419         }
420     };
421 };