]> git.sesse.net Git - vlc/blob - bindings/java/core/src/test/java/org/videolan/jvlc/internal/MediaListPlayerTest.java
jvlc: download a sample file to run tests, if needed
[vlc] / bindings / java / core / src / test / java / org / videolan / jvlc / internal / MediaListPlayerTest.java
1 /*****************************************************************************
2  * MediaListPlayerTest.java: VLC Java Bindings
3  *****************************************************************************
4  * Copyright (C) 1998-2008 the VideoLAN team
5  *
6  * Authors: Filippo Carone <filippo@carone.org>
7  *
8  *
9  * $Id $
10  *
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.
15  *
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.
20  *
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  *****************************************************************************/
25
26 package org.videolan.jvlc.internal;
27
28 import junit.framework.Assert;
29
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;
36
37
38 public class MediaListPlayerTest extends AbstractVLCInternalTest
39 {
40     @Test
41     public void mediaListPlayerNewTest()
42     {
43         libvlc_exception_t exception = new libvlc_exception_t();
44         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
45         Assert.assertNotNull(mediaListPlayer);
46         Assert.assertEquals(0, exception.raised);
47         libvlc.libvlc_media_list_player_release(mediaListPlayer);
48     }
49
50     @Test
51     public void mediaListPlayerSetMediaListTest()
52     {
53         libvlc_exception_t exception = new libvlc_exception_t();
54         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
55         LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
56         libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
57         Assert.assertEquals(0, exception.raised);
58         libvlc.libvlc_media_list_release(mediaList);
59         libvlc.libvlc_media_list_player_release(mediaListPlayer);
60     }
61
62     @Test
63     public void mediaListPlayerSetMediaListTest2()
64     {
65         libvlc_exception_t exception = new libvlc_exception_t();
66         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
67         LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
68         LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
69         libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
70         libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
71         Assert.assertEquals(0, exception.raised);
72         libvlc.libvlc_media_list_release(mediaList);
73         libvlc.libvlc_media_list_player_release(mediaListPlayer);
74     }
75
76     @Test
77     public void mediaListPlayerIsNotPlayingTest()
78     {
79         libvlc_exception_t exception = new libvlc_exception_t();
80         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
81         int result = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
82         Assert.assertEquals(0, result);
83         Assert.assertEquals(0, exception.raised);
84         libvlc.libvlc_media_list_player_release(mediaListPlayer);
85     }
86
87     @Test
88     public void mediaListPlayerPlayNoItemTest()
89     {
90         libvlc_exception_t exception = new libvlc_exception_t();
91         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
92         libvlc.libvlc_media_list_player_play(mediaListPlayer, exception);
93         Assert.assertEquals(1, exception.raised);
94         libvlc.libvlc_media_list_player_release(mediaListPlayer);
95     }
96
97     /**
98      * this fails: see https://trac.videolan.org/vlc/ticket/1527
99      */
100     // @Test
101     public void mediaListPlayerPlay()
102     {
103         libvlc_exception_t exception = new libvlc_exception_t();
104         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
105         LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
106         LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
107         libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
108         libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
109         libvlc.libvlc_media_list_player_play(mediaListPlayer, exception);
110         Assert.assertEquals("Exception message: " + exception.message + ".\n", 0, exception.raised);
111         libvlc.libvlc_media_release(mediaDescriptor);
112         libvlc.libvlc_media_list_release(mediaList);
113         libvlc.libvlc_media_list_player_release(mediaListPlayer);
114     }
115
116     @Test
117     public void mediaListPlayerPlayItemAtIndex() throws Exception
118     {
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_new(libvlcInstance, mrl, exception);
123         libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
124         libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
125         libvlc.libvlc_media_list_player_play_item_at_index(mediaListPlayer, 0, exception);
126         while (true)
127         {
128             int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
129             if (exception.raised == 1)
130             {
131                 throw new RuntimeException("Native exception thrown");
132             }
133             if (playing == 1)
134             {
135                 break;
136             }
137             Thread.sleep(150);
138         }
139         libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
140         libvlc.libvlc_media_release(mediaDescriptor);
141         libvlc.libvlc_media_list_release(mediaList);
142         libvlc.libvlc_media_list_player_release(mediaListPlayer);
143     }
144
145     @Test
146     public void mediaListPlayerPlayItem() throws Exception
147     {
148         libvlc_exception_t exception = new libvlc_exception_t();
149         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
150         LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
151         LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
152         libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
153         libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
154         libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
155         Assert.assertEquals(0, exception.raised);
156         while (true)
157         {
158             int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
159             if (exception.raised == 1)
160             {
161                 throw new RuntimeException("Native exception thrown");
162             }
163             if (playing == 1)
164             {
165                 break;
166             }
167             Thread.sleep(150);
168         }
169         // FIXME give stats the time to run... there's probably a race condition in misc/stats.c:259 that
170         // needs to be fixed
171         // Thread.sleep(400);
172         libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
173         libvlc.libvlc_media_list_release(mediaList);
174         libvlc.libvlc_media_list_player_release(mediaListPlayer);
175     }
176
177     @Test
178     public void mediaListPlayerGetStateEnded()
179     {
180         libvlc_exception_t exception = new libvlc_exception_t();
181         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
182         int state = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
183         Assert.assertEquals(LibVlcState.libvlc_Ended.ordinal(), state);
184         libvlc.libvlc_media_list_player_release(mediaListPlayer);
185     }
186
187     @Test
188     public void mediaLtistPlayerPause() throws Exception
189     {
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_new(libvlcInstance, mrl, exception);
194         libvlc.libvlc_media_list_add_media(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         while (true)
198         {
199             int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
200             if (exception.raised == 1)
201             {
202                 throw new RuntimeException("Native exception thrown");
203             }
204             if (playing == 1)
205             {
206                 break;
207             }
208             Thread.sleep(150);
209         }
210         libvlc.libvlc_media_list_player_pause(mediaListPlayer, exception);
211         Assert.assertEquals(exception.message, 0, exception.raised);
212         while (true)
213         {
214             int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
215             if (exception.raised == 1)
216             {
217                 throw new RuntimeException("Native exception thrown");
218             }
219             if (playing == 0)
220             {
221                 break;
222             }
223             Thread.sleep(150);
224         }
225         int state = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
226         Assert.assertEquals(exception.message, 0, exception.raised);
227         Assert.assertEquals(
228             "Expected state: " + LibVlcState.libvlc_Paused + ".\n",
229             LibVlcState.libvlc_Paused.ordinal(),
230             state);
231         libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
232         libvlc.libvlc_media_list_release(mediaList);
233         libvlc.libvlc_media_list_player_release(mediaListPlayer);
234     }
235
236     @Test
237     public void mediaListPlayerSetMediaInstance()
238     {
239         libvlc_exception_t exception = new libvlc_exception_t();
240         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
241         LibVlcMediaDescriptor md = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
242         LibVlcMediaInstance mi = libvlc.libvlc_media_player_new_from_media(md, exception);
243         libvlc.libvlc_media_list_player_set_media_player(mediaListPlayer, mi, exception);
244         Assert.assertEquals(0, exception.raised);
245     }
246
247     @Test
248     public void mediaListPlayerNextNoItems()
249     {
250         libvlc_exception_t exception = new libvlc_exception_t();
251         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
252         libvlc.libvlc_media_list_player_next(mediaListPlayer, exception);
253         Assert.assertEquals(1, exception.raised);
254     }
255
256     /**
257      * fails, see https://trac.videolan.org/vlc/ticket/1535
258      */
259     // @Test
260     public void mediaListPlayerNext() throws Exception
261     {
262         libvlc_exception_t exception = new libvlc_exception_t();
263         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
264         LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
265         LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
266         libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
267         libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
268         libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
269         libvlc.libvlc_media_list_player_play_item_at_index(mediaListPlayer, 0, exception);
270         Thread.sleep(150);
271         libvlc.libvlc_media_list_player_next(mediaListPlayer, exception);
272         Assert.assertEquals(0, exception.raised);
273         libvlc.libvlc_media_list_release(mediaList);
274     }
275
276     @Test
277     public void mediaListPlayerIsPlaying() throws Exception
278     {
279         libvlc_exception_t exception = new libvlc_exception_t();
280         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
281         LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
282         LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
283         libvlc.libvlc_media_list_add_media(mediaList, mediaDescriptor, exception);
284         libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
285         libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
286
287         while (true)
288         {
289             int playing = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
290             Assert.assertEquals(0, exception.raised);
291             if (playing == LibVlcState.libvlc_Playing.ordinal())
292             {
293                 break;
294             }
295             Thread.sleep(150);
296         }
297
298         libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
299         while (true)
300         {
301             int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
302             Assert.assertEquals(0, exception.raised);
303             if (playing == 0)
304             {
305                 break;
306             }
307             Thread.sleep(150);
308         }
309         Assert.assertEquals(LibVlcState.libvlc_Ended.ordinal(), libvlc.libvlc_media_list_player_get_state(
310             mediaListPlayer,
311             exception));
312         libvlc.libvlc_media_list_release(mediaList);
313     }
314
315 }