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[]{"-vvv","-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_list_release(mediaList);
137 libvlc.libvlc_media_list_player_release(mediaListPlayer);
141 public void mediaListPlayerPlayItemAtIndex() throws Exception
143 libvlc_exception_t exception = new libvlc_exception_t();
144 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
145 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
146 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
147 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
148 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
149 libvlc.libvlc_media_list_player_play_item_at_index(mediaListPlayer, 0, exception);
152 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
153 if (exception.raised == 1)
155 throw new RuntimeException("Native exception thrown");
163 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
164 libvlc.libvlc_media_list_release(mediaList);
165 libvlc.libvlc_media_list_player_release(mediaListPlayer);
170 public void mediaListPlayerPlayItem() throws Exception
172 libvlc_exception_t exception = new libvlc_exception_t();
173 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
174 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
175 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
176 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
177 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
178 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
179 Assert.assertEquals(0, exception.raised);
182 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
183 if (exception.raised == 1)
185 throw new RuntimeException("Native exception thrown");
193 // FIXME give stats the time to run... there's probably a race condition in misc/stats.c:259 that
196 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
197 libvlc.libvlc_media_list_release(mediaList);
198 libvlc.libvlc_media_list_player_release(mediaListPlayer);
202 public void mediaListPlayerGetStateStopped()
204 libvlc_exception_t exception = new libvlc_exception_t();
205 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
206 int state = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
207 Assert.assertEquals(LibVlcState.libvlc_Stopped.ordinal(), state);
208 libvlc.libvlc_media_list_player_release(mediaListPlayer);
212 public void mediaListPlayerPause() throws Exception
214 libvlc_exception_t exception = new libvlc_exception_t();
215 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
216 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
217 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
218 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
219 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
220 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
223 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
224 if (exception.raised == 1)
226 throw new RuntimeException("Native exception thrown");
234 libvlc.libvlc_media_list_player_pause(mediaListPlayer, exception);
235 Assert.assertEquals(0, exception.raised);
238 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
239 if (exception.raised == 1)
241 throw new RuntimeException("Native exception thrown");
249 int state = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
250 Assert.assertEquals("Expected state: " + LibVlcState.libvlc_Paused +".\n", LibVlcState.libvlc_Paused.ordinal(), state);
251 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
252 libvlc.libvlc_media_list_release(mediaList);
253 libvlc.libvlc_media_list_player_release(mediaListPlayer);
258 public void mediaListPlayerSetMediaInstance()
260 libvlc_exception_t exception = new libvlc_exception_t();
261 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
262 LibVlcMediaDescriptor md = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
263 LibVlcMediaInstance mi = libvlc.libvlc_media_player_new_from_media(md, exception);
264 libvlc.libvlc_media_list_player_set_media_player(mediaListPlayer, mi, exception);
265 Assert.assertEquals(0, exception.raised);
269 public void mediaListPlayerNextNoItems()
271 libvlc_exception_t exception = new libvlc_exception_t();
272 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
273 libvlc.libvlc_media_list_player_next(mediaListPlayer, exception);
274 Assert.assertEquals(1, exception.raised);
278 * fails, see https://trac.videolan.org/vlc/ticket/1535
281 public void mediaListPlayerNext() throws Exception
283 libvlc_exception_t exception = new libvlc_exception_t();
284 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
285 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
286 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
287 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
288 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
289 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
290 libvlc.libvlc_media_list_player_play_item_at_index(mediaListPlayer, 0, exception);
292 libvlc.libvlc_media_list_player_next(mediaListPlayer, exception);
293 Assert.assertEquals(0, exception.raised);
294 libvlc.libvlc_media_list_release(mediaList);
298 public void mediaListPlayerIsPlaying() throws Exception
300 libvlc_exception_t exception = new libvlc_exception_t();
301 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
302 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
303 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
304 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
305 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
306 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
310 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
311 Assert.assertEquals(0, exception.raised);
318 Assert.assertEquals("Expected state: " + LibVlcState.libvlc_Playing +".\n", LibVlcState.libvlc_Playing.ordinal(), libvlc.libvlc_media_list_player_get_state(
322 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
325 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
326 Assert.assertEquals(0, exception.raised);
333 Assert.assertEquals(LibVlcState.libvlc_Stopped.ordinal(), libvlc.libvlc_media_list_player_get_state(
336 libvlc.libvlc_media_list_release(mediaList);