2 * media_list_player.c - libvlc smoke test
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. *
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. *
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 **********************************************************************/
27 #include <vlc_common.h>
28 #include <vlc_mtime.h>
30 static void* media_list_add_file_path(libvlc_instance_t *vlc, libvlc_media_list_t *ml, const char * file_path)
32 libvlc_media_t *md = libvlc_media_new (vlc, file_path, &ex);
35 libvlc_media_list_add_media (ml, md, &ex);
38 libvlc_media_release (md);
42 static bool done_playing = false;
43 static const unsigned items_count = 4;
44 static void * items[4];
45 static unsigned current_index = 0;
47 static void next_item_callback(const libvlc_event_t * p_event, void * user_data)
50 libvlc_media_t *md = p_event->u.media_list_player_next_item_set.item;
52 assert(current_index < items_count);
53 assert(items[current_index] == md);
54 log ("Item %d was correctly queued\n", current_index);
55 if (current_index == (items_count - 1))
59 static void test_media_list_player_items_queue(const char** argv, int argc)
61 libvlc_instance_t *vlc;
63 libvlc_media_list_t *ml;
64 libvlc_media_list_player_t *mlp;
66 const char * file = test_default_sample;
68 log ("Testing media player item queue-ing\n");
70 libvlc_exception_init (&ex);
71 vlc = libvlc_new (argc, argv, &ex);
74 md = libvlc_media_new (vlc, file, &ex);
77 ml = libvlc_media_list_new (vlc, &ex);
80 mlp = libvlc_media_list_player_new (vlc, &ex);
83 libvlc_media_list_add_media (ml, md, &ex);
88 // Add three more media
89 items[1] = media_list_add_file_path (vlc, ml, file);
90 items[2] = media_list_add_file_path (vlc, ml, file);
91 items[3] = media_list_add_file_path (vlc, ml, file);
93 libvlc_media_list_player_set_media_list (mlp, ml, &ex);
95 libvlc_event_manager_t * em = libvlc_media_list_player_event_manager(mlp);
96 libvlc_event_attach(em, libvlc_MediaListPlayerNextItemSet, next_item_callback, NULL, &ex);
99 libvlc_media_list_player_play_item (mlp, md, &ex);
102 // Wait dummily for next_item_callback() to flag 'done_playing':
103 while (!done_playing)
106 libvlc_media_list_player_stop (mlp, &ex);
109 libvlc_media_list_player_release (mlp);
112 libvlc_release (vlc);
116 static void test_media_list_player_next(const char** argv, int argc)
118 libvlc_instance_t *vlc;
120 libvlc_media_list_t *ml;
121 libvlc_media_list_player_t *mlp;
123 const char * file = test_default_sample;
125 log ("Testing media player next()\n");
127 libvlc_exception_init (&ex);
128 vlc = libvlc_new (argc, argv, &ex);
131 md = libvlc_media_new (vlc, file, &ex);
134 ml = libvlc_media_list_new (vlc, &ex);
137 mlp = libvlc_media_list_player_new (vlc, &ex);
140 libvlc_media_list_add_media (ml, md, &ex);
144 media_list_add_file_path (vlc, ml, file);
145 media_list_add_file_path (vlc, ml, file);
146 media_list_add_file_path (vlc, ml, file);
148 libvlc_media_list_player_set_media_list (mlp, ml, &ex);
150 libvlc_media_list_player_play_item (mlp, md, &ex);
153 libvlc_media_release (md);
157 libvlc_media_list_player_next (mlp, &ex);
160 libvlc_media_list_player_pause (mlp, &ex);
165 libvlc_media_list_player_next (mlp, &ex);
168 libvlc_media_list_player_stop (mlp, &ex);
173 libvlc_media_list_player_next (mlp, &ex);
176 libvlc_media_list_player_release (mlp);
179 libvlc_release (vlc);
183 static void test_media_list_player_pause_stop(const char** argv, int argc)
185 libvlc_instance_t *vlc;
187 libvlc_media_list_t *ml;
188 libvlc_media_list_player_t *mlp;
190 const char * file = test_default_sample;
192 log ("Testing play and pause of %s using the media list.\n", file);
194 libvlc_exception_init (&ex);
195 vlc = libvlc_new (argc, argv, &ex);
198 md = libvlc_media_new (vlc, file, &ex);
201 ml = libvlc_media_list_new (vlc, &ex);
204 mlp = libvlc_media_list_player_new (vlc, &ex);
206 libvlc_media_list_add_media( ml, md, &ex );
209 libvlc_media_list_player_set_media_list( mlp, ml, &ex );
211 libvlc_media_list_player_play_item( mlp, md, &ex );
214 libvlc_media_list_player_pause (mlp, &ex);
217 libvlc_media_list_player_stop (mlp, &ex);
220 libvlc_media_release (md);
222 libvlc_media_list_player_release (mlp);
225 libvlc_release (vlc);
229 static void test_media_list_player_play_item_at_index(const char** argv, int argc)
231 libvlc_instance_t *vlc;
233 libvlc_media_list_t *ml;
234 libvlc_media_list_player_t *mlp;
236 const char * file = test_default_sample;
238 log ("Testing play_item_at_index of %s using the media list.\n", file);
240 libvlc_exception_init (&ex);
241 vlc = libvlc_new (argc, argv, &ex);
244 md = libvlc_media_new (vlc, file, &ex);
247 ml = libvlc_media_list_new (vlc, &ex);
250 mlp = libvlc_media_list_player_new (vlc, &ex);
252 for (unsigned i = 0; i < 5; i++)
254 libvlc_media_list_add_media( ml, md, &ex );
258 libvlc_media_list_player_set_media_list( mlp, ml, &ex );
260 libvlc_media_list_player_play_item_at_index( mlp, 0, &ex );
263 libvlc_media_list_player_stop (mlp, &ex);
266 libvlc_media_release (md);
269 libvlc_media_list_player_release (mlp);
272 libvlc_release (vlc);
281 test_media_list_player_pause_stop (test_defaults_args, test_defaults_nargs);
282 test_media_list_player_play_item_at_index (test_defaults_args, test_defaults_nargs);
283 test_media_list_player_next (test_defaults_args, test_defaults_nargs);
284 test_media_list_player_items_queue (test_defaults_args, test_defaults_nargs);