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);
75 public void mediaListPlayerSetMediaListTest()
77 libvlc_exception_t exception = new libvlc_exception_t();
78 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
79 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
80 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
81 Assert.assertEquals(0, exception.raised);
85 public void mediaListPlayerSetMediaListTest2()
87 libvlc_exception_t exception = new libvlc_exception_t();
88 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
89 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
90 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
91 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
92 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
93 Assert.assertEquals(0, exception.raised);
97 public void mediaListPlayerIsNotPlayingTest()
99 libvlc_exception_t exception = new libvlc_exception_t();
100 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
101 int result = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
102 Assert.assertEquals(0, result);
103 Assert.assertEquals(0, exception.raised);
107 public void mediaListPlayerPlayNoItemTest()
109 libvlc_exception_t exception = new libvlc_exception_t();
110 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
111 libvlc.libvlc_media_list_player_play(mediaListPlayer, exception);
112 Assert.assertEquals(1, exception.raised);
116 * this fails: see https://trac.videolan.org/vlc/ticket/1527
119 public void mediaListPlayerPlay()
121 libvlc_exception_t exception = new libvlc_exception_t();
122 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
123 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
124 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
125 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
126 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
127 libvlc.libvlc_media_list_player_play(mediaListPlayer, exception);
128 Assert.assertEquals("Exception message: " + exception.message + ".\n", 0, exception.raised);
132 public void mediaListPlayerPlayItemAtIndex() throws Exception
134 libvlc_exception_t exception = new libvlc_exception_t();
135 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
136 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
137 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
138 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
139 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
140 libvlc.libvlc_media_list_player_play_item_at_index(mediaListPlayer, 0, exception);
143 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
144 if (exception.raised == 1)
146 throw new RuntimeException("Native exception thrown");
154 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
159 public void mediaListPlayerPlayItem() throws Exception
161 libvlc_exception_t exception = new libvlc_exception_t();
162 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
163 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
164 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
165 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
166 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
167 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
168 Assert.assertEquals(0, exception.raised);
171 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
172 if (exception.raised == 1)
174 throw new RuntimeException("Native exception thrown");
182 // FIXME give stats the time to run... there's probably a race condition in misc/stats.c:259 that
185 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
186 libvlc.libvlc_media_list_player_release(mediaListPlayer);
190 public void mediaListPlayerGetStateStopped()
192 libvlc_exception_t exception = new libvlc_exception_t();
193 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
194 int state = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
195 Assert.assertEquals(LibVlcState.libvlc_Stopped.ordinal(), state);
199 public void mediaListPlayerPause() throws Exception
201 libvlc_exception_t exception = new libvlc_exception_t();
202 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
203 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
204 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
205 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
206 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
207 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
210 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
211 if (exception.raised == 1)
213 throw new RuntimeException("Native exception thrown");
221 libvlc.libvlc_media_list_player_pause(mediaListPlayer, exception);
222 Assert.assertEquals(0, exception.raised);
225 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
226 if (exception.raised == 1)
228 throw new RuntimeException("Native exception thrown");
236 int state = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
237 Assert.assertEquals("Expected state: " + LibVlcState.libvlc_Paused +".\n", LibVlcState.libvlc_Paused.ordinal(), state);
238 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
239 libvlc.libvlc_media_list_player_release(mediaListPlayer);
244 public void mediaListPlayerSetMediaInstance()
246 libvlc_exception_t exception = new libvlc_exception_t();
247 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
248 LibVlcMediaDescriptor md = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
249 LibVlcMediaInstance mi = libvlc.libvlc_media_player_new_from_media(md, exception);
250 libvlc.libvlc_media_list_player_set_media_player(mediaListPlayer, mi, exception);
251 Assert.assertEquals(0, exception.raised);
255 public void mediaListPlayerNextNoItems()
257 libvlc_exception_t exception = new libvlc_exception_t();
258 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
259 libvlc.libvlc_media_list_player_next(mediaListPlayer, exception);
260 Assert.assertEquals(1, exception.raised);
264 * fails, see https://trac.videolan.org/vlc/ticket/1535
267 public void mediaListPlayerNext() throws Exception
269 libvlc_exception_t exception = new libvlc_exception_t();
270 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
271 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
272 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
273 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, 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_at_index(mediaListPlayer, 0, exception);
278 libvlc.libvlc_media_list_player_next(mediaListPlayer, exception);
279 Assert.assertEquals(0, exception.raised);
283 public void mediaListPlayerIsPlaying() throws Exception
285 libvlc_exception_t exception = new libvlc_exception_t();
286 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
287 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
288 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
289 libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
290 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
291 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
295 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
296 Assert.assertEquals(0, exception.raised);
303 Assert.assertEquals("Expected state: " + LibVlcState.libvlc_Playing +".\n", LibVlcState.libvlc_Playing.ordinal(), libvlc.libvlc_media_list_player_get_state(
307 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
310 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
311 Assert.assertEquals(0, exception.raised);
318 Assert.assertEquals(LibVlcState.libvlc_Stopped.ordinal(), libvlc.libvlc_media_list_player_get_state(