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
42 public void mediaListPlayerNewTest()
44 libvlc_exception_t exception = new libvlc_exception_t();
45 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
46 Assert.assertNotNull(mediaListPlayer);
47 Assert.assertEquals(0, exception.raised);
48 libvlc.libvlc_media_list_player_release(mediaListPlayer);
52 public void mediaListPlayerSetMediaListTest()
54 libvlc_exception_t exception = new libvlc_exception_t();
55 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
56 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
57 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
58 Assert.assertEquals(0, exception.raised);
59 libvlc.libvlc_media_list_release(mediaList);
60 libvlc.libvlc_media_list_player_release(mediaListPlayer);
64 public void mediaListPlayerSetMediaListTest2()
66 libvlc_exception_t exception = new libvlc_exception_t();
67 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
68 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
69 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
70 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
71 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
72 Assert.assertEquals(0, exception.raised);
73 libvlc.libvlc_media_list_release(mediaList);
74 libvlc.libvlc_media_list_player_release(mediaListPlayer);
78 public void mediaListPlayerIsNotPlayingTest()
80 libvlc_exception_t exception = new libvlc_exception_t();
81 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
82 int result = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
83 Assert.assertEquals(0, result);
84 Assert.assertEquals(0, exception.raised);
85 libvlc.libvlc_media_list_player_release(mediaListPlayer);
89 public void mediaListPlayerPlayNoItemTest()
91 libvlc_exception_t exception = new libvlc_exception_t();
92 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
93 libvlc.libvlc_media_list_player_play(mediaListPlayer, exception);
94 Assert.assertEquals(1, exception.raised);
95 libvlc.libvlc_media_list_player_release(mediaListPlayer);
99 * this fails: see https://trac.videolan.org/vlc/ticket/1527
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 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
107 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
108 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
109 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
110 libvlc.libvlc_media_list_player_play(mediaListPlayer, exception);
111 Assert.assertEquals("Exception message: " + exception.message + ".\n", 0, exception.raised);
112 libvlc.libvlc_media_release(mediaDescriptor);
113 libvlc.libvlc_media_list_release(mediaList);
114 libvlc.libvlc_media_list_player_release(mediaListPlayer);
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 LibVlcMediaDescriptor 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 libvlc.libvlc_media_release(mediaDescriptor);
142 libvlc.libvlc_media_list_release(mediaList);
143 libvlc.libvlc_media_list_player_release(mediaListPlayer);
147 public void mediaListPlayerPlayItem() throws Exception
149 libvlc_exception_t exception = new libvlc_exception_t();
150 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
151 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
152 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
153 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
154 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
155 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
156 Assert.assertEquals(0, exception.raised);
159 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
160 if (exception.raised == 1)
162 throw new RuntimeException("Native exception thrown");
171 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
172 libvlc.libvlc_media_list_release(mediaList);
173 libvlc.libvlc_media_list_player_release(mediaListPlayer);
177 public void mediaListPlayerGetStateEnded()
179 libvlc_exception_t exception = new libvlc_exception_t();
180 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
181 int state = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
182 Assert.assertEquals(LibVlcState.libvlc_Ended.ordinal(), state);
183 libvlc.libvlc_media_list_player_release(mediaListPlayer);
187 public void mediaLtistPlayerPause() throws Exception
189 libvlc_exception_t exception = new libvlc_exception_t();
190 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
191 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
192 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
193 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
194 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
195 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
198 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
199 if (exception.raised == 1)
201 throw new RuntimeException("Native exception thrown");
209 libvlc.libvlc_media_list_player_pause(mediaListPlayer, exception);
211 int state = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
212 Assert.assertEquals(exception.message, 0, exception.raised);
214 "Expected state: " + LibVlcState.libvlc_Paused + ".\n",
215 LibVlcState.libvlc_Paused.ordinal(),
217 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
218 libvlc.libvlc_media_list_release(mediaList);
219 libvlc.libvlc_media_list_player_release(mediaListPlayer);
223 public void mediaListPlayerSetMediaInstance()
225 libvlc_exception_t exception = new libvlc_exception_t();
226 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
227 LibVlcMediaDescriptor md = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
228 LibVlcMediaInstance mi = libvlc.libvlc_media_player_new_from_media(md, exception);
229 libvlc.libvlc_media_list_player_set_media_player(mediaListPlayer, mi, exception);
230 Assert.assertEquals(0, exception.raised);
234 public void mediaListPlayerNextNoItems()
236 libvlc_exception_t exception = new libvlc_exception_t();
237 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
238 libvlc.libvlc_media_list_player_next(mediaListPlayer, exception);
239 Assert.assertEquals(1, exception.raised);
243 * fails, see https://trac.videolan.org/vlc/ticket/1535
246 public void mediaListPlayerNext() throws Exception
248 libvlc_exception_t exception = new libvlc_exception_t();
249 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
250 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
251 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
252 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
253 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
254 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
255 libvlc.libvlc_media_list_player_play_item_at_index(mediaListPlayer, 0, exception);
257 libvlc.libvlc_media_list_player_next(mediaListPlayer, exception);
258 Assert.assertEquals(0, exception.raised);
259 libvlc.libvlc_media_list_release(mediaList);
263 public void mediaListPlayerIsPlaying() throws Exception
265 libvlc_exception_t exception = new libvlc_exception_t();
266 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
267 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
268 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
269 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
270 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
271 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
275 int playing = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
276 Assert.assertEquals(0, exception.raised);
277 if (playing == LibVlcState.libvlc_Playing.ordinal())
284 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
287 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
288 Assert.assertEquals(0, exception.raised);
295 Assert.assertEquals(LibVlcState.libvlc_Ended.ordinal(), libvlc.libvlc_media_list_player_get_state(
298 libvlc.libvlc_media_list_release(mediaList);