]> git.sesse.net Git - vlc/blob - test/libvlc/media_list_player.c
test: Use vlc's msleep. Only portable and working implementation we have.
[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  // For msleep
27 #include <vlc_common.h>
28 #include <vlc_mtime.h>
29
30 static void media_list_add_file_path(libvlc_instance_t *vlc, libvlc_media_list_t *ml, const char * file_path)
31 {
32     libvlc_media_t *md = libvlc_media_new (vlc, file_path, &ex);
33     catch ();
34
35     libvlc_media_list_add_media (ml, md, &ex);
36     catch ();
37
38     libvlc_media_release (md);
39 }
40
41 static void test_media_list_player_next(const char** argv, int argc)
42 {
43     libvlc_instance_t *vlc;
44     libvlc_media_t *md;
45     libvlc_media_list_t *ml;
46     libvlc_media_list_player_t *mlp;
47     
48     const char * file = test_default_sample;
49     
50     log ("Testing media player next()\n");
51     
52     libvlc_exception_init (&ex);
53     vlc = libvlc_new (argc, argv, &ex);
54     catch ();
55     
56     md = libvlc_media_new (vlc, file, &ex);
57     catch ();
58     
59     ml = libvlc_media_list_new (vlc, &ex);
60     catch ();
61     
62     mlp = libvlc_media_list_player_new (vlc, &ex);
63     catch ();
64
65     libvlc_media_list_add_media (ml, md, &ex);
66     catch ();
67
68     // Add three media
69     media_list_add_file_path (vlc, ml, file);
70     media_list_add_file_path (vlc, ml, file);
71     media_list_add_file_path (vlc, ml, file);
72
73     libvlc_media_list_player_set_media_list (mlp, ml, &ex);
74     
75     libvlc_media_list_player_play_item (mlp, md, &ex);
76     catch ();
77
78     libvlc_media_release (md);
79
80     msleep(100000);
81     
82     libvlc_media_list_player_next (mlp, &ex);
83     catch ();
84
85     libvlc_media_list_player_pause (mlp, &ex);
86     catch();
87
88     msleep(100000);
89     
90     libvlc_media_list_player_next (mlp, &ex);
91     catch ();
92     
93     libvlc_media_list_player_stop (mlp, &ex);
94     catch ();
95
96     msleep(100000);
97     
98     libvlc_media_list_player_next (mlp, &ex);
99     catch ();
100         
101     libvlc_media_list_player_release (mlp);
102     catch ();
103     
104     libvlc_release (vlc);
105     catch ();
106 }
107
108 static void test_media_list_player_pause_stop(const char** argv, int argc)
109 {
110     libvlc_instance_t *vlc;
111     libvlc_media_t *md;
112     libvlc_media_list_t *ml;
113     libvlc_media_list_player_t *mlp;
114
115     const char * file = test_default_sample;
116
117     log ("Testing play and pause of %s using the media list.\n", file);
118
119     libvlc_exception_init (&ex);
120     vlc = libvlc_new (argc, argv, &ex);
121     catch ();
122
123     md = libvlc_media_new (vlc, file, &ex);
124     catch ();
125
126     ml = libvlc_media_list_new (vlc, &ex);
127     catch ();
128
129     mlp = libvlc_media_list_player_new (vlc, &ex);
130
131     libvlc_media_list_add_media( ml, md, &ex );
132     catch ();
133
134     libvlc_media_list_player_set_media_list( mlp, ml, &ex );
135
136     libvlc_media_list_player_play_item( mlp, md, &ex );
137     catch ();
138
139     libvlc_media_list_player_pause (mlp, &ex);
140     catch();
141
142     libvlc_media_list_player_stop (mlp, &ex);
143     catch ();
144
145     libvlc_media_release (md);
146
147     libvlc_media_list_player_release (mlp);
148     catch ();
149
150     libvlc_release (vlc);
151     catch ();
152 }
153
154 static void test_media_list_player_play_item_at_index(const char** argv, int argc)
155 {
156     libvlc_instance_t *vlc;
157     libvlc_media_t *md;
158     libvlc_media_list_t *ml;
159     libvlc_media_list_player_t *mlp;
160
161     const char * file = test_default_sample;
162
163     log ("Testing play_item_at_index of %s using the media list.\n", file);
164
165     libvlc_exception_init (&ex);
166     vlc = libvlc_new (argc, argv, &ex);
167     catch ();
168
169     md = libvlc_media_new (vlc, file, &ex);
170     catch ();
171
172     ml = libvlc_media_list_new (vlc, &ex);
173     catch ();
174
175     mlp = libvlc_media_list_player_new (vlc, &ex);
176
177     for (unsigned i = 0; i < 5; i++)
178     {
179         libvlc_media_list_add_media( ml, md, &ex );
180         catch ();
181     }
182
183     libvlc_media_list_player_set_media_list( mlp, ml, &ex );
184
185     libvlc_media_list_player_play_item_at_index( mlp, 0, &ex );
186     catch ();
187
188     libvlc_media_list_player_stop (mlp, &ex);
189     catch ();
190
191     libvlc_media_release (md);
192     catch ();
193
194     libvlc_media_list_player_release (mlp);
195     catch ();
196
197     libvlc_release (vlc);
198     catch ();
199 }
200
201
202 int main (void)
203 {
204     test_init();
205
206     test_media_list_player_pause_stop (test_defaults_args, test_defaults_nargs);
207     test_media_list_player_play_item_at_index (test_defaults_args, test_defaults_nargs);
208     test_media_list_player_next (test_defaults_args, test_defaults_nargs);
209
210     return 0;
211 }