2 * libvlc.cs - libvlc-control CIL bindings
7 /**********************************************************************
8 * Copyright (C) 2007 RĂ©mi Denis-Courmont. *
9 * This program is free software; you can redistribute and/or modify *
10 * it under the terms of the GNU General Public License as published *
11 * by the Free Software Foundation; version 2 of the license, or (at *
12 * your option) any later version. *
14 * This program is distributed in the hope that it will be useful, *
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
17 * See the GNU General Public License for more details. *
19 * You should have received a copy of the GNU General Public License *
20 * along with this program; if not, you can get it from: *
21 * http://www.gnu.org/copyleft/gpl.html *
22 **********************************************************************/
25 using System.Collections.Generic;
26 using System.Runtime.InteropServices;
28 namespace VideoLAN.LibVLC
30 public sealed class VLC
32 public static Instance CreateInstance (string[] args)
34 U8String[] argv = new U8String[args.Length];
35 for (int i = 0; i < args.Length; i++)
36 argv[i] = new U8String (args[i]);
38 NativeException ex = new NativeException ();
40 InstanceHandle h = InstanceHandle.Create (argv.Length, argv, ex);
43 return new Instance (h);
47 /** Safe handle for unmanaged LibVLC instance pointer */
48 public sealed class InstanceHandle : NonNullHandle
50 private InstanceHandle ()
54 [DllImport ("libvlc-control.dll", EntryPoint="libvlc_new")]
56 InstanceHandle Create (int argc, U8String[] argv, NativeException ex);
58 [DllImport ("libvlc-control.dll", EntryPoint="libvlc_release")]
59 static extern void Destroy (IntPtr ptr, NativeException ex);
61 protected override bool ReleaseHandle ()
63 Destroy (handle, null);
69 * Managed class for LibVLC instance (including playlist)
71 public class Instance : BaseObject<InstanceHandle>
73 Dictionary<int, PlaylistItem> items;
75 internal Instance (InstanceHandle self) : base (self)
77 items = new Dictionary<int, PlaylistItem> ();
80 public MediaDescriptor CreateDescriptor (string mrl)
82 U8String umrl = new U8String (mrl);
83 DescriptorHandle dh = DescriptorHandle.Create (self, umrl, ex);
86 return new MediaDescriptor (dh);
89 [DllImport ("libvlc-control.dll", EntryPoint="libvlc_playlist_loop")]
90 static extern void PlaylistLoop (InstanceHandle self, bool b,
92 /** Sets the playlist loop flag */
97 PlaylistLoop (self, value, ex);
102 [DllImport ("libvlc-control.dll", EntryPoint="libvlc_playlist_play")]
103 static extern void PlaylistPlay (InstanceHandle self, int id, int optc,
104 U8String[] optv, NativeException ex);
105 /** Plays the next playlist item */
108 PlaylistPlay (self, -1, 0, new U8String[0], ex);
112 [DllImport ("libvlc-control.dll", EntryPoint="libvlc_playlist_pause")]
113 static extern void PlaylistPause (InstanceHandle self,
116 public void TogglePause ()
118 PlaylistPause (self, ex);
122 [DllImport ("libvlc-control.dll",
123 EntryPoint="libvlc_playlist_isplaying")]
124 static extern int PlaylistIsPlaying (InstanceHandle self,
126 /** Whether the playlist is running, or in pause/stop */
127 public bool IsPlaying
131 int ret = PlaylistIsPlaying (self, ex);
137 [DllImport ("libvlc-control.dll", EntryPoint="libvlc_playlist_stop")]
138 static extern void PlaylistStop (InstanceHandle self,
143 PlaylistStop (self, ex);
147 [DllImport ("libvlc-control.dll", EntryPoint="libvlc_playlist_next")]
148 static extern void PlaylistNext (InstanceHandle self,
150 /** Goes to next playlist item (and start playing it) */
153 PlaylistNext (self, ex);
157 [DllImport ("libvlc-control.dll", EntryPoint="libvlc_playlist_prev")]
158 static extern void PlaylistPrev (InstanceHandle self,
160 /** Goes to previous playlist item (and start playing it) */
163 PlaylistPrev (self, ex);
167 [DllImport ("libvlc-control.dll", EntryPoint="libvlc_playlist_clear")]
168 static extern void PlaylistClear (InstanceHandle self,
170 /** Clears the whole playlist */
173 PlaylistClear (self, ex);
176 foreach (PlaylistItem item in items.Values)
181 [DllImport ("libvlc-control.dll",
182 EntryPoint="libvlc_playlist_add_extended")]
183 static extern int PlaylistAdd (InstanceHandle self, U8String uri,
184 U8String name, int optc,
185 U8String[] optv, NativeException e);
186 /** Appends an item to the playlist with options */
187 public PlaylistItem Add (string mrl, string name, string[] opts)
189 U8String umrl = new U8String (mrl);
190 U8String uname = new U8String (name);
191 U8String[] optv = new U8String[opts.Length];
192 for (int i = 0; i < opts.Length; i++)
193 optv[i] = new U8String (opts[i]);
195 int id = PlaylistAdd (self, umrl, uname, optv.Length, optv, ex);
198 PlaylistItem item = new PlaylistItem (id);
199 items.Add (id, item);
202 public PlaylistItem Add (string mrl, string[] opts)
204 return Add (mrl, null, opts);
206 public PlaylistItem Add (string mrl, string name)
208 return Add (mrl, name, new string[0]);
210 public PlaylistItem Add (string mrl)
212 return Add (mrl, null, new string[0]);
215 [DllImport ("libvlc-control.dll",
216 EntryPoint="libvlc_playlist_delete_item")]
217 static extern int PlaylistDelete (InstanceHandle self, int id,
219 public void Delete (PlaylistItem item)
222 PlaylistDelete (self, id, ex);
230 public class PlaylistItem
235 internal PlaylistItem (int id)
238 this.deleted = false;
241 internal void Close ()
251 throw new ObjectDisposedException ("Playlist item deleted");
257 /** Safe handle for unmanaged LibVLC media descriptor */
258 public sealed class DescriptorHandle : NonNullHandle
260 private DescriptorHandle ()
264 [DllImport ("libvlc-control.dll",
265 EntryPoint="libvlc_media_descriptor_new")]
267 DescriptorHandle Create (InstanceHandle inst, U8String mrl,
270 [DllImport ("libvlc-control.dll",
271 EntryPoint="libvlc_media_descriptor_release")]
272 public static extern void Release (IntPtr ptr);
274 protected override bool ReleaseHandle ()
281 public class MediaDescriptor : BaseObject<DescriptorHandle>
283 internal MediaDescriptor (DescriptorHandle self) : base (self)