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