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