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.Test;
32 import org.videolan.jvlc.internal.LibVlc.LibVlcMedia;
33 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaInstance;
34 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaList;
35 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaListPlayer;
36 import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t;
39 public class MediaListPlayerTest extends AbstractVLCInternalTest
42 private LibVlcMediaListPlayer current;
45 public void mediaListPlayerNewTest()
47 libvlc_exception_t exception = new libvlc_exception_t();
48 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
49 Assert.assertNotNull(mediaListPlayer);
50 Assert.assertEquals(0, exception.raised);
51 libvlc.libvlc_media_list_player_release(mediaListPlayer);
55 public void mediaListPlayerSetMediaListTest()
57 libvlc_exception_t exception = new libvlc_exception_t();
58 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
59 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
60 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
61 Assert.assertEquals(0, exception.raised);
62 libvlc.libvlc_media_list_release(mediaList);
63 libvlc.libvlc_media_list_player_release(mediaListPlayer);
67 public void mediaListPlayerSetMediaListTest2()
69 libvlc_exception_t exception = new libvlc_exception_t();
70 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
71 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
72 LibVlcMedia mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
73 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
74 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
75 Assert.assertEquals(0, exception.raised);
76 libvlc.libvlc_media_list_release(mediaList);
77 libvlc.libvlc_media_list_player_release(mediaListPlayer);
81 public void mediaListPlayerIsNotPlayingTest()
83 libvlc_exception_t exception = new libvlc_exception_t();
84 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
85 int result = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
86 Assert.assertEquals(0, result);
87 Assert.assertEquals(0, exception.raised);
88 libvlc.libvlc_media_list_player_release(mediaListPlayer);
92 public void mediaListPlayerPlayNoItemTest()
94 libvlc_exception_t exception = new libvlc_exception_t();
95 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
96 libvlc.libvlc_media_list_player_play(mediaListPlayer, exception);
97 Assert.assertEquals(1, exception.raised);
98 libvlc.libvlc_media_list_player_release(mediaListPlayer);
102 public void mediaListPlayerPlay()
104 libvlc_exception_t exception = new libvlc_exception_t();
105 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
106 current = mediaListPlayer;
107 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
108 LibVlcMedia mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
109 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
110 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
111 libvlc.libvlc_media_list_player_play(mediaListPlayer, exception);
112 Assert.assertEquals("Exception message: " + exception.message + ".\n", 0, exception.raised);
113 libvlc.libvlc_media_release(mediaDescriptor);
114 libvlc.libvlc_media_list_release(mediaList);
118 public void mediaListPlayerPlayItemAtIndex() throws Exception
120 libvlc_exception_t exception = new libvlc_exception_t();
121 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
122 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
123 LibVlcMedia mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
124 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
125 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
126 libvlc.libvlc_media_list_player_play_item_at_index(mediaListPlayer, 0, exception);
129 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
130 if (exception.raised == 1)
132 throw new RuntimeException("Native exception thrown");
140 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
141 while (libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception) != LibVlcState.libvlc_Ended
146 libvlc.libvlc_media_release(mediaDescriptor);
147 libvlc.libvlc_media_list_release(mediaList);
148 libvlc.libvlc_media_list_player_release(mediaListPlayer);
152 public void mediaListPlayerPlayItem() throws Exception
154 libvlc_exception_t exception = new libvlc_exception_t();
155 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
156 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
157 LibVlcMedia mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
158 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
159 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
160 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
161 Assert.assertEquals(0, exception.raised);
164 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
165 if (exception.raised == 1)
167 throw new RuntimeException("Native exception thrown");
176 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
177 libvlc.libvlc_media_list_release(mediaList);
178 libvlc.libvlc_media_list_player_release(mediaListPlayer);
182 public void mediaListPlayerGetStateEnded()
184 libvlc_exception_t exception = new libvlc_exception_t();
185 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
186 int state = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
187 Assert.assertEquals(LibVlcState.libvlc_Ended.ordinal(), state);
188 libvlc.libvlc_media_list_player_release(mediaListPlayer);
192 public void mediaLtistPlayerPause() throws Exception
194 libvlc_exception_t exception = new libvlc_exception_t();
195 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
196 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
197 LibVlcMedia mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
198 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
199 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
200 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
203 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
204 if (exception.raised == 1)
206 throw new RuntimeException("Native exception thrown");
214 libvlc.libvlc_media_list_player_pause(mediaListPlayer, exception);
216 int state = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
217 Assert.assertEquals(exception.message, 0, exception.raised);
219 "Expected state: " + LibVlcState.libvlc_Paused + ".\n",
220 LibVlcState.libvlc_Paused.ordinal(),
222 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
223 libvlc.libvlc_media_list_release(mediaList);
224 libvlc.libvlc_media_list_player_release(mediaListPlayer);
228 public void mediaListPlayerSetMediaInstance()
230 libvlc_exception_t exception = new libvlc_exception_t();
231 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
232 LibVlcMedia md = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
233 LibVlcMediaInstance mi = libvlc.libvlc_media_player_new_from_media(md, exception);
234 libvlc.libvlc_media_list_player_set_media_player(mediaListPlayer, mi, exception);
235 Assert.assertEquals(0, exception.raised);
239 public void mediaListPlayerNextNoItems()
241 libvlc_exception_t exception = new libvlc_exception_t();
242 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
243 libvlc.libvlc_media_list_player_next(mediaListPlayer, exception);
244 Assert.assertEquals(1, exception.raised);
248 * fails, see https://trac.videolan.org/vlc/ticket/1535
251 public void mediaListPlayerNext() throws Exception
253 libvlc_exception_t exception = new libvlc_exception_t();
254 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
255 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
256 LibVlcMedia mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
257 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
258 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
259 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
260 libvlc.libvlc_media_list_player_play_item_at_index(mediaListPlayer, 0, exception);
262 libvlc.libvlc_media_list_player_next(mediaListPlayer, exception);
263 Assert.assertEquals(0, exception.raised);
264 libvlc.libvlc_media_list_release(mediaList);
268 public void mediaListPlayerIsPlaying() throws Exception
270 libvlc_exception_t exception = new libvlc_exception_t();
271 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
272 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
273 LibVlcMedia mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
274 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
275 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
276 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
280 int playing = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
281 Assert.assertEquals(0, exception.raised);
282 if (playing == LibVlcState.libvlc_Playing.ordinal())
289 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
292 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
293 Assert.assertEquals(0, exception.raised);
300 Assert.assertEquals(LibVlcState.libvlc_Ended.ordinal(), libvlc.libvlc_media_list_player_get_state(
303 libvlc.libvlc_media_list_release(mediaList);
308 public void tearDown()
312 libvlc.libvlc_media_list_player_stop(current, exception);
313 while (libvlc.libvlc_media_list_player_get_state(current, exception) != LibVlcState.libvlc_Ended.ordinal())
319 catch (InterruptedException e)