]> git.sesse.net Git - vlc/blob - test/libvlc/media_player.c
8df6b10311a032688785b3a00827e2ed51c5ef54
[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 test_media_player_play_stop(const char** argv, int argc)
27 {
28     libvlc_instance_t *vlc;
29     libvlc_media_t *md;
30     libvlc_media_player_t *mi;
31     const char * file = test_default_sample;
32
33     log ("Testing play and pause of %s\n", file);
34
35     vlc = libvlc_new (argc, argv);
36     assert (vlc != NULL);
37
38     md = libvlc_media_new (vlc, file);
39     assert (md != NULL);
40
41     mi = libvlc_media_player_new_from_media (md);
42     assert (mi != NULL);
43
44     libvlc_media_release (md);
45
46     libvlc_media_player_play (mi);
47
48     /* Wait a correct state */
49     libvlc_state_t state;
50     do {
51         state = libvlc_media_player_get_state (mi);
52     } while( state != libvlc_Playing &&
53              state != libvlc_Error &&
54              state != libvlc_Ended );
55
56     assert( state == libvlc_Playing || state == libvlc_Ended );
57
58     libvlc_media_player_stop (mi);
59     libvlc_media_player_release (mi);
60     libvlc_release (vlc);
61 }
62
63 static void test_media_player_pause_stop(const char** argv, int argc)
64 {
65     libvlc_instance_t *vlc;
66     libvlc_media_t *md;
67     libvlc_media_player_t *mi;
68     const char * file = test_default_sample;
69
70     log ("Testing pause and stop of %s\n", file);
71
72     vlc = libvlc_new (argc, argv);
73     assert (vlc != NULL);
74
75     md = libvlc_media_new (vlc, file);
76     assert (md != NULL);
77
78     mi = libvlc_media_player_new_from_media (md);
79     assert (mi != NULL);
80
81     libvlc_media_release (md);
82
83     libvlc_media_player_play (mi);
84
85     log ("Waiting for playing\n");
86
87     /* Wait a correct state */
88     libvlc_state_t state;
89     do {
90         state = libvlc_media_player_get_state (mi);
91     } while( state != libvlc_Playing &&
92              state != libvlc_Error &&
93              state != libvlc_Ended );
94
95     assert( state == libvlc_Playing || state == libvlc_Ended );
96
97 #if 0
98     /* This can't work because under some condition (short file, this is the case) this will be
99      * equivalent to a play() */
100     libvlc_media_player_pause (mi);
101
102     log ("Waiting for pause\n");
103
104     /* Wait a correct state */
105     do {
106         state = libvlc_media_player_get_state (mi);
107     } while( state != libvlc_Paused &&
108             state != libvlc_Error &&
109             state != libvlc_Ended );
110
111     assert( state == libvlc_Paused || state == libvlc_Ended );
112 #endif
113     
114     libvlc_media_player_stop (mi);
115     libvlc_media_player_release (mi);
116     libvlc_release (vlc);
117 }
118
119
120 int main (void)
121 {
122     test_init();
123
124     test_media_player_play_stop (test_defaults_args, test_defaults_nargs);
125     test_media_player_pause_stop (test_defaults_args, test_defaults_nargs);
126
127     return 0;
128 }