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;
30 import junit.framework.Assert;
32 import org.junit.After;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.videolan.jvlc.internal.LibVlc.LibVlcInstance;
36 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaDescriptor;
37 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaInstance;
38 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaList;
39 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaListPlayer;
40 import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t;
43 public class MediaListPlayerTest
46 private LibVlc libvlc = LibVlc.SYNC_INSTANCE;
48 private LibVlcInstance libvlcInstance;
50 private String mrl = this.getClass().getResource("/raffa_voice.ogg").getPath();
53 public void testSetup() throws Exception
55 libvlc_exception_t exception = new libvlc_exception_t();
56 libvlcInstance = libvlc.libvlc_new(0, new String[]{"-A","file","--audiofile-file=" + File.createTempFile("jvlc", ".wav").getAbsolutePath()}, exception);
57 // use the following line to use your audio card.
58 // libvlcInstance = libvlc.libvlc_new(0, new String[]{}, exception);
62 public void tearDown()
64 libvlc.libvlc_release(libvlcInstance);
68 public void mediaListPlayerNewTest()
70 libvlc_exception_t exception = new libvlc_exception_t();
71 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
72 Assert.assertNotNull(mediaListPlayer);
73 Assert.assertEquals(0, exception.raised);
77 public void mediaListPlayerSetMediaListTest()
79 libvlc_exception_t exception = new libvlc_exception_t();
80 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
81 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
82 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
83 Assert.assertEquals(0, exception.raised);
87 public void mediaListPlayerSetMediaListTest2()
89 libvlc_exception_t exception = new libvlc_exception_t();
90 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
91 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
92 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
93 libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception);
94 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
95 Assert.assertEquals(0, exception.raised);
99 public void mediaListPlayerIsNotPlayingTest()
101 libvlc_exception_t exception = new libvlc_exception_t();
102 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
103 int result = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
104 Assert.assertEquals(0, result);
105 Assert.assertEquals(0, exception.raised);
109 public void mediaListPlayerPlayNoItemTest()
111 libvlc_exception_t exception = new libvlc_exception_t();
112 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
113 libvlc.libvlc_media_list_player_play(mediaListPlayer, exception);
114 Assert.assertEquals(1, exception.raised);
118 * this fails: see https://trac.videolan.org/vlc/ticket/1527
121 public void mediaListPlayerPlay()
123 libvlc_exception_t exception = new libvlc_exception_t();
124 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
125 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
126 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
127 libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception);
128 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
129 libvlc.libvlc_media_list_player_play(mediaListPlayer, exception);
130 Assert.assertEquals("Exception message: " + exception.message + ".\n", 0, exception.raised);
134 public void mediaListPlayerPlayItemAtIndex() throws Exception
136 libvlc_exception_t exception = new libvlc_exception_t();
137 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
138 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
139 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
140 libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception);
141 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
142 libvlc.libvlc_media_list_player_play_item_at_index(mediaListPlayer, 0, exception);
145 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
146 if (exception.raised == 1)
148 throw new RuntimeException("Native exception thrown");
156 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
161 public void mediaListPlayerPlayItem() throws Exception
163 libvlc_exception_t exception = new libvlc_exception_t();
164 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
165 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
166 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
167 libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception);
168 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
169 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
170 Assert.assertEquals(0, exception.raised);
173 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
174 if (exception.raised == 1)
176 throw new RuntimeException("Native exception thrown");
184 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
188 public void mediaListPlayerPause() 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_descriptor_new(libvlcInstance, mrl, exception);
194 libvlc.libvlc_media_list_add_media_descriptor(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);
197 libvlc.libvlc_media_list_player_pause(mediaListPlayer, exception);
198 Assert.assertEquals(0, exception.raised);
201 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
202 if (exception.raised == 1)
204 throw new RuntimeException("Native exception thrown");
212 int state = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
213 Assert.assertEquals("Expected state: " + LibVlcState.libvlc_Paused +".\n", LibVlcState.libvlc_Paused.ordinal(), state);
214 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
218 public void mediaListPlayerGetStateStopped()
220 libvlc_exception_t exception = new libvlc_exception_t();
221 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
222 int state = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
223 Assert.assertEquals(LibVlcState.libvlc_Stopped.ordinal(), state);
227 public void mediaListPlayerSetMediaInstance()
229 libvlc_exception_t exception = new libvlc_exception_t();
230 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
231 LibVlcMediaDescriptor md = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
232 LibVlcMediaInstance mi = libvlc.libvlc_media_instance_new_from_media_descriptor(md, exception);
233 libvlc.libvlc_media_list_player_set_media_instance(mediaListPlayer, mi, exception);
234 Assert.assertEquals(0, exception.raised);
238 public void mediaListPlayerNextNoItems()
240 libvlc_exception_t exception = new libvlc_exception_t();
241 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
242 libvlc.libvlc_media_list_player_next(mediaListPlayer, exception);
243 Assert.assertEquals(1, exception.raised);
247 * fails, see https://trac.videolan.org/vlc/ticket/1535
250 public void mediaListPlayerNext() throws Exception
252 libvlc_exception_t exception = new libvlc_exception_t();
253 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
254 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
255 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
256 libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception);
257 libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception);
258 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
259 libvlc.libvlc_media_list_player_play_item_at_index(mediaListPlayer, 0, exception);
261 libvlc.libvlc_media_list_player_next(mediaListPlayer, exception);
262 Assert.assertEquals(0, exception.raised);
266 public void mediaListPlayerIsPlaying() throws Exception
268 libvlc_exception_t exception = new libvlc_exception_t();
269 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
270 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
271 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
272 libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception);
273 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
274 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
278 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
279 Assert.assertEquals(0, exception.raised);
286 Assert.assertEquals("Expected state: " + LibVlcState.libvlc_Playing +".\n", LibVlcState.libvlc_Playing.ordinal(), libvlc.libvlc_media_list_player_get_state(
290 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
293 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
294 Assert.assertEquals(0, exception.raised);
301 Assert.assertEquals(LibVlcState.libvlc_Stopped.ordinal(), libvlc.libvlc_media_list_player_get_state(