]> git.sesse.net Git - vlc/blob - bindings/java/core/src/test/java/org/videolan/jvlc/internal/MediaListPlayerTest.java
write to tmpFile instead of /dev/dsp
[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 java.io.File;
29
30 import junit.framework.Assert;
31
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;
41
42
43 public class MediaListPlayerTest
44 {
45
46     private LibVlc libvlc = LibVlc.SYNC_INSTANCE;
47
48     private LibVlcInstance libvlcInstance;
49
50     private String mrl = this.getClass().getResource("/raffa_voice.ogg").getPath();
51
52     @Before
53     public void testSetup() throws Exception
54     {
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);
59     }
60
61     @After
62     public void tearDown()
63     {
64         libvlc.libvlc_release(libvlcInstance);
65     }
66
67     @Test
68     public void mediaListPlayerNewTest()
69     {
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);
74     }
75
76     @Test
77     public void mediaListPlayerSetMediaListTest()
78     {
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);
84     }
85
86     @Test
87     public void mediaListPlayerSetMediaListTest2()
88     {
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);
96     }
97
98     @Test
99     public void mediaListPlayerIsNotPlayingTest()
100     {
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);
106     }
107
108     @Test
109     public void mediaListPlayerPlayNoItemTest()
110     {
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);
115     }
116
117     /**
118      * this fails: see https://trac.videolan.org/vlc/ticket/1527
119      */
120 //    @Test
121     public void mediaListPlayerPlay()
122     {
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);
131     }
132
133     @Test
134     public void mediaListPlayerPlayItemAtIndex() throws Exception
135     {
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);
143         while (true)
144         {
145             int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
146             if (exception.raised == 1)
147             {
148                 throw new RuntimeException("Native exception thrown");
149             }
150             if (playing == 1)
151             {
152                 break;
153             }
154             Thread.sleep(150);
155         }
156         libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
157
158     }
159
160     @Test
161     public void mediaListPlayerPlayItem() throws Exception
162     {
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);
171         while (true)
172         {
173             int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
174             if (exception.raised == 1)
175             {
176                 throw new RuntimeException("Native exception thrown");
177             }
178             if (playing == 1)
179             {
180                 break;
181             }
182             Thread.sleep(150);
183         }
184         libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
185     }
186
187     @Test
188     public void mediaListPlayerPause() 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_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);
199         while (true)
200         {
201             int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
202             if (exception.raised == 1)
203             {
204                 throw new RuntimeException("Native exception thrown");
205             }            
206             if (playing == 0)
207             {
208                 break;
209             }
210             Thread.sleep(150);
211         }
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);
215     }
216
217     @Test
218     public void mediaListPlayerGetStateStopped()
219     {
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);
224     }
225     
226     @Test
227     public void mediaListPlayerSetMediaInstance()
228     {
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);
235     }
236     
237     @Test
238     public void mediaListPlayerNextNoItems()
239     {
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);
244     }
245     
246     /**
247      * fails, see https://trac.videolan.org/vlc/ticket/1535
248      */
249 //    @Test
250     public void mediaListPlayerNext() throws Exception
251     {
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);
260         Thread.sleep(150);
261         libvlc.libvlc_media_list_player_next(mediaListPlayer, exception);
262         Assert.assertEquals(0, exception.raised);
263     }
264
265     @Test
266     public void mediaListPlayerIsPlaying() throws Exception
267     {
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);
275
276         while (true)
277         {
278             int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
279             Assert.assertEquals(0, exception.raised);
280             if (playing == 1)
281             {
282                 break;
283             }
284             Thread.sleep(150);
285         }
286         Assert.assertEquals("Expected state: " + LibVlcState.libvlc_Playing +".\n", LibVlcState.libvlc_Playing.ordinal(), libvlc.libvlc_media_list_player_get_state(
287             mediaListPlayer,
288             exception));
289         
290         libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
291         while (true)
292         {
293             int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
294             Assert.assertEquals(0, exception.raised);
295             if (playing == 0)
296             {
297                 break;
298             }
299             Thread.sleep(150);
300         }
301         Assert.assertEquals(LibVlcState.libvlc_Stopped.ordinal(), libvlc.libvlc_media_list_player_get_state(
302             mediaListPlayer,
303             exception));
304     }
305
306
307
308 }