}
+
/**
* Returns the instance.
* @return the instance
package org.videolan.jvlc;
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.List;
+
import org.videolan.jvlc.internal.LibVlc.LibVlcEventManager;
import org.videolan.jvlc.internal.LibVlc.LibVlcMediaDescriptor;
import org.videolan.jvlc.internal.LibVlc.LibVlcMediaList;
private final LibVlcEventManager eventManager;
+ private List<String> items = new ArrayList<String>();
+
public MediaList(JVLC jvlc)
{
this.jvlc = jvlc;
public void addMediaDescriptor(MediaDescriptor descriptor)
{
+ if (items.contains(descriptor.getMrl()))
+ {
+ return;
+ }
+ items.add(descriptor.getMrl());
libvlc_exception_t exception = new libvlc_exception_t();
jvlc.getLibvlc().libvlc_media_list_add_media_descriptor(instance, descriptor.getInstance(), exception);
}
return new MediaDescriptor(jvlc, descriptor);
}
- public void remove(int index)
+ /**
+ * @param index The index of the media to remove
+ * @return True if the media was successfully removed, false otherwise.
+ */
+ public boolean removeMedia(int index)
{
libvlc_exception_t exception = new libvlc_exception_t();
jvlc.getLibvlc().libvlc_media_list_remove_index(instance, index, exception);
+ if (exception.raised == 0)
+ {
+ items.remove(index);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * @param media The media descriptor mrl
+ */
+ public boolean removeMedia(String mrl)
+ {
+ int index = items.indexOf(mrl);
+ if (index == -1)
+ {
+ return false;
+ }
+ return removeMedia(index);
}
public void insertMediaDescriptor(MediaDescriptor descriptor, int index)
return instance;
}
+ /**
+ * @param mediaDescriptor
+ */
+ public boolean removeMedia(MediaDescriptor mediaDescriptor)
+ {
+ String mrl = mediaDescriptor.getMrl();
+ int index = items.indexOf(mrl);
+ if (index == -1)
+ {
+ return false;
+ }
+ return removeMedia(index);
+ }
+
}
--- /dev/null
+/*****************************************************************************
+ * JVLCTest.java: VLC Java Bindings
+ *****************************************************************************
+ * Copyright (C) 1998-2008 the VideoLAN team
+ *
+ * Authors: Filippo Carone <filippo@carone.org>
+ *
+ *
+ * $Id $
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ *****************************************************************************/
+
+package org.videolan.jvlc;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+
+public class JVLCTest
+{
+
+ String mrl = getClass().getResource("/raffa_voice.ogg").getFile();
+
+ @Test
+ public void jvlcNew()
+ {
+ JVLC jvlc = new JVLC();
+ Assert.assertNotNull(jvlc.getMediaList());
+ }
+
+ @Test
+ public void jvlcPlay()
+ {
+ JVLC jvlc = new JVLC();
+ MediaInstance instance = jvlc.play(mrl);
+ Assert.assertNotNull(instance);
+ }
+
+
+
+}
--- /dev/null
+/*****************************************************************************
+ * MediaListTest.java: VLC Java Bindings
+ *****************************************************************************
+ * Copyright (C) 1998-2008 the VideoLAN team
+ *
+ * Authors: Filippo Carone <filippo@carone.org>
+ *
+ *
+ * $Id $
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ *****************************************************************************/
+
+package org.videolan.jvlc;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class MediaListTest
+{
+
+ private JVLC jvlc;
+
+ private String mrl = getClass().getResource("/raffa_voice.ogg").getFile();
+
+ @Before
+ public void setup()
+ {
+ jvlc = new JVLC();
+ }
+
+ @Test
+ public void mediaListAddMedia()
+ {
+ MediaList mlist = new MediaList(jvlc);
+ mlist.addMedia(mrl);
+ Assert.assertEquals(1, mlist.itemsCount());
+ }
+
+ @Test
+ public void mediaListAddMedia2()
+ {
+ MediaList mlist = new MediaList(jvlc);
+ mlist.addMedia(mrl);
+ Assert.assertEquals(1, mlist.itemsCount());
+ mlist.addMedia(mrl);
+ Assert.assertEquals(1, mlist.itemsCount());
+ mlist.addMediaDescriptor(new MediaDescriptor(jvlc, mrl));
+ Assert.assertEquals(1, mlist.itemsCount());
+ mlist.addMedia("non-existing");
+ Assert.assertEquals(2, mlist.itemsCount());
+ }
+
+ @Test
+ public void mediaListRemoveMedia()
+ {
+ MediaList mlist = new MediaList(jvlc);
+ mlist.addMedia(mrl);
+ Assert.assertEquals(1, mlist.itemsCount());
+ mlist.removeMedia(0);
+ Assert.assertEquals(0, mlist.itemsCount());
+ }
+
+ @Test
+ public void mediaListRemoveMedia2()
+ {
+ MediaList mlist = new MediaList(jvlc);
+ mlist.addMedia(mrl);
+ Assert.assertEquals(1, mlist.itemsCount());
+ mlist.removeMedia(0);
+ Assert.assertEquals(0, mlist.itemsCount());
+
+ mlist.addMedia(mrl);
+ mlist.removeMedia(0);
+ Assert.assertEquals(0, mlist.itemsCount());
+
+ mlist.addMediaDescriptor(new MediaDescriptor(jvlc, mrl));
+ mlist.removeMedia(0);
+ Assert.assertEquals(0, mlist.itemsCount());
+
+ mlist.addMediaDescriptor(new MediaDescriptor(jvlc, mrl));
+ mlist.removeMedia(mrl);
+ Assert.assertEquals(0, mlist.itemsCount());
+
+ mlist.addMediaDescriptor(new MediaDescriptor(jvlc, mrl));
+ mlist.removeMedia(new MediaDescriptor(jvlc, mrl));
+ Assert.assertEquals(0, mlist.itemsCount());
+
+ }
+
+
+}
Assert.assertEquals(0, exception.raised);
}
+ @Test
+ public void mediaListRemoveIndexTest()
+ {
+ libvlc_exception_t exception = new libvlc_exception_t();
+ LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
+ String mrl = this.getClass().getResource("/raffa_voice.ogg").getPath();
+ LibVlcMediaDescriptor libvlc_media_descriptor = libvlc.libvlc_media_descriptor_new(
+ libvlcInstance,
+ mrl,
+ exception);
+ libvlc.libvlc_media_list_add_media_descriptor(mediaList, libvlc_media_descriptor, exception);
+ libvlc.libvlc_media_list_remove_index(mediaList, 0, exception);
+ Assert.assertEquals(0, exception.raised);
+ }
+
+ @Test
+ public void mediaListRemoveIndexTest2()
+ {
+ libvlc_exception_t exception = new libvlc_exception_t();
+ LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
+ String mrl = this.getClass().getResource("/raffa_voice.ogg").getPath();
+ LibVlcMediaDescriptor libvlc_media_descriptor = libvlc.libvlc_media_descriptor_new(
+ libvlcInstance,
+ mrl,
+ exception);
+ libvlc.libvlc_media_list_add_media_descriptor(mediaList, libvlc_media_descriptor, exception);
+ libvlc.libvlc_media_list_remove_index(mediaList, 0, exception);
+ Assert.assertEquals(0, exception.raised);
+
+ libvlc_media_descriptor = libvlc.libvlc_media_descriptor_new(
+ libvlcInstance,
+ mrl,
+ exception);
+ libvlc.libvlc_media_list_add_media_descriptor(mediaList, libvlc_media_descriptor, exception);
+ libvlc.libvlc_media_list_remove_index(mediaList, 0, exception);
+ }
+
}