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.LibVlcMediaDescriptor;
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 LibVlcMediaDescriptor 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 * this fails: see https://trac.videolan.org/vlc/ticket/1527
105 public void mediaListPlayerPlay()
107 libvlc_exception_t exception = new libvlc_exception_t();
108 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
109 current = mediaListPlayer;
110 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
111 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
112 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
113 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
114 libvlc.libvlc_media_list_player_play(mediaListPlayer, exception);
115 Assert.assertEquals("Exception message: " + exception.message + ".\n", 0, exception.raised);
116 libvlc.libvlc_media_release(mediaDescriptor);
117 libvlc.libvlc_media_list_release(mediaList);
118 libvlc.libvlc_media_list_player_release(mediaListPlayer);
122 public void mediaListPlayerPlayItemAtIndex() throws Exception
124 libvlc_exception_t exception = new libvlc_exception_t();
125 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
126 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
127 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
128 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
129 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
130 libvlc.libvlc_media_list_player_play_item_at_index(mediaListPlayer, 0, exception);
133 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
134 if (exception.raised == 1)
136 throw new RuntimeException("Native exception thrown");
144 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
145 while (libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception) != LibVlcState.libvlc_Ended
150 libvlc.libvlc_media_release(mediaDescriptor);
151 libvlc.libvlc_media_list_release(mediaList);
152 libvlc.libvlc_media_list_player_release(mediaListPlayer);
156 public void mediaListPlayerPlayItem() throws Exception
158 libvlc_exception_t exception = new libvlc_exception_t();
159 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
160 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
161 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
162 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
163 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
164 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
165 Assert.assertEquals(0, exception.raised);
168 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
169 if (exception.raised == 1)
171 throw new RuntimeException("Native exception thrown");
180 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
181 libvlc.libvlc_media_list_release(mediaList);
182 libvlc.libvlc_media_list_player_release(mediaListPlayer);
186 public void mediaListPlayerGetStateEnded()
188 libvlc_exception_t exception = new libvlc_exception_t();
189 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
190 int state = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
191 Assert.assertEquals(LibVlcState.libvlc_Ended.ordinal(), state);
192 libvlc.libvlc_media_list_player_release(mediaListPlayer);
196 public void mediaLtistPlayerPause() throws Exception
198 libvlc_exception_t exception = new libvlc_exception_t();
199 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
200 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
201 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
202 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
203 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
204 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
207 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
208 if (exception.raised == 1)
210 throw new RuntimeException("Native exception thrown");
218 libvlc.libvlc_media_list_player_pause(mediaListPlayer, exception);
220 int state = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
221 Assert.assertEquals(exception.message, 0, exception.raised);
223 "Expected state: " + LibVlcState.libvlc_Paused + ".\n",
224 LibVlcState.libvlc_Paused.ordinal(),
226 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
227 libvlc.libvlc_media_list_release(mediaList);
228 libvlc.libvlc_media_list_player_release(mediaListPlayer);
232 public void mediaListPlayerSetMediaInstance()
234 libvlc_exception_t exception = new libvlc_exception_t();
235 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
236 LibVlcMediaDescriptor md = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
237 LibVlcMediaInstance mi = libvlc.libvlc_media_player_new_from_media(md, exception);
238 libvlc.libvlc_media_list_player_set_media_player(mediaListPlayer, mi, exception);
239 Assert.assertEquals(0, exception.raised);
243 public void mediaListPlayerNextNoItems()
245 libvlc_exception_t exception = new libvlc_exception_t();
246 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
247 libvlc.libvlc_media_list_player_next(mediaListPlayer, exception);
248 Assert.assertEquals(1, exception.raised);
252 * fails, see https://trac.videolan.org/vlc/ticket/1535
255 public void mediaListPlayerNext() throws Exception
257 libvlc_exception_t exception = new libvlc_exception_t();
258 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
259 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
260 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
261 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
262 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
263 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
264 libvlc.libvlc_media_list_player_play_item_at_index(mediaListPlayer, 0, exception);
266 libvlc.libvlc_media_list_player_next(mediaListPlayer, exception);
267 Assert.assertEquals(0, exception.raised);
268 libvlc.libvlc_media_list_release(mediaList);
272 public void mediaListPlayerIsPlaying() throws Exception
274 libvlc_exception_t exception = new libvlc_exception_t();
275 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
276 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
277 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
278 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
279 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
280 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
284 int playing = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
285 Assert.assertEquals(0, exception.raised);
286 if (playing == LibVlcState.libvlc_Playing.ordinal())
293 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
296 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
297 Assert.assertEquals(0, exception.raised);
304 Assert.assertEquals(LibVlcState.libvlc_Ended.ordinal(), libvlc.libvlc_media_list_player_get_state(
307 libvlc.libvlc_media_list_release(mediaList);
312 public void tearDown()
316 libvlc.libvlc_media_list_player_stop(current, exception);
317 while (libvlc.libvlc_media_list_player_get_state(current, exception) != LibVlcState.libvlc_Ended.ordinal())
323 catch (InterruptedException e)