Mercurial > audlegacy
annotate src/audacious/playback.c @ 2407:1dc1d36d0347 trunk
[svn] - add hooks: playback begin, playback end, playlist reached end
author | nenolod |
---|---|
date | Thu, 25 Jan 2007 21:29:51 -0800 |
parents | 0358eb5783e6 |
children | 0fd7f4f969ad |
rev | line source |
---|---|
2313 | 1 /* Audacious - Cross-platform multimedia player |
2 * Copyright (C) 2005-2007 Audacious development team | |
3 * | |
4 * Based on BMP: | |
5 * Copyright (C) 2003-2004 BMP development team. | |
6 * | |
7 * Based on XMMS: | |
8 * Copyright (C) 1998-2003 XMMS development team. | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; under version 2 of the License. | |
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. See the | |
17 * 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, write to the Free Software | |
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 # include "config.h" | |
26 #endif | |
27 | |
28 #include <glib.h> | |
29 #include <glib/gi18n.h> | |
30 #include <glib/gprintf.h> | |
31 #include <stdlib.h> | |
32 #include <string.h> | |
33 #include <time.h> | |
34 | |
35 #include <unistd.h> | |
36 #include <sys/types.h> | |
37 #include <sys/stat.h> | |
38 #include <dirent.h> | |
39 | |
40 #include "libaudacious/util.h" | |
41 #include "libaudacious/configdb.h" | |
42 | |
43 #include "input.h" | |
44 #include "main.h" | |
45 #include "ui_main.h" | |
46 #include "ui_equalizer.h" | |
47 #include "output.h" | |
48 #include "playlist.h" | |
49 #include "ui_playlist.h" | |
50 #include "ui_skinselector.h" | |
51 #include "libaudacious/urldecode.h" | |
52 #include "util.h" | |
53 | |
54 #include "playback.h" | |
55 | |
2407
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2366
diff
changeset
|
56 #include "hook.h" |
2313 | 57 |
58 /* FIXME: yuck!! this shouldn't be here... */ | |
59 void | |
60 playback_set_random_skin(void) | |
61 { | |
62 SkinNode *node; | |
63 guint32 randval; | |
64 | |
65 /* Get a random value to select the skin to use */ | |
66 randval = g_random_int_range(0, g_list_length(skinlist)); | |
67 node = g_list_nth(skinlist, randval)->data; | |
68 bmp_active_skin_load(node->path); | |
69 } | |
70 | |
71 gint | |
72 playback_get_time(void) | |
73 { | |
74 if (!playback_get_playing()) | |
75 return -1; | |
76 | |
77 if (!get_current_input_plugin()) | |
78 return -1; | |
79 | |
80 return get_current_input_plugin()->get_time(); | |
81 } | |
82 | |
83 void | |
84 playback_initiate(void) | |
85 { | |
86 PlaylistEntry *entry = NULL; | |
87 Playlist *playlist = playlist_get_active(); | |
88 gint penalty = 0; | |
89 | |
90 if (playlist_get_length(playlist) == 0) | |
91 return; | |
92 | |
93 if (playback_get_playing()) | |
94 playback_stop(); | |
95 | |
96 vis_clear_data(mainwin_vis); | |
97 svis_clear_data(mainwin_svis); | |
98 mainwin_disable_seekbar(); | |
99 | |
100 entry = playlist_get_entry_to_play(playlist); | |
101 | |
102 if (entry == NULL) | |
103 return; | |
104 | |
105 /* | |
106 * If the playlist entry cannot be played, try to pick another one. | |
107 * If that does not work, e.g. entry == NULL, then bail. | |
108 * | |
109 * - nenolod | |
110 */ | |
111 for ( penalty=0 ; penalty <= 15 && entry != NULL && !playback_play_file(entry) ; penalty++ ) | |
112 { | |
113 playlist_next(playlist); | |
114 | |
115 entry = playlist_get_entry_to_play(playlist); | |
116 | |
117 /* XXX ew. workaround for a stupid bug where audacious will keep | |
118 * trying to play a file with no valid decoder. | |
119 */ | |
120 if (entry == NULL) | |
121 return; | |
122 | |
123 if (entry->decoder == NULL ) | |
124 entry->decoder = input_check_file(entry->filename, FALSE); | |
125 | |
126 /* if we hit 15 entries in a row with no valid decoder, just | |
127 * bail due to confusion | |
128 */ | |
129 if (penalty == 15) | |
130 return; | |
131 } | |
132 | |
133 if (playback_get_time() != -1) { | |
134 equalizerwin_load_auto_preset(entry->filename); | |
135 input_set_eq(cfg.equalizer_active, cfg.equalizer_preamp, | |
136 cfg.equalizer_bands); | |
137 output_set_eq(cfg.equalizer_active, cfg.equalizer_preamp, | |
138 cfg.equalizer_bands); | |
139 } | |
140 | |
141 playlist_check_pos_current(playlist); | |
142 mainwin_set_info_text(); | |
2407
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2366
diff
changeset
|
143 |
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2366
diff
changeset
|
144 hook_call("playback begin", entry); |
2313 | 145 } |
146 | |
147 void | |
148 playback_pause(void) | |
149 { | |
150 if (!playback_get_playing()) | |
151 return; | |
152 | |
153 if (!get_current_input_plugin()) | |
154 return; | |
155 | |
156 ip_data.paused = !ip_data.paused; | |
157 | |
158 if (get_current_input_plugin()->pause) | |
159 get_current_input_plugin()->pause(ip_data.paused); | |
160 | |
161 g_return_if_fail(mainwin_playstatus != NULL); | |
162 | |
163 if (ip_data.paused) | |
164 playstatus_set_status(mainwin_playstatus, STATUS_PAUSE); | |
165 else | |
166 playstatus_set_status(mainwin_playstatus, STATUS_PLAY); | |
167 } | |
168 | |
169 void | |
170 playback_stop(void) | |
171 { | |
172 if (ip_data.playing && get_current_input_plugin()) { | |
173 | |
174 if (playback_get_paused()) { | |
175 output_flush(get_written_time()); /* to avoid noise */ | |
176 playback_pause(); | |
177 } | |
178 | |
179 ip_data.playing = FALSE; | |
180 | |
181 if (get_current_input_plugin()->stop) | |
182 get_current_input_plugin()->stop(); | |
183 | |
184 free_vis_data(); | |
185 ip_data.paused = FALSE; | |
186 | |
187 if (input_info_text) { | |
188 g_free(input_info_text); | |
189 input_info_text = NULL; | |
190 mainwin_set_info_text(); | |
191 } | |
192 } | |
193 | |
194 ip_data.buffering = FALSE; | |
195 ip_data.playing = FALSE; | |
196 | |
197 g_return_if_fail(mainwin_playstatus != NULL); | |
198 playstatus_set_status_buffering(mainwin_playstatus, FALSE); | |
199 } | |
200 | |
201 static void | |
202 run_no_output_plugin_dialog(void) | |
203 { | |
204 const gchar *markup = | |
205 N_("<b><big>No output plugin selected.</big></b>\n" | |
206 "You have not selected an output plugin."); | |
207 | |
208 GtkWidget *dialog = | |
209 gtk_message_dialog_new_with_markup(GTK_WINDOW(mainwin), | |
210 GTK_DIALOG_DESTROY_WITH_PARENT, | |
211 GTK_MESSAGE_ERROR, | |
212 GTK_BUTTONS_OK, | |
213 _(markup)); | |
214 gtk_dialog_run(GTK_DIALOG(dialog)); | |
215 gtk_widget_destroy(dialog); | |
216 } | |
217 | |
218 gboolean | |
219 playback_play_file(PlaylistEntry *entry) | |
220 { | |
221 g_return_val_if_fail(entry != NULL, FALSE); | |
222 | |
223 if (!get_current_output_plugin()) { | |
224 run_no_output_plugin_dialog(); | |
225 mainwin_stop_pushed(); | |
226 return FALSE; | |
227 } | |
228 | |
229 if (cfg.random_skin_on_play) | |
230 playback_set_random_skin(); | |
231 | |
232 /* | |
233 * This is slightly uglier than the original version, but should | |
234 * fix the "crash" issues as seen in 0.2 when dealing with this situation. | |
235 * - nenolod | |
236 */ | |
237 if (!entry->decoder && | |
238 (((entry->decoder = input_check_file(entry->filename, FALSE)) == NULL) || | |
239 !input_is_enabled(entry->decoder->filename))) | |
240 { | |
241 input_file_not_playable(entry->filename); | |
242 | |
243 set_current_input_plugin(NULL); | |
244 mainwin_set_info_text(); | |
245 | |
246 return FALSE; | |
247 } | |
248 | |
249 set_current_input_plugin(entry->decoder); | |
250 entry->decoder->output = &psuedo_output_plugin; | |
251 entry->decoder->play_file(entry->filename); | |
252 | |
253 ip_data.playing = TRUE; | |
254 | |
255 return TRUE; | |
256 } | |
257 | |
258 gboolean | |
259 playback_get_playing(void) | |
260 { | |
261 return ip_data.playing; | |
262 } | |
263 | |
264 gboolean | |
265 playback_get_paused(void) | |
266 { | |
267 return ip_data.paused; | |
268 } | |
269 | |
270 void | |
271 playback_seek(gint time) | |
272 { | |
273 gboolean restore_pause = FALSE; | |
274 gint l=0, r=0; | |
275 | |
276 if (!ip_data.playing) | |
277 return; | |
278 | |
279 if (!get_current_input_plugin()) | |
280 return; | |
281 | |
282 /* FIXME WORKAROUND...that should work with all plugins | |
283 * mute the volume, start playback again, do the seek, then pause again | |
284 * -Patrick Sudowe | |
285 */ | |
286 if(ip_data.paused) | |
287 { | |
288 restore_pause = TRUE; | |
289 output_get_volume(&l, &r); | |
290 output_set_volume(0,0); | |
291 playback_pause(); | |
292 } | |
293 | |
294 free_vis_data(); | |
295 get_current_input_plugin()->seek(time); | |
296 | |
297 if(restore_pause) | |
298 { | |
299 playback_pause(); | |
300 output_set_volume(l, r); | |
301 } | |
302 } | |
303 | |
304 void | |
305 playback_seek_relative(gint offset) | |
306 { | |
307 gint time = CLAMP(playback_get_time() / 1000 + offset, | |
308 0, playlist_get_current_length(playlist_get_active()) / 1000 - 1); | |
309 playback_seek(time); | |
310 } |