3 * @brief Media player class
6 * @defgroup API Managed interface to LibVLC
7 * This is the primary class library for .NET applications
8 * to embed and control LibVLC.
10 * @defgroup Internals LibVLC internals
11 * This covers internal marshalling functions to use the native LibVLC.
12 * Only VLC developers should need to read this section.
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. *
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. *
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 **********************************************************************/
33 using System.Runtime.InteropServices;
35 namespace VideoLAN.LibVLC
38 * @brief PlayerHandle: unmanaged LibVLC media player pointer
41 internal sealed class PlayerHandle : NonNullHandle
43 protected override void Destroy ()
45 LibVLC.PlayerRelease (handle);
50 * @brief MediaPlayer: a simple media player
52 * Use this class to play a media.
54 public class Player : EventingObject
56 internal PlayerHandle Handle
60 return handle as PlayerHandle;
64 Media media; /**< Active media */
66 * The Media object that the MediaPlayer is using,
67 * or null if there is none.
77 MediaHandle mh = (value != null) ? value.Handle : null;
79 LibVLC.PlayerSetMedia (Handle, mh, null);
85 * Creates a player with no medias.
86 * An input media will be needed before this media player can be used.
88 * @param instance VLC instance
90 public Player (VLC instance)
93 handle = LibVLC.PlayerCreate (instance.Handle, ex);
98 * Creates a player object for a given a media.
100 * @param media media object
102 public Player (Media media)
105 handle = LibVLC.PlayerCreateFromMedia (media.Handle, ex);
109 internal override EventManagerHandle GetManager ()
111 return LibVLC.PlayerEventManager (Handle, null);
115 * Whether the player is currently active.
118 public bool IsPlaying
122 int ret = LibVLC.PlayerIsPlaying (Handle, ex);
129 * Starts playing the selected media.
133 LibVLC.PlayerPlay (Handle, ex);
138 * Pauses the playback.
142 LibVLC.PlayerPause (Handle, ex);
147 * Stops the playback.
151 LibVLC.PlayerStop (Handle, ex);
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
164 * @warning If the identifier is invalid, Xlib might abort the process.
171 return LibVLC.PlayerGetXWindow (Handle);
175 LibVLC.PlayerSetXWindow (Handle, value, ex);
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.
189 public SafeHandle HWND
193 return LibVLC.PlayerGetHWND (Handle);
197 LibVLC.PlayerSetHWND (Handle, value, ex);
203 * Total length in milliseconds of the playback (if known).
209 long ret = LibVLC.PlayerGetLength (Handle, ex);
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.
220 * Changing the Time will also change the Position.
226 long ret = LibVLC.PlayerGetTime (Handle, ex);
232 LibVLC.PlayerSetTime (Handle, value, ex);
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.
243 * Changing the Position will also change the Time.
245 public float Position
249 float ret = LibVLC.PlayerGetPosition (Handle, ex);
255 LibVLC.PlayerSetPosition (Handle, value, ex);
261 * Number of the current chapter (within the current title).
262 * This is mostly used for DVDs and the likes.
268 int ret = LibVLC.PlayerGetChapter (Handle, ex);
274 LibVLC.PlayerSetChapter (Handle, value, ex);
280 * Number of chapters within the current title,
282 public int ChapterCount
286 int ret = LibVLC.PlayerGetChapterCount (Handle, ex);
293 * Gets the number of chapters within a given title.
294 * @param title media title number
297 public int GetChapterCountByTitle (int title)
299 int ret = LibVLC.PlayerGetChapterCountForTitle (Handle, title, ex);
305 * Number of the current title.
312 int ret = LibVLC.PlayerGetTitle (Handle, ex);
318 LibVLC.PlayerSetTitle (Handle, value, ex);
324 * Total number of titles.
327 public int TitleCount
331 int ret = LibVLC.PlayerGetTitleCount (Handle, ex);
338 * Skips to the beginning of the next chapter.
341 public void NextChapter ()
343 LibVLC.PlayerNextChapter (Handle, ex);
348 * Rewinds to the previous chapter.
351 public void PreviousChapter ()
353 LibVLC.PlayerPreviousChapter (Handle, ex);
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.
367 float ret = LibVLC.PlayerGetRate (Handle, ex);
373 LibVLC.PlayerSetRate (Handle, value, ex);
379 * Current state of the player.
385 State ret = LibVLC.PlayerGetState (Handle, ex);
392 * Frame rate in unit/seconds.
394 public float FramePerSeconds
398 float ret = LibVLC.PlayerGetFPS (Handle, ex);
405 * Whether a video track is currently active.
406 * This is false if there is no video track, or if video is discarded.
412 int ret = LibVLC.PlayerHasVout (Handle, ex);
419 * Whether the media supports seeking.
420 * Note that this tells nothing about the seeking precision.
426 int ret = LibVLC.PlayerIsSeekable (Handle, ex);
433 * Whether the media supports pausing.
434 * Live content cannot be paused, unless timeshifting is enabled.
440 int ret = LibVLC.PlayerCanPause (Handle, ex);