Commit 8837d3d6 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Playlist delete support... sorta. LibVLC crashes internally.

parent d95b7e67
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
**********************************************************************/ **********************************************************************/
using System; using System;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace VideoLAN.LibVLC namespace VideoLAN.LibVLC
...@@ -69,8 +70,11 @@ namespace VideoLAN.LibVLC ...@@ -69,8 +70,11 @@ namespace VideoLAN.LibVLC
*/ */
public class Instance : BaseObject<InstanceHandle> public class Instance : BaseObject<InstanceHandle>
{ {
Dictionary<int, PlaylistItem> items;
internal Instance (InstanceHandle self) : base (self) internal Instance (InstanceHandle self) : base (self)
{ {
items = new Dictionary<int, PlaylistItem> ();
} }
public MediaDescriptor CreateDescriptor (string mrl) public MediaDescriptor CreateDescriptor (string mrl)
...@@ -82,7 +86,6 @@ namespace VideoLAN.LibVLC ...@@ -82,7 +86,6 @@ namespace VideoLAN.LibVLC
return new MediaDescriptor (dh); return new MediaDescriptor (dh);
} }
[DllImport ("libvlc-control.dll", EntryPoint="libvlc_playlist_loop")] [DllImport ("libvlc-control.dll", EntryPoint="libvlc_playlist_loop")]
static extern void PlaylistLoop (InstanceHandle self, bool b, static extern void PlaylistLoop (InstanceHandle self, bool b,
NativeException ex); NativeException ex);
...@@ -169,15 +172,19 @@ namespace VideoLAN.LibVLC ...@@ -169,15 +172,19 @@ namespace VideoLAN.LibVLC
{ {
PlaylistClear (self, ex); PlaylistClear (self, ex);
ex.Raise (); ex.Raise ();
foreach (PlaylistItem item in items.Values)
item.Close ();
items.Clear ();
} }
[DllImport ("libvlc-control.dll", [DllImport ("libvlc-control.dll",
EntryPoint="libvlc_playlist_add_extended")] EntryPoint="libvlc_playlist_add_extended")]
static extern void PlaylistAdd (InstanceHandle self, U8String uri, static extern int PlaylistAdd (InstanceHandle self, U8String uri,
U8String name, int optc, U8String name, int optc,
U8String[] optv, NativeException e); U8String[] optv, NativeException e);
/** Appends an item to the playlist with options */ /** Appends an item to the playlist with options */
public void Add (string mrl, string name, string[] opts) public PlaylistItem Add (string mrl, string name, string[] opts)
{ {
U8String umrl = new U8String (mrl); U8String umrl = new U8String (mrl);
U8String uname = new U8String (name); U8String uname = new U8String (name);
...@@ -185,20 +192,65 @@ namespace VideoLAN.LibVLC ...@@ -185,20 +192,65 @@ namespace VideoLAN.LibVLC
for (int i = 0; i < opts.Length; i++) for (int i = 0; i < opts.Length; i++)
optv[i] = new U8String (opts[i]); optv[i] = new U8String (opts[i]);
PlaylistAdd (self, umrl, uname, optv.Length, optv, ex); int id = PlaylistAdd (self, umrl, uname, optv.Length, optv, ex);
ex.Raise (); ex.Raise ();
PlaylistItem item = new PlaylistItem (id);
items.Add (id, item);
return item;
} }
public void Add (string mrl, string[] opts) public PlaylistItem Add (string mrl, string[] opts)
{ {
Add (mrl, null, opts); return Add (mrl, null, opts);
} }
public void Add (string mrl, string name) public PlaylistItem Add (string mrl, string name)
{ {
Add (mrl, name, new string[0]); return Add (mrl, name, new string[0]);
} }
public void Add (string mrl) public PlaylistItem Add (string mrl)
{ {
Add (mrl, null, new string[0]); return Add (mrl, null, new string[0]);
}
[DllImport ("libvlc-control.dll",
EntryPoint="libvlc_playlist_delete_item")]
static extern int PlaylistDelete (InstanceHandle self, int id,
NativeException e);
public void Delete (PlaylistItem item)
{
int id = item.Id;
PlaylistDelete (self, id, ex);
ex.Raise ();
item.Close ();
items.Remove (id);
}
};
public class PlaylistItem
{
int id;
bool deleted;
internal PlaylistItem (int id)
{
this.id = id;
this.deleted = false;
}
internal void Close ()
{
deleted = true;
}
internal int Id
{
get
{
if (deleted)
throw new ObjectDisposedException ("Playlist item deleted");
return id;
}
} }
}; };
......
...@@ -36,12 +36,18 @@ namespace VideoLAN.LibVLC.Test ...@@ -36,12 +36,18 @@ namespace VideoLAN.LibVLC.Test
MediaDescriptor md = vlc.CreateDescriptor (args[0]); MediaDescriptor md = vlc.CreateDescriptor (args[0]);
md.Dispose (); md.Dispose ();
PlaylistItem item = null;
foreach (string s in args) foreach (string s in args)
vlc.Add (s); item = vlc.Add (s);
vlc.Loop = false; vlc.Loop = false;
vlc.TogglePause (); vlc.TogglePause ();
Console.ReadLine (); Console.ReadLine ();
if (item != null)
vlc.Delete (item);
vlc.Clear ();
vlc.Dispose (); vlc.Dispose ();
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment