1 /*****************************************************************************
2 * MediaList.java: VLC Java Bindings, MediaList
3 *****************************************************************************
4 * Copyright (C) 1998-2008 the VideoLAN team
6 * Authors: Filippo Carone <filippo@carone.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 package org.videolan.jvlc;
28 import java.util.ArrayList;
29 import java.util.LinkedHashSet;
30 import java.util.List;
32 import org.videolan.jvlc.internal.LibVlc.LibVlcEventManager;
33 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaDescriptor;
34 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaList;
35 import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t;
38 public class MediaList
41 private final JVLC jvlc;
43 private final LibVlcMediaList instance;
45 private final LibVlcEventManager eventManager;
47 private List<String> items = new ArrayList<String>();
49 public MediaList(JVLC jvlc)
52 libvlc_exception_t exception = new libvlc_exception_t();
53 instance = jvlc.getLibvlc().libvlc_media_list_new(jvlc.getInstance(), exception);
54 eventManager = jvlc.getLibvlc().libvlc_media_list_event_manager(instance, exception);
57 public void addMedia(String media)
59 MediaDescriptor descriptor = new MediaDescriptor(jvlc, media);
63 public void addMedia(MediaDescriptor descriptor)
65 if (items.contains(descriptor.getMrl()))
69 items.add(descriptor.getMrl());
70 libvlc_exception_t exception = new libvlc_exception_t();
71 jvlc.getLibvlc().libvlc_media_list_add_media_descriptor(instance, descriptor.getInstance(), exception);
74 public int itemsCount()
76 libvlc_exception_t exception = new libvlc_exception_t();
77 return jvlc.getLibvlc().libvlc_media_list_count(instance, exception);
80 public int indexOf(MediaDescriptor descriptor)
82 libvlc_exception_t exception = new libvlc_exception_t();
83 return jvlc.getLibvlc().libvlc_media_list_index_of_item(instance, descriptor.getInstance(), exception);
86 public MediaDescriptor getMediaDescriptorAtIndex(int index)
88 libvlc_exception_t exception = new libvlc_exception_t();
89 LibVlcMediaDescriptor descriptor = jvlc.getLibvlc().libvlc_media_list_item_at_index(instance, index, exception);
90 return new MediaDescriptor(jvlc, descriptor);
94 * @param index The index of the media to remove
95 * @return True if the media was successfully removed, false otherwise.
97 public boolean removeMedia(int index)
99 libvlc_exception_t exception = new libvlc_exception_t();
100 jvlc.getLibvlc().libvlc_media_list_remove_index(instance, index, exception);
101 if (exception.raised == 0)
110 * @param media The media descriptor mrl
112 public boolean removeMedia(String mrl)
114 int index = items.indexOf(mrl);
119 return removeMedia(index);
122 public void insertMediaDescriptor(MediaDescriptor descriptor, int index)
124 libvlc_exception_t exception = new libvlc_exception_t();
127 .libvlc_media_list_insert_media_descriptor(instance, descriptor.getInstance(), index, exception);
134 protected void finalize() throws Throwable
136 jvlc.getLibvlc().libvlc_media_list_release(instance);
141 * Returns the instance.
142 * @return the instance
144 LibVlcMediaList getInstance()
150 * @param mediaDescriptor
152 public boolean removeMedia(MediaDescriptor mediaDescriptor)
154 String mrl = mediaDescriptor.getMrl();
155 int index = items.indexOf(mrl);
160 return removeMedia(index);