]> git.sesse.net Git - vlc/blob - test/libvlc/media_list_player.c
test: Spend less time in the media_list_player test.
[vlc] / test / libvlc / media_list_player.c
1 /*
2  * media_list_player.c - libvlc smoke test
3  *
4  * $Id$
5  */
6
7 /**********************************************************************
8  *  Copyright (C) 2007 RĂ©mi Denis-Courmont.                           *
9  *  This program is free software; you can redistribute and/or modify *
10  *  it under the terms of the GNU General Public License as published *
11  *  by the Free Software Foundation; version 2 of the license, or (at *
12  *  your option) any later version.                                   *
13  *                                                                    *
14  *  This program is distributed in the hope that it will be useful,   *
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of    *
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.              *
17  *  See the GNU General Public License for more details.              *
18  *                                                                    *
19  *  You should have received a copy of the GNU General Public License *
20  *  along with this program; if not, you can get it from:             *
21  *  http://www.gnu.org/copyleft/gpl.html                              *
22  **********************************************************************/
23
24 #include "test.h"
25
26 static void media_list_add_file_path(libvlc_instance_t *vlc, libvlc_media_list_t *ml, const char * file_path)
27 {
28     libvlc_media_t *md = libvlc_media_new (vlc, file_path, &ex);
29     catch ();
30
31     libvlc_media_list_add_media (ml, md, &ex);
32     catch ();
33
34     libvlc_media_release (md);
35 }
36
37 static void test_media_list_player_next(const char** argv, int argc)
38 {
39     libvlc_instance_t *vlc;
40     libvlc_media_t *md;
41     libvlc_media_list_t *ml;
42     libvlc_media_list_player_t *mlp;
43     
44     const char * file = test_default_sample;
45     
46     log ("Testing media player next()\n");
47     
48     libvlc_exception_init (&ex);
49     vlc = libvlc_new (argc, argv, &ex);
50     catch ();
51     
52     md = libvlc_media_new (vlc, file, &ex);
53     catch ();
54     
55     ml = libvlc_media_list_new (vlc, &ex);
56     catch ();
57     
58     mlp = libvlc_media_list_player_new (vlc, &ex);
59     catch ();
60
61     libvlc_media_list_add_media (ml, md, &ex);
62     catch ();
63
64     // Add three media
65     media_list_add_file_path (vlc, ml, file);
66     media_list_add_file_path (vlc, ml, file);
67     media_list_add_file_path (vlc, ml, file);
68
69     libvlc_media_list_player_set_media_list (mlp, ml, &ex);
70     
71     libvlc_media_list_player_play_item (mlp, md, &ex);
72     catch ();
73
74     libvlc_media_release (md);
75
76     usleep(100000);
77     
78     libvlc_media_list_player_next (mlp, &ex);
79     catch ();
80
81     libvlc_media_list_player_pause (mlp, &ex);
82     catch();
83
84     usleep(100000);
85     
86     libvlc_media_list_player_next (mlp, &ex);
87     catch ();
88     
89     libvlc_media_list_player_stop (mlp, &ex);
90     catch ();
91
92     usleep(100000);
93     
94     libvlc_media_list_player_next (mlp, &ex);
95     catch ();
96         
97     libvlc_media_list_player_release (mlp);
98     catch ();
99     
100     libvlc_release (vlc);
101     catch ();
102 }
103
104 static void test_media_list_player_pause_stop(const char** argv, int argc)
105 {
106     libvlc_instance_t *vlc;
107     libvlc_media_t *md;
108     libvlc_media_list_t *ml;
109     libvlc_media_list_player_t *mlp;
110
111     const char * file = test_default_sample;
112
113     log ("Testing play and pause of %s using the media list.\n", file);
114
115     libvlc_exception_init (&ex);
116     vlc = libvlc_new (argc, argv, &ex);
117     catch ();
118
119     md = libvlc_media_new (vlc, file, &ex);
120     catch ();
121
122     ml = libvlc_media_list_new (vlc, &ex);
123     catch ();
124
125     mlp = libvlc_media_list_player_new (vlc, &ex);
126
127     libvlc_media_list_add_media( ml, md, &ex );
128     catch ();
129
130     libvlc_media_list_player_set_media_list( mlp, ml, &ex );
131
132     libvlc_media_list_player_play_item( mlp, md, &ex );
133     catch ();
134
135     libvlc_media_list_player_pause (mlp, &ex);
136     catch();
137
138     libvlc_media_list_player_stop (mlp, &ex);
139     catch ();
140
141     libvlc_media_release (md);
142
143     libvlc_media_list_player_release (mlp);
144     catch ();
145
146     libvlc_release (vlc);
147     catch ();
148 }
149
150 static void test_media_list_player_play_item_at_index(const char** argv, int argc)
151 {
152     libvlc_instance_t *vlc;
153     libvlc_media_t *md;
154     libvlc_media_list_t *ml;
155     libvlc_media_list_player_t *mlp;
156
157     const char * file = test_default_sample;
158
159     log ("Testing play_item_at_index of %s using the media list.\n", file);
160
161     libvlc_exception_init (&ex);
162     vlc = libvlc_new (argc, argv, &ex);
163     catch ();
164
165     md = libvlc_media_new (vlc, file, &ex);
166     catch ();
167
168     ml = libvlc_media_list_new (vlc, &ex);
169     catch ();
170
171     mlp = libvlc_media_list_player_new (vlc, &ex);
172
173     for (unsigned i = 0; i < 5; i++)
174     {
175         libvlc_media_list_add_media( ml, md, &ex );
176         catch ();
177     }
178
179     libvlc_media_list_player_set_media_list( mlp, ml, &ex );
180
181     libvlc_media_list_player_play_item_at_index( mlp, 0, &ex );
182     catch ();
183
184     libvlc_media_list_player_stop (mlp, &ex);
185     catch ();
186
187     libvlc_media_release (md);
188     catch ();
189
190     libvlc_media_list_player_release (mlp);
191     catch ();
192
193     libvlc_release (vlc);
194     catch ();
195 }
196
197
198 int main (void)
199 {
200     test_init();
201
202     test_media_list_player_pause_stop (test_defaults_args, test_defaults_nargs);
203     test_media_list_player_play_item_at_index (test_defaults_args, test_defaults_nargs);
204     test_media_list_player_next (test_defaults_args, test_defaults_nargs);
205
206     return 0;
207 }