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.Test;
31 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaDescriptor;
32 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaInstance;
33 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaList;
34 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaListPlayer;
35 import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t;
38 public class MediaListPlayerTest extends AbstractVLCInternalTest
41 public void mediaListPlayerNewTest()
43 libvlc_exception_t exception = new libvlc_exception_t();
44 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
45 Assert.assertNotNull(mediaListPlayer);
46 Assert.assertEquals(0, exception.raised);
47 libvlc.libvlc_media_list_player_release(mediaListPlayer);
51 public void mediaListPlayerSetMediaListTest()
53 libvlc_exception_t exception = new libvlc_exception_t();
54 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
55 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
56 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
57 Assert.assertEquals(0, exception.raised);
58 libvlc.libvlc_media_list_release(mediaList);
59 libvlc.libvlc_media_list_player_release(mediaListPlayer);
63 public void mediaListPlayerSetMediaListTest2()
65 libvlc_exception_t exception = new libvlc_exception_t();
66 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
67 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
68 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
69 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
70 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
71 Assert.assertEquals(0, exception.raised);
72 libvlc.libvlc_media_list_release(mediaList);
73 libvlc.libvlc_media_list_player_release(mediaListPlayer);
77 public void mediaListPlayerIsNotPlayingTest()
79 libvlc_exception_t exception = new libvlc_exception_t();
80 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
81 int result = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
82 Assert.assertEquals(0, result);
83 Assert.assertEquals(0, exception.raised);
84 libvlc.libvlc_media_list_player_release(mediaListPlayer);
88 public void mediaListPlayerPlayNoItemTest()
90 libvlc_exception_t exception = new libvlc_exception_t();
91 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
92 libvlc.libvlc_media_list_player_play(mediaListPlayer, exception);
93 Assert.assertEquals(1, exception.raised);
94 libvlc.libvlc_media_list_player_release(mediaListPlayer);
98 * this fails: see https://trac.videolan.org/vlc/ticket/1527
101 public void mediaListPlayerPlay()
103 libvlc_exception_t exception = new libvlc_exception_t();
104 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
105 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
106 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
107 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
108 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
109 libvlc.libvlc_media_list_player_play(mediaListPlayer, exception);
110 Assert.assertEquals("Exception message: " + exception.message + ".\n", 0, exception.raised);
111 libvlc.libvlc_media_release(mediaDescriptor);
112 libvlc.libvlc_media_list_release(mediaList);
113 libvlc.libvlc_media_list_player_release(mediaListPlayer);
117 public void mediaListPlayerPlayItemAtIndex() throws Exception
119 libvlc_exception_t exception = new libvlc_exception_t();
120 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
121 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
122 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
123 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
124 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
125 libvlc.libvlc_media_list_player_play_item_at_index(mediaListPlayer, 0, exception);
128 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
129 if (exception.raised == 1)
131 throw new RuntimeException("Native exception thrown");
139 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
140 libvlc.libvlc_media_release(mediaDescriptor);
141 libvlc.libvlc_media_list_release(mediaList);
142 libvlc.libvlc_media_list_player_release(mediaListPlayer);
146 public void mediaListPlayerPlayItem() throws Exception
148 libvlc_exception_t exception = new libvlc_exception_t();
149 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
150 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
151 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
152 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
153 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
154 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
155 Assert.assertEquals(0, exception.raised);
158 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
159 if (exception.raised == 1)
161 throw new RuntimeException("Native exception thrown");
169 // FIXME give stats the time to run... there's probably a race condition in misc/stats.c:259 that
171 // Thread.sleep(400);
172 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
173 libvlc.libvlc_media_list_release(mediaList);
174 libvlc.libvlc_media_list_player_release(mediaListPlayer);
178 public void mediaListPlayerGetStateEnded()
180 libvlc_exception_t exception = new libvlc_exception_t();
181 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
182 int state = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
183 Assert.assertEquals(LibVlcState.libvlc_Ended.ordinal(), state);
184 libvlc.libvlc_media_list_player_release(mediaListPlayer);
188 public void mediaLtistPlayerPause() throws Exception
190 libvlc_exception_t exception = new libvlc_exception_t();
191 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
192 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
193 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
194 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
195 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
196 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
199 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
200 if (exception.raised == 1)
202 throw new RuntimeException("Native exception thrown");
210 libvlc.libvlc_media_list_player_pause(mediaListPlayer, exception);
211 Assert.assertEquals(exception.message, 0, exception.raised);
214 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
215 if (exception.raised == 1)
217 throw new RuntimeException("Native exception thrown");
225 int state = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
226 Assert.assertEquals(exception.message, 0, exception.raised);
228 "Expected state: " + LibVlcState.libvlc_Paused + ".\n",
229 LibVlcState.libvlc_Paused.ordinal(),
231 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
232 libvlc.libvlc_media_list_release(mediaList);
233 libvlc.libvlc_media_list_player_release(mediaListPlayer);
237 public void mediaListPlayerSetMediaInstance()
239 libvlc_exception_t exception = new libvlc_exception_t();
240 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
241 LibVlcMediaDescriptor md = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
242 LibVlcMediaInstance mi = libvlc.libvlc_media_player_new_from_media(md, exception);
243 libvlc.libvlc_media_list_player_set_media_player(mediaListPlayer, mi, exception);
244 Assert.assertEquals(0, exception.raised);
248 public void mediaListPlayerNextNoItems()
250 libvlc_exception_t exception = new libvlc_exception_t();
251 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
252 libvlc.libvlc_media_list_player_next(mediaListPlayer, exception);
253 Assert.assertEquals(1, exception.raised);
257 * fails, see https://trac.videolan.org/vlc/ticket/1535
260 public void mediaListPlayerNext() throws Exception
262 libvlc_exception_t exception = new libvlc_exception_t();
263 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
264 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
265 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
266 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
267 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
268 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
269 libvlc.libvlc_media_list_player_play_item_at_index(mediaListPlayer, 0, exception);
271 libvlc.libvlc_media_list_player_next(mediaListPlayer, exception);
272 Assert.assertEquals(0, exception.raised);
273 libvlc.libvlc_media_list_release(mediaList);
277 public void mediaListPlayerIsPlaying() throws Exception
279 libvlc_exception_t exception = new libvlc_exception_t();
280 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
281 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
282 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
283 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
284 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
285 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
289 int playing = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
290 Assert.assertEquals(0, exception.raised);
291 if (playing == LibVlcState.libvlc_Playing.ordinal())
298 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
301 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
302 Assert.assertEquals(0, exception.raised);
309 Assert.assertEquals(LibVlcState.libvlc_Ended.ordinal(), libvlc.libvlc_media_list_player_get_state(
312 libvlc.libvlc_media_list_release(mediaList);