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()
53 libvlc_exception_t exception = new libvlc_exception_t();
54 libvlcInstance = libvlc.libvlc_new(0, new String[]{}, exception);
58 public void tearDown()
60 libvlc.libvlc_release(libvlcInstance);
64 public void mediaListPlayerNewTest()
66 libvlc_exception_t exception = new libvlc_exception_t();
67 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
68 Assert.assertNotNull(mediaListPlayer);
69 Assert.assertEquals(0, exception.raised);
73 public void mediaListPlayerSetMediaListTest()
75 libvlc_exception_t exception = new libvlc_exception_t();
76 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
77 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
78 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
79 Assert.assertEquals(0, exception.raised);
83 public void mediaListPlayerSetMediaListTest2()
85 libvlc_exception_t exception = new libvlc_exception_t();
86 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
87 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
88 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
89 libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception);
90 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
91 Assert.assertEquals(0, exception.raised);
95 public void mediaListPlayerIsPlayingTest()
97 libvlc_exception_t exception = new libvlc_exception_t();
98 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
99 int result = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
100 Assert.assertEquals(0, result);
101 Assert.assertEquals(0, exception.raised);
105 public void mediaListPlayerPlayNoItemTest()
107 libvlc_exception_t exception = new libvlc_exception_t();
108 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
109 libvlc.libvlc_media_list_player_play(mediaListPlayer, exception);
110 Assert.assertEquals(1, exception.raised);
114 * this fails: see https://trac.videolan.org/vlc/ticket/1527
117 public void mediaListPlayerPlay()
119 libvlc_exception_t exception = new libvlc_exception_t();
120 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
121 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
122 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
123 libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception);
124 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
125 libvlc.libvlc_media_list_player_play(mediaListPlayer, exception);
126 Assert.assertEquals("Exception message: " + exception.message + ".\n", 0, exception.raised);
130 public void mediaListPlayerPlayItemAtIndex()
132 libvlc_exception_t exception = new libvlc_exception_t();
133 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
134 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
135 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
136 libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception);
137 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
138 libvlc.libvlc_media_list_player_play_item_at_index(mediaListPlayer, 0, exception);
142 public void mediaListPlayerPlayItem() throws Exception
144 libvlc_exception_t exception = new libvlc_exception_t();
145 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
146 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
147 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
148 libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception);
149 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
150 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
154 public void mediaListPlayerPause()
156 libvlc_exception_t exception = new libvlc_exception_t();
157 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
158 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
159 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
160 libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception);
161 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
162 libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
163 libvlc.libvlc_media_list_player_pause(mediaListPlayer, exception);
164 Assert.assertEquals(0, exception.raised);
165 int state = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
166 Assert.assertEquals(LibVlcState.libvlc_Paused.ordinal(), state);
170 public void mediaListPlayerIsPlaying() 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_descriptor_new(libvlcInstance, mrl, exception);
176 libvlc.libvlc_media_list_add_media_descriptor(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);
182 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
183 Assert.assertEquals(0, exception.raised);
190 Assert.assertEquals(LibVlcState.libvlc_Playing.ordinal(), libvlc.libvlc_media_list_player_get_state(
194 libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
197 int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
198 Assert.assertEquals(0, exception.raised);
205 Assert.assertEquals(LibVlcState.libvlc_Stopped.ordinal(), libvlc.libvlc_media_list_player_get_state(
211 public void mediaListPlayerGetStateStopped()
213 libvlc_exception_t exception = new libvlc_exception_t();
214 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
215 int state = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
216 Assert.assertEquals(LibVlcState.libvlc_Stopped.ordinal(), state);
220 public void mediaListPlayerSetMediaInstance()
222 libvlc_exception_t exception = new libvlc_exception_t();
223 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
224 LibVlcMediaDescriptor md = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
225 LibVlcMediaInstance mi = libvlc.libvlc_media_instance_new_from_media_descriptor(md, exception);
226 libvlc.libvlc_media_list_player_set_media_instance(mediaListPlayer, mi, exception);
227 Assert.assertEquals(0, exception.raised);
231 public void mediaListPlayerNextNoItems()
233 libvlc_exception_t exception = new libvlc_exception_t();
234 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
235 libvlc.libvlc_media_list_player_next(mediaListPlayer, exception);
236 Assert.assertEquals(1, exception.raised);
240 * fails, see https://trac.videolan.org/vlc/ticket/1535
243 public void mediaListPlayerNext() throws Exception
245 libvlc_exception_t exception = new libvlc_exception_t();
246 LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
247 LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
248 LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
249 libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception);
250 libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception);
251 libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
252 libvlc.libvlc_media_list_player_play_item_at_index(mediaListPlayer, 0, exception);
254 libvlc.libvlc_media_list_player_next(mediaListPlayer, exception);
255 Assert.assertEquals(0, exception.raised);