1 /*****************************************************************************
2 * MediaListPlayerTest.java: VLC Java Bindings
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.internal;
28 import junit.framework.Assert;
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.videolan.jvlc.internal.LibVlc.LibVlcInstance;
34 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaDescriptor;
35 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaInstance;
36 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaList;
37 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaListPlayer;
38 import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t;
41 public class MediaListPlayerTest
44 private LibVlc libvlc = LibVlc.SYNC_INSTANCE;
46 private LibVlcInstance libvlcInstance;
48 private String mrl = this.getClass().getResource("/raffa_voice.ogg").getPath();
51 public void testSetup() throws Exception
53 libvlc_exception_t exception = new libvlc_exception_t();
54 libvlcInstance = libvlc.libvlc_new(0, new String[]{"-I", "dummy", "--aout=dummy", "--vout=dummy" }, exception);
55 // use the following line to use your audio card.
56 // libvlcInstance = libvlc.libvlc_new(0, new String[]{}, exception);
60 public void tearDown()
62 libvlc.libvlc_release(libvlcInstance);
66 public void mediaListPlayerNewTest()
68 libvlc_exception_t exception = new libvlc_exception_t();
69 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
70 Assert.assertNotNull(mediaListPlayer);
71 Assert.assertEquals(0, exception.raised);
72 libvlc.libvlc_media_list_player_release(mediaListPlayer);
76 public void mediaListPlayerSetMediaListTest()
78 libvlc_exception_t exception = new libvlc_exception_t();
79 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
80 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
81 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
82 Assert.assertEquals(0, exception.raised);
83 libvlc.libvlc_media_list_release(mediaList);
84 libvlc.libvlc_media_list_player_release(mediaListPlayer);
88 public void mediaListPlayerSetMediaListTest2()
90 libvlc_exception_t exception = new libvlc_exception_t();
91 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
92 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
93 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
94 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
95 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
96 Assert.assertEquals(0, exception.raised);
97 libvlc.libvlc_media_list_release(mediaList);
98 libvlc.libvlc_media_list_player_release(mediaListPlayer);
102 public void mediaListPlayerIsNotPlayingTest()
104 libvlc_exception_t exception = new libvlc_exception_t();
105 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
106 int result = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
107 Assert.assertEquals(0, result);
108 Assert.assertEquals(0, exception.raised);
109 libvlc.libvlc_media_list_player_release(mediaListPlayer);
113 public void mediaListPlayerPlayNoItemTest()
115 libvlc_exception_t exception = new libvlc_exception_t();
116 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
117 libvlc.libvlc_media_list_player_play(mediaListPlayer, exception);
118 Assert.assertEquals(1, exception.raised);
119 libvlc.libvlc_media_list_player_release(mediaListPlayer);
123 * this fails: see https://trac.videolan.org/vlc/ticket/1527
126 public void mediaListPlayerPlay()
128 libvlc_exception_t exception = new libvlc_exception_t();
129 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
130 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
131 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
132 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
133 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
134 libvlc.libvlc_media_list_player_play(mediaListPlayer, exception);
135 Assert.assertEquals("Exception message: " + exception.message + ".\n", 0, exception.raised);
136 libvlc.libvlc_media_release(mediaDescriptor);
137 libvlc.libvlc_media_list_release(mediaList);
138 libvlc.libvlc_media_list_player_release(mediaListPlayer);
142 public void mediaListPlayerPlayItemAtIndex() throws Exception
144 libvlc_exception_t exception = new libvlc_exception_t();
145 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
146 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
147 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
148 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
149 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
150 libvlc.libvlc_media_list_player_play_item_at_index(mediaListPlayer, 0, exception);
153 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
154 if (exception.raised == 1)
156 throw new RuntimeException("Native exception thrown");
164 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
165 libvlc.libvlc_media_release(mediaDescriptor);
166 libvlc.libvlc_media_list_release(mediaList);
167 libvlc.libvlc_media_list_player_release(mediaListPlayer);
171 public void mediaListPlayerPlayItem() throws Exception
173 libvlc_exception_t exception = new libvlc_exception_t();
174 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
175 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
176 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
177 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
178 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
179 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
180 Assert.assertEquals(0, exception.raised);
183 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
184 if (exception.raised == 1)
186 throw new RuntimeException("Native exception thrown");
194 // FIXME give stats the time to run... there's probably a race condition in misc/stats.c:259 that
196 // Thread.sleep(400);
197 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
198 libvlc.libvlc_media_list_release(mediaList);
199 libvlc.libvlc_media_list_player_release(mediaListPlayer);
203 public void mediaListPlayerGetStateStopped()
205 libvlc_exception_t exception = new libvlc_exception_t();
206 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
207 int state = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
208 Assert.assertEquals(LibVlcState.libvlc_Stopped.ordinal(), state);
209 libvlc.libvlc_media_list_player_release(mediaListPlayer);
213 public void mediaLtistPlayerPause() throws Exception
215 libvlc_exception_t exception = new libvlc_exception_t();
216 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
217 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
218 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
219 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
220 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
221 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
224 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
225 if (exception.raised == 1)
227 throw new RuntimeException("Native exception thrown");
235 libvlc.libvlc_media_list_player_pause(mediaListPlayer, exception);
236 Assert.assertEquals(exception.message, 0, exception.raised);
239 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
240 if (exception.raised == 1)
242 throw new RuntimeException("Native exception thrown");
250 int state = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
251 Assert.assertEquals(exception.message, 0, exception.raised);
253 "Expected state: " + LibVlcState.libvlc_Paused + ".\n",
254 LibVlcState.libvlc_Paused.ordinal(),
256 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
257 libvlc.libvlc_media_list_release(mediaList);
258 libvlc.libvlc_media_list_player_release(mediaListPlayer);
262 public void mediaListPlayerSetMediaInstance()
264 libvlc_exception_t exception = new libvlc_exception_t();
265 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
266 LibVlcMediaDescriptor md = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
267 LibVlcMediaInstance mi = libvlc.libvlc_media_player_new_from_media(md, exception);
268 libvlc.libvlc_media_list_player_set_media_player(mediaListPlayer, mi, exception);
269 Assert.assertEquals(0, exception.raised);
273 public void mediaListPlayerNextNoItems()
275 libvlc_exception_t exception = new libvlc_exception_t();
276 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
277 libvlc.libvlc_media_list_player_next(mediaListPlayer, exception);
278 Assert.assertEquals(1, exception.raised);
282 * fails, see https://trac.videolan.org/vlc/ticket/1535
285 public void mediaListPlayerNext() throws Exception
287 libvlc_exception_t exception = new libvlc_exception_t();
288 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
289 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
290 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
291 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
292 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
293 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
294 libvlc.libvlc_media_list_player_play_item_at_index(mediaListPlayer, 0, exception);
296 libvlc.libvlc_media_list_player_next(mediaListPlayer, exception);
297 Assert.assertEquals(0, exception.raised);
298 libvlc.libvlc_media_list_release(mediaList);
302 public void mediaListPlayerIsPlaying() throws Exception
304 libvlc_exception_t exception = new libvlc_exception_t();
305 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
306 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
307 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
308 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
309 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
310 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
314 int playing = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
315 Assert.assertEquals(0, exception.raised);
316 if (playing == LibVlcState.libvlc_Playing.ordinal())
323 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
326 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
327 Assert.assertEquals(0, exception.raised);
334 Assert.assertEquals(LibVlcState.libvlc_Stopped.ordinal(), libvlc.libvlc_media_list_player_get_state(
337 libvlc.libvlc_media_list_release(mediaList);