File: player.h

package info (click to toggle)
alarm-clock-applet 0.3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,720 kB
  • sloc: ansic: 5,121; sh: 1,382; makefile: 189
file content (124 lines) | stat: -rw-r--r-- 3,079 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
 * player.h - Simple media player based on GStreamer
 * 
 * Copyright (C) 2007-2008 Johannes H. Jensen <joh@pseudoberries.com>
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 * 
 * Authors:
 * 		Johannes H. Jensen <joh@pseudoberries.com>
 */

#ifndef PLAYER_H_
#define PLAYER_H_

#include <gst/gst.h>

G_BEGIN_DECLS

typedef enum {
	MEDIA_PLAYER_INVALID = 0,
	MEDIA_PLAYER_STOPPED,
	MEDIA_PLAYER_PLAYING,
	MEDIA_PLAYER_ERROR
} MediaPlayerState;

typedef struct _MediaPlayer MediaPlayer;

/*
 * Callback for when the media player's state changes.
 */
typedef void (*MediaPlayerStateChangeCallback)	(MediaPlayer *player, MediaPlayerState state, gpointer data);

/*
 * Callback for when an error occurs in the media player.
 * The error details is put in the error argument. This value
 * should _never_ be freed in the callback!
 */
typedef void (*MediaPlayerErrorHandler)			(MediaPlayer *player, GError *error, gpointer data);

struct _MediaPlayer {
	GstElement *player;
	gboolean loop;
	MediaPlayerState state;
	
	guint watch_id;
	
	MediaPlayerStateChangeCallback state_changed;
	MediaPlayerErrorHandler error_handler;
	
	gpointer state_changed_data;
	gpointer error_handler_data;
};

/**
 * Create a new media player.
 * 
 * @uri				The file to play.
 * @loop			Wether to loop or not.
 * @state_callback	An optional #MediaPlayerStateChangeCallback which will be
 * 					notified when the state of the player changes.
 * @data			Data for the state_callback
 * @error_handler	An optional #MediaPlayerErrorHandler which will be notified
 * 					if an error occurs.
 * @error_data		Data for the error_handler.
 */

MediaPlayer *
media_player_new (const gchar *uri, gboolean loop,
				  MediaPlayerStateChangeCallback state_callback, gpointer data,
				  MediaPlayerErrorHandler error_handler, gpointer error_data);

/**
 * Free a media player.
 */
void
media_player_free (MediaPlayer *player);

/**
 * Set the uri of player.
 */
void
media_player_set_uri (MediaPlayer *player, const gchar *uri);

/**
 * Get the uri of player.
 * 
 * Free with g_free()
 */
gchar *
media_player_get_uri (MediaPlayer *player);

/**
 * Set media player state.
 */
void
media_player_set_state (MediaPlayer *player, MediaPlayerState state);

/**
 * Start media player
 */
void
media_player_start (MediaPlayer *player);

/**
 * Stop player
 */
void
media_player_stop (MediaPlayer *player);

G_END_DECLS

#endif /*PLAYER_H_*/