]> git.sesse.net Git - vlc/blob - bindings/java/core/src/test/java/org/videolan/jvlc/internal/MediaListPlayerTest.java
more libvlc_media_list_player tests
[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.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;
39
40
41 public class MediaListPlayerTest
42 {
43
44     private LibVlc libvlc = LibVlc.SYNC_INSTANCE;
45
46     private LibVlcInstance libvlcInstance;
47
48     private String mrl = this.getClass().getResource("/raffa_voice.ogg").getPath();
49
50     @Before
51     public void testSetup()
52     {
53         libvlc_exception_t exception = new libvlc_exception_t();
54         libvlcInstance = libvlc.libvlc_new(0, new String[]{}, exception);
55     }
56
57     @After
58     public void tearDown()
59     {
60         libvlc.libvlc_release(libvlcInstance);
61     }
62
63     @Test
64     public void mediaListPlayerNewTest()
65     {
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);
70     }
71
72     @Test
73     public void mediaListPlayerSetMediaListTest()
74     {
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);
80     }
81
82     @Test
83     public void mediaListPlayerSetMediaListTest2()
84     {
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);
92     }
93
94     @Test
95     public void mediaListPlayerIsPlayingTest()
96     {
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);
102     }
103
104     @Test
105     public void mediaListPlayerPlayNoItemTest()
106     {
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);
111     }
112
113     /**
114      * this fails: see https://trac.videolan.org/vlc/ticket/1527
115      */
116 //    @Test
117     public void mediaListPlayerPlay()
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_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);
127     }
128
129     @Test
130     public void mediaListPlayerPlayItemAtIndex()
131     {
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);
139     }
140
141     @Test
142     public void mediaListPlayerPlayItem() throws Exception
143     {
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);
151     }
152
153     @Test
154     public void mediaListPlayerPause()
155     {
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);
167     }
168
169     @Test
170     public void mediaListPlayerIsPlaying() throws Exception
171     {
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);
179
180         while (true)
181         {
182             int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
183             Assert.assertEquals(0, exception.raised);
184             if (playing == 1)
185             {
186                 break;
187             }
188             Thread.sleep(150);
189         }
190         Assert.assertEquals(LibVlcState.libvlc_Playing.ordinal(), libvlc.libvlc_media_list_player_get_state(
191             mediaListPlayer,
192             exception));
193         
194         libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
195         while (true)
196         {
197             int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
198             Assert.assertEquals(0, exception.raised);
199             if (playing == 0)
200             {
201                 break;
202             }
203             Thread.sleep(150);
204         }
205         Assert.assertEquals(LibVlcState.libvlc_Stopped.ordinal(), libvlc.libvlc_media_list_player_get_state(
206             mediaListPlayer,
207             exception));
208     }
209
210     @Test
211     public void mediaListPlayerGetStateStopped()
212     {
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);
217     }
218     
219     @Test
220     public void mediaListPlayerSetMediaInstance()
221     {
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);
228     }
229
230 }