3 * @brief libvlc-control CIL bindings
8 /**********************************************************************
9 * Copyright (C) 2007 RĂ©mi Denis-Courmont. *
10 * This program is free software; you can redistribute and/or modify *
11 * it under the terms of the GNU General Public License as published *
12 * by the Free Software Foundation; version 2 of the license, or (at *
13 * your option) any later version. *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
18 * See the GNU General Public License for more details. *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, you can get it from: *
22 * http://www.gnu.org/copyleft/gpl.html *
23 **********************************************************************/
26 using System.Collections.Generic;
27 using System.Runtime.InteropServices;
29 namespace VideoLAN.LibVLC
32 * The VLC class is used to create LibVLC Instance objects.
33 * The VLC class has only one static method and cannot be instanciated.
36 * string[] argv = new string[]{ "-vvv", "-I", "dummy" };
38 * Instance vlc = VLC.CreateInstance (argv);
41 public sealed class VLC
44 * Loads native LibVLC and creates a LibVLC instance.
46 * @param args VLC command line parameters for the LibVLC Instance.
48 * @return a new LibVLC Instance
50 public static Instance CreateInstance (string[] args)
52 U8String[] argv = new U8String[args.Length];
53 for (int i = 0; i < args.Length; i++)
54 argv[i] = new U8String (args[i]);
56 NativeException ex = new NativeException ();
58 InstanceHandle h = InstanceHandle.Create (argv.Length, argv, ex);
61 return new Instance (h);
66 * Safe handle for unmanaged LibVLC instance pointer.
68 public sealed class InstanceHandle : NonNullHandle
70 private InstanceHandle ()
74 [DllImport ("libvlc-control.dll", EntryPoint="libvlc_new")]
75 internal static extern
76 InstanceHandle Create (int argc, U8String[] argv, NativeException ex);
78 [DllImport ("libvlc-control.dll", EntryPoint="libvlc_release")]
79 static extern void Destroy (IntPtr ptr, NativeException ex);
82 * System.Runtime.InteropServices.SafeHandle::ReleaseHandle.
84 protected override bool ReleaseHandle ()
86 Destroy (handle, null);
92 * LibVLC Instance provides basic media player features from VLC,
93 * such as play/pause/stop and flat playlist management.
95 public class Instance : BaseObject<InstanceHandle>
97 Dictionary<int, PlaylistItem> items;
99 internal Instance (InstanceHandle self) : base (self)
101 items = new Dictionary<int, PlaylistItem> ();
105 * Creates a MediaDescriptor.
106 * @param mrl Media Resource Locator (file path or URL)
107 * @return create MediaDescriptor object.
109 public MediaDescriptor CreateDescriptor (string mrl)
111 U8String umrl = new U8String (mrl);
112 DescriptorHandle dh = DescriptorHandle.Create (self, umrl, ex);
115 return new MediaDescriptor (dh);
118 [DllImport ("libvlc-control.dll", EntryPoint="libvlc_playlist_loop")]
119 static extern void PlaylistLoop (InstanceHandle self, bool b,
121 /** Sets the playlist loop flag. */
126 PlaylistLoop (self, value, ex);
131 [DllImport ("libvlc-control.dll", EntryPoint="libvlc_playlist_play")]
132 static extern void PlaylistPlay (InstanceHandle self, int id, int optc,
133 U8String[] optv, NativeException ex);
134 /** Plays the next playlist item (if not already playing). */
137 PlaylistPlay (self, -1, 0, new U8String[0], ex);
141 [DllImport ("libvlc-control.dll", EntryPoint="libvlc_playlist_pause")]
142 static extern void PlaylistPause (InstanceHandle self,
144 /** Toggles pause (starts playing if stopped, pauses if playing). */
145 public void TogglePause ()
147 PlaylistPause (self, ex);
151 [DllImport ("libvlc-control.dll",
152 EntryPoint="libvlc_playlist_isplaying")]
153 static extern int PlaylistIsPlaying (InstanceHandle self,
155 /** Whether the playlist is running, or paused/stopped. */
156 public bool IsPlaying
160 int ret = PlaylistIsPlaying (self, ex);
166 [DllImport ("libvlc-control.dll", EntryPoint="libvlc_playlist_stop")]
167 static extern void PlaylistStop (InstanceHandle self,
169 /** Stops playing. */
172 PlaylistStop (self, ex);
176 [DllImport ("libvlc-control.dll", EntryPoint="libvlc_playlist_next")]
177 static extern void PlaylistNext (InstanceHandle self,
179 /** Switches to next playlist item, and starts playing it. */
182 PlaylistNext (self, ex);
186 [DllImport ("libvlc-control.dll", EntryPoint="libvlc_playlist_prev")]
187 static extern void PlaylistPrev (InstanceHandle self,
189 /** Switches to previous playlist item, and starts playing it. */
192 PlaylistPrev (self, ex);
196 [DllImport ("libvlc-control.dll", EntryPoint="libvlc_playlist_clear")]
197 static extern void PlaylistClear (InstanceHandle self,
199 /** Clears the whole playlist. */
202 PlaylistClear (self, ex);
205 foreach (PlaylistItem item in items.Values)
210 [DllImport ("libvlc-control.dll",
211 EntryPoint="libvlc_playlist_add_extended")]
212 static extern int PlaylistAdd (InstanceHandle self, U8String uri,
213 U8String name, int optc,
214 U8String[] optv, NativeException e);
216 * Appends an item to the playlist, with options.
217 * @param mrl Media Resource Locator (file name or URL)
218 * @param name playlist item user-visible name
219 * @param opts item options (see LibVLC documentation for details)
220 * @return created playlist item.
222 public PlaylistItem Add (string mrl, string name, string[] opts)
224 U8String umrl = new U8String (mrl);
225 U8String uname = new U8String (name);
226 U8String[] optv = new U8String[opts.Length];
227 for (int i = 0; i < opts.Length; i++)
228 optv[i] = new U8String (opts[i]);
230 int id = PlaylistAdd (self, umrl, uname, optv.Length, optv, ex);
233 PlaylistItem item = new PlaylistItem (id);
234 items.Add (id, item);
238 * Appends an item with options.
239 * @param mrl Media Resource Locator (file name or URL)
240 * @param opts item options (see LibVLC documentation for details)
241 * @return created playlist item.
243 public PlaylistItem Add (string mrl, string[] opts)
245 return Add (mrl, null, opts);
248 * Appends an item to the playlist.
249 * @param mrl Media Resource Locator (file name or URL)
250 * @param name playlist item user-visible name
251 * @return created playlist item.
253 public PlaylistItem Add (string mrl, string name)
255 return Add (mrl, name, new string[0]);
258 * Appends an item to the playlist.
259 * @param mrl Media Resource Locator (file name or URL)
260 * @return created playlist item.
262 public PlaylistItem Add (string mrl)
264 return Add (mrl, null, new string[0]);
267 [DllImport ("libvlc-control.dll",
268 EntryPoint="libvlc_playlist_delete_item")]
269 static extern int PlaylistDelete (InstanceHandle self, int id,
272 * Removes an item from the playlist.
273 * @param item playlist item (as obtained from Add())
275 public void Delete (PlaylistItem item)
278 PlaylistDelete (self, id, ex);
289 public class PlaylistItem
294 internal PlaylistItem (int id)
297 this.deleted = false;
300 internal void Close ()
310 throw new ObjectDisposedException ("Playlist item deleted");
316 /** Safe handle for unmanaged LibVLC media descriptor */
317 public sealed class DescriptorHandle : NonNullHandle
319 private DescriptorHandle ()
323 [DllImport ("libvlc-control.dll",
324 EntryPoint="libvlc_media_descriptor_new")]
326 DescriptorHandle Create (InstanceHandle inst, U8String mrl,
329 [DllImport ("libvlc-control.dll",
330 EntryPoint="libvlc_media_descriptor_release")]
331 public static extern void Release (IntPtr ptr);
333 protected override bool ReleaseHandle ()
341 * Media descriptor. Not implemented yet.
343 public class MediaDescriptor : BaseObject<DescriptorHandle>
345 internal MediaDescriptor (DescriptorHandle self) : base (self)