]> git.sesse.net Git - vlc/blob - bindings/java/org/videolan/jvlc/Playlist.java
820e50da6948aea1348f677e7069a39bb7e62013
[vlc] / bindings / java / org / videolan / jvlc / Playlist.java
1  /*****************************************************************************
2  * Playlist.java: PlaylistIntf implementation class
3  *****************************************************************************
4  *
5  * Copyright (C) 1998-2008 the VideoLAN team
6  * 
7  * Author: Filippo Carone <filippo@carone.org>
8  *
9  * Created on 28-feb-2006
10  *
11  * $Id: Playlist.java 17089 2006-10-15 10:54:15Z littlejohn $
12  *
13  * This program is free software; you can redistribute it
14  * and/or modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2 of the
16  * License, or (at your option) any later version.
17  * 
18  * This program is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21  * General Public License for more details.
22  * 
23  * You should have received a copy of the GNU General Public
24  * License along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26  * 
27  */
28
29
30 package org.videolan.jvlc;
31
32 import org.videolan.jvlc.internal.LibVlc;
33 import org.videolan.jvlc.internal.LibVlc.LibVlcInstance;
34 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaInstance;
35 import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t;
36
37 public class Playlist {
38     
39     
40     private final LibVlcInstance libvlcInstance;
41     private final LibVlc libvlc;
42     private final JVLC jvlc;
43
44     public Playlist(JVLC jvlc) {
45         this.jvlc = jvlc;
46         this.libvlcInstance = jvlc.getInstance();
47         this.libvlc = jvlc.getLibvlc();
48     }
49     
50     public synchronized void play(int id, String[] options) throws VLCException {
51         libvlc_exception_t exception = new libvlc_exception_t();
52         libvlc.libvlc_playlist_play(libvlcInstance, id, options.length, options, exception);
53     }
54
55     public synchronized void play() throws VLCException {
56         libvlc_exception_t exception = new libvlc_exception_t();
57         libvlc.libvlc_playlist_play(libvlcInstance, -1, 0, new String[] {}, exception);
58     }
59
60     public synchronized void togglePause() throws VLCException {
61         libvlc_exception_t exception = new libvlc_exception_t();
62         libvlc.libvlc_playlist_pause(libvlcInstance, exception);
63     }
64
65     public synchronized void stop() throws VLCException {
66         libvlc_exception_t exception = new libvlc_exception_t();
67         libvlc.libvlc_playlist_stop(libvlcInstance, exception);
68     }
69
70     public boolean isRunning() throws VLCException {
71         libvlc_exception_t exception = new libvlc_exception_t();
72         return libvlc.libvlc_playlist_isplaying(libvlcInstance, exception) == 0? false : true;
73     }
74
75     public synchronized int itemsCount() throws VLCException {
76         libvlc_exception_t exception = new libvlc_exception_t();
77         return libvlc.libvlc_playlist_items_count(libvlcInstance, exception);
78     }
79
80     public synchronized void next() throws VLCException {
81         libvlc_exception_t exception = new libvlc_exception_t();
82         if (! isRunning())
83             play();
84         libvlc.libvlc_playlist_next(libvlcInstance, exception);
85     }
86
87     public synchronized void prev() throws VLCException {
88         libvlc_exception_t exception = new libvlc_exception_t();
89         if (! isRunning())
90             play();
91         libvlc.libvlc_playlist_prev(libvlcInstance, exception);
92     }
93
94     public synchronized void clear() throws VLCException {
95         libvlc_exception_t exception = new libvlc_exception_t();
96         libvlc.libvlc_playlist_clear(libvlcInstance, exception);
97     }
98     
99     public synchronized int add(String uri, String name) throws VLCException {
100         libvlc_exception_t exception = new libvlc_exception_t();
101         return libvlc.libvlc_playlist_add(libvlcInstance, uri, name, exception);
102     }
103
104
105     public synchronized void deleteItem(int itemID) throws VLCException {
106         libvlc_exception_t exception = new libvlc_exception_t();
107         libvlc.libvlc_playlist_delete_item(libvlcInstance, itemID, exception);
108     }
109     
110     public synchronized void setLoop(boolean loop) {
111         libvlc_exception_t exception = new libvlc_exception_t();
112         libvlc.libvlc_playlist_loop(libvlcInstance, loop? 1 : 0, exception);
113     }
114     
115     public MediaInstance getMediaInstance()
116     {
117         libvlc_exception_t exception = new libvlc_exception_t();
118         LibVlcMediaInstance mi = libvlc.libvlc_playlist_get_media_instance(libvlcInstance, exception);
119         return new MediaInstance(jvlc, mi);
120         
121     }
122 }