1 /*
2  * player.h - Simple media player based on GStreamer
3  *
4  * Copyright (C) 2007-2008 Johannes H. Jensen <joh@pseudoberries.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19  *
20  * Authors:
21  * 		Johannes H. Jensen <joh@pseudoberries.com>
22  */
23 
24 #ifndef PLAYER_H_
25 #define PLAYER_H_
26 
27 #include <gst/gst.h>
28 
29 G_BEGIN_DECLS
30 
31 typedef enum {
32 	MEDIA_PLAYER_INVALID = 0,
33 	MEDIA_PLAYER_STOPPED,
34 	MEDIA_PLAYER_PLAYING,
35 	MEDIA_PLAYER_ERROR
36 } MediaPlayerState;
37 
38 typedef struct _MediaPlayer MediaPlayer;
39 
40 /*
41  * Callback for when the media player's state changes.
42  */
43 typedef void (*MediaPlayerStateChangeCallback)	(MediaPlayer *player, MediaPlayerState state, gpointer data);
44 
45 /*
46  * Callback for when an error occurs in the media player.
47  * The error details is put in the error argument. This value
48  * should _never_ be freed in the callback!
49  */
50 typedef void (*MediaPlayerErrorHandler)			(MediaPlayer *player, GError *error, gpointer data);
51 
52 struct _MediaPlayer {
53 	GstElement *player;
54 	gboolean loop;
55 	MediaPlayerState state;
56 
57 	guint watch_id;
58 
59 	MediaPlayerStateChangeCallback state_changed;
60 	MediaPlayerErrorHandler error_handler;
61 
62 	gpointer state_changed_data;
63 	gpointer error_handler_data;
64 };
65 
66 /**
67  * Create a new media player.
68  *
69  * @uri				The file to play.
70  * @loop			Wether to loop or not.
71  * @state_callback	An optional #MediaPlayerStateChangeCallback which will be
72  * 					notified when the state of the player changes.
73  * @data			Data for the state_callback
74  * @error_handler	An optional #MediaPlayerErrorHandler which will be notified
75  * 					if an error occurs.
76  * @error_data		Data for the error_handler.
77  */
78 
79 MediaPlayer *
80 media_player_new (const gchar *uri, gboolean loop,
81 				  MediaPlayerStateChangeCallback state_callback, gpointer data,
82 				  MediaPlayerErrorHandler error_handler, gpointer error_data);
83 
84 /**
85  * Free a media player.
86  */
87 void
88 media_player_free (MediaPlayer *player);
89 
90 /**
91  * Set the uri of player.
92  */
93 void
94 media_player_set_uri (MediaPlayer *player, const gchar *uri);
95 
96 /**
97  * Get the uri of player.
98  *
99  * Free with g_free()
100  */
101 gchar *
102 media_player_get_uri (MediaPlayer *player);
103 
104 /**
105  * Set media player state.
106  */
107 void
108 media_player_set_state (MediaPlayer *player, MediaPlayerState state);
109 
110 /**
111  * Start media player
112  */
113 void
114 media_player_start (MediaPlayer *player);
115 
116 /**
117  * Stop player
118  */
119 void
120 media_player_stop (MediaPlayer *player);
121 
122 G_END_DECLS
123 
124 #endif /*PLAYER_H_*/
125