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