]> git.sesse.net Git - vlc/blob - test/libvlc/media_player.c
0b0be8d863677330df2329f2ce8856dbdc40019d
[vlc] / test / libvlc / media_player.c
1 /*
2  * media_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 wait_playing(libvlc_media_player_t *mp)
27 {
28     libvlc_state_t state;
29     do {
30         state = libvlc_media_player_get_state (mp);
31     } while(state != libvlc_Playing &&
32             state != libvlc_Error &&
33             state != libvlc_Ended );
34
35     state = libvlc_media_player_get_state (mp);
36     assert(state == libvlc_Playing || state == libvlc_Ended);
37 }
38
39 static void wait_paused(libvlc_media_player_t *mp)
40 {
41     libvlc_state_t state;
42     do {
43         state = libvlc_media_player_get_state (mp);
44     } while(state != libvlc_Paused &&
45             state != libvlc_Ended );
46
47     state = libvlc_media_player_get_state (mp);
48     assert(state == libvlc_Paused || state == libvlc_Ended);
49 }
50
51 static void test_media_player_set_media(const char** argv, int argc)
52 {
53     const char * file = test_default_sample;
54
55     log ("Testing set_media\n");
56
57     libvlc_instance_t *vlc = libvlc_new (argc, argv);
58     assert (vlc != NULL);
59
60     libvlc_media_t *md = libvlc_media_new_path (vlc, file);
61     assert (md != NULL);
62
63     libvlc_media_player_t *mp = libvlc_media_player_new (vlc);
64     assert (mp != NULL);
65
66     libvlc_media_player_set_media (mp, md);
67
68     libvlc_media_release (md);
69
70     libvlc_media_player_play (mp);
71
72     wait_playing (mp);
73
74     libvlc_media_player_stop (mp);
75     libvlc_media_player_release (mp);
76     libvlc_release (vlc);
77 }
78
79 static void test_media_player_play_stop(const char** argv, int argc)
80 {
81     libvlc_instance_t *vlc;
82     libvlc_media_t *md;
83     libvlc_media_player_t *mi;
84     const char * file = test_default_sample;
85
86     log ("Testing play and pause of %s\n", file);
87
88     vlc = libvlc_new (argc, argv);
89     assert (vlc != NULL);
90
91     md = libvlc_media_new_path (vlc, file);
92     assert (md != NULL);
93
94     mi = libvlc_media_player_new_from_media (md);
95     assert (mi != NULL);
96
97     libvlc_media_release (md);
98
99     libvlc_media_player_play (mi);
100
101     wait_playing (mi);
102
103     libvlc_media_player_stop (mi);
104     libvlc_media_player_release (mi);
105     libvlc_release (vlc);
106 }
107
108 static void test_media_player_pause_stop(const char** argv, int argc)
109 {
110     libvlc_instance_t *vlc;
111     libvlc_media_t *md;
112     libvlc_media_player_t *mi;
113     const char * file = test_default_sample;
114
115     log ("Testing pause and stop of %s\n", file);
116
117     vlc = libvlc_new (argc, argv);
118     assert (vlc != NULL);
119
120     md = libvlc_media_new_path (vlc, file);
121     assert (md != NULL);
122
123     mi = libvlc_media_player_new_from_media (md);
124     assert (mi != NULL);
125
126     libvlc_media_release (md);
127
128     libvlc_media_player_play (mi);
129
130     log ("Waiting for playing\n");
131
132     wait_playing (mi);
133
134     libvlc_media_player_set_pause (mi, true);
135     log ("Waiting for pause\n");
136     wait_paused (mi);
137
138     libvlc_media_player_stop (mi);
139     libvlc_media_player_release (mi);
140     libvlc_release (vlc);
141 }
142
143
144 int main (void)
145 {
146     test_init();
147
148     test_media_player_set_media (test_defaults_args, test_defaults_nargs);
149     test_media_player_play_stop (test_defaults_args, test_defaults_nargs);
150     test_media_player_pause_stop (test_defaults_args, test_defaults_nargs);
151
152     return 0;
153 }