Mercurial > audlegacy
annotate src/audacious/playback.c @ 3081:ba2143c1c6f5
unescape url encoded filename where real filename is needed.
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Tue, 17 Jul 2007 00:31:43 +0900 |
parents | 84de3244aeaa |
children | 20830a69b5f5 |
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 | |
2717 | 40 #include "configdb.h" |
2313 | 41 |
2420 | 42 #include "hook.h" |
2313 | 43 #include "input.h" |
44 #include "main.h" | |
45 #include "ui_equalizer.h" | |
46 #include "output.h" | |
47 #include "playlist.h" | |
2420 | 48 #include "ui_main.h" |
2313 | 49 #include "ui_playlist.h" |
50 #include "ui_skinselector.h" | |
3072
84de3244aeaa
replace Playstatus with UiSkinnedPlaystatus
Tomasz Mon <desowin@gmail.com>
parents:
3054
diff
changeset
|
51 #include "ui_skinned_playstatus.h" |
2313 | 52 #include "util.h" |
53 | |
54 #include "playback.h" | |
55 | |
3018
6a9fdd5aee3a
Move timer updates out of the 100hz giant loop.
Daniel Drake <dsd@gentoo.org>
parents:
3001
diff
changeset
|
56 static int song_info_timeout_source = 0; |
2313 | 57 |
58 gint | |
59 playback_get_time(void) | |
60 { | |
2438
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
61 InputPlayback *playback; |
2420 | 62 g_return_val_if_fail(playback_get_playing(), -1); |
2438
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
63 playback = get_current_input_playback(); |
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
64 g_return_val_if_fail(playback, -1); |
2313 | 65 |
2438
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
66 if (playback->plugin->get_time) |
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
67 return playback->plugin->get_time(playback); |
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
68 if (playback->error) |
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
69 return -2; |
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
70 if (!playback->playing || |
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
71 (playback->eof && !playback->output->buffer_playing())) |
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
72 return -1; |
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
73 return playback->output->output_time(); |
2313 | 74 } |
75 | |
76 void | |
77 playback_initiate(void) | |
78 { | |
79 PlaylistEntry *entry = NULL; | |
80 Playlist *playlist = playlist_get_active(); | |
81 | |
2420 | 82 g_return_if_fail(playlist_get_length(playlist) != 0); |
2313 | 83 |
84 if (playback_get_playing()) | |
85 playback_stop(); | |
86 | |
3020 | 87 ui_vis_clear_data(mainwin_vis); |
3054 | 88 ui_svis_clear_data(mainwin_svis); |
2313 | 89 mainwin_disable_seekbar(); |
90 | |
91 entry = playlist_get_entry_to_play(playlist); | |
2420 | 92 g_return_if_fail(entry != NULL); |
2592
6f7be3702c5f
[svn] - revert the penalty-based "find something to play" logic of 1.2. it's
nenolod
parents:
2454
diff
changeset
|
93 playback_play_file(entry); |
2313 | 94 |
95 if (playback_get_time() != -1) { | |
96 equalizerwin_load_auto_preset(entry->filename); | |
97 input_set_eq(cfg.equalizer_active, cfg.equalizer_preamp, | |
98 cfg.equalizer_bands); | |
99 output_set_eq(cfg.equalizer_active, cfg.equalizer_preamp, | |
100 cfg.equalizer_bands); | |
101 } | |
102 | |
103 playlist_check_pos_current(playlist); | |
104 mainwin_set_info_text(); | |
3018
6a9fdd5aee3a
Move timer updates out of the 100hz giant loop.
Daniel Drake <dsd@gentoo.org>
parents:
3001
diff
changeset
|
105 mainwin_update_song_info(); |
6a9fdd5aee3a
Move timer updates out of the 100hz giant loop.
Daniel Drake <dsd@gentoo.org>
parents:
3001
diff
changeset
|
106 |
6a9fdd5aee3a
Move timer updates out of the 100hz giant loop.
Daniel Drake <dsd@gentoo.org>
parents:
3001
diff
changeset
|
107 /* FIXME: use g_timeout_add_seconds when glib-2.14 is required */ |
6a9fdd5aee3a
Move timer updates out of the 100hz giant loop.
Daniel Drake <dsd@gentoo.org>
parents:
3001
diff
changeset
|
108 song_info_timeout_source = g_timeout_add(1000, |
6a9fdd5aee3a
Move timer updates out of the 100hz giant loop.
Daniel Drake <dsd@gentoo.org>
parents:
3001
diff
changeset
|
109 (GSourceFunc) mainwin_update_song_info, NULL); |
2407
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2366
diff
changeset
|
110 |
3000
bbca1e0e054a
don't call gtk_widget_show/hide from func that's called every now and then
Tomasz Mon <desowin@gmail.com>
parents:
2976
diff
changeset
|
111 if (cfg.player_shaded) { |
bbca1e0e054a
don't call gtk_widget_show/hide from func that's called every now and then
Tomasz Mon <desowin@gmail.com>
parents:
2976
diff
changeset
|
112 gtk_widget_show(mainwin_stime_min); |
bbca1e0e054a
don't call gtk_widget_show/hide from func that's called every now and then
Tomasz Mon <desowin@gmail.com>
parents:
2976
diff
changeset
|
113 gtk_widget_show(mainwin_stime_sec); |
3042
01ae56759d15
mainwin_sposition is now UiSkinnedHorizontalSlider
Tomasz Mon <desowin@gmail.com>
parents:
3041
diff
changeset
|
114 gtk_widget_show(mainwin_sposition); |
3001
6d4b7b739232
fully implement UiSkinnedNumber, number.c no longer needed
Tomasz Mon <desowin@gmail.com>
parents:
3000
diff
changeset
|
115 } else { |
6d4b7b739232
fully implement UiSkinnedNumber, number.c no longer needed
Tomasz Mon <desowin@gmail.com>
parents:
3000
diff
changeset
|
116 gtk_widget_show(mainwin_minus_num); |
6d4b7b739232
fully implement UiSkinnedNumber, number.c no longer needed
Tomasz Mon <desowin@gmail.com>
parents:
3000
diff
changeset
|
117 gtk_widget_show(mainwin_10min_num); |
6d4b7b739232
fully implement UiSkinnedNumber, number.c no longer needed
Tomasz Mon <desowin@gmail.com>
parents:
3000
diff
changeset
|
118 gtk_widget_show(mainwin_min_num); |
6d4b7b739232
fully implement UiSkinnedNumber, number.c no longer needed
Tomasz Mon <desowin@gmail.com>
parents:
3000
diff
changeset
|
119 gtk_widget_show(mainwin_10sec_num); |
6d4b7b739232
fully implement UiSkinnedNumber, number.c no longer needed
Tomasz Mon <desowin@gmail.com>
parents:
3000
diff
changeset
|
120 gtk_widget_show(mainwin_sec_num); |
3040
067e0186623a
import UiSkinnedHorizontalSlider
Tomasz Mon <desowin@gmail.com>
parents:
3021
diff
changeset
|
121 gtk_widget_show(mainwin_position); |
3000
bbca1e0e054a
don't call gtk_widget_show/hide from func that's called every now and then
Tomasz Mon <desowin@gmail.com>
parents:
2976
diff
changeset
|
122 } |
bbca1e0e054a
don't call gtk_widget_show/hide from func that's called every now and then
Tomasz Mon <desowin@gmail.com>
parents:
2976
diff
changeset
|
123 |
2407
1dc1d36d0347
[svn] - add hooks: playback begin, playback end, playlist reached end
nenolod
parents:
2366
diff
changeset
|
124 hook_call("playback begin", entry); |
2313 | 125 } |
126 | |
127 void | |
128 playback_pause(void) | |
129 { | |
130 if (!playback_get_playing()) | |
131 return; | |
132 | |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
133 if (!get_current_input_playback()) |
2313 | 134 return; |
135 | |
136 ip_data.paused = !ip_data.paused; | |
137 | |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
138 if (get_current_input_playback()->plugin->pause) |
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
139 get_current_input_playback()->plugin->pause(get_current_input_playback(), |
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
140 ip_data.paused); |
2313 | 141 |
3039
c981df78db8c
added hooks: playback pause and playback unpause
Giacomo Lozito <james@develia.org>
parents:
3021
diff
changeset
|
142 if (ip_data.paused) |
c981df78db8c
added hooks: playback pause and playback unpause
Giacomo Lozito <james@develia.org>
parents:
3021
diff
changeset
|
143 hook_call("playback pause", NULL); |
c981df78db8c
added hooks: playback pause and playback unpause
Giacomo Lozito <james@develia.org>
parents:
3021
diff
changeset
|
144 else |
c981df78db8c
added hooks: playback pause and playback unpause
Giacomo Lozito <james@develia.org>
parents:
3021
diff
changeset
|
145 hook_call("playback unpause", NULL); |
c981df78db8c
added hooks: playback pause and playback unpause
Giacomo Lozito <james@develia.org>
parents:
3021
diff
changeset
|
146 |
2313 | 147 g_return_if_fail(mainwin_playstatus != NULL); |
148 | |
149 if (ip_data.paused) | |
3072
84de3244aeaa
replace Playstatus with UiSkinnedPlaystatus
Tomasz Mon <desowin@gmail.com>
parents:
3054
diff
changeset
|
150 ui_skinned_playstatus_set_status(mainwin_playstatus, STATUS_PAUSE); |
2313 | 151 else |
3072
84de3244aeaa
replace Playstatus with UiSkinnedPlaystatus
Tomasz Mon <desowin@gmail.com>
parents:
3054
diff
changeset
|
152 ui_skinned_playstatus_set_status(mainwin_playstatus, STATUS_PLAY); |
2313 | 153 } |
154 | |
155 void | |
156 playback_stop(void) | |
157 { | |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
158 if (ip_data.playing && get_current_input_playback()) { |
2313 | 159 |
160 if (playback_get_paused()) { | |
161 output_flush(get_written_time()); /* to avoid noise */ | |
162 playback_pause(); | |
163 } | |
164 | |
165 ip_data.playing = FALSE; | |
166 | |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
167 if (get_current_input_playback()->plugin->stop) |
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
168 get_current_input_playback()->plugin->stop(get_current_input_playback()); |
2313 | 169 |
170 free_vis_data(); | |
171 ip_data.paused = FALSE; | |
172 | |
173 if (input_info_text) { | |
174 g_free(input_info_text); | |
175 input_info_text = NULL; | |
176 mainwin_set_info_text(); | |
177 } | |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
178 |
2438
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
179 g_free(get_current_input_playback()->filename); |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
180 g_free(get_current_input_playback()); |
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
181 set_current_input_playback(NULL); |
2313 | 182 } |
183 | |
184 ip_data.buffering = FALSE; | |
185 ip_data.playing = FALSE; | |
3018
6a9fdd5aee3a
Move timer updates out of the 100hz giant loop.
Daniel Drake <dsd@gentoo.org>
parents:
3001
diff
changeset
|
186 |
6a9fdd5aee3a
Move timer updates out of the 100hz giant loop.
Daniel Drake <dsd@gentoo.org>
parents:
3001
diff
changeset
|
187 if (song_info_timeout_source) |
6a9fdd5aee3a
Move timer updates out of the 100hz giant loop.
Daniel Drake <dsd@gentoo.org>
parents:
3001
diff
changeset
|
188 g_source_remove(song_info_timeout_source); |
6a9fdd5aee3a
Move timer updates out of the 100hz giant loop.
Daniel Drake <dsd@gentoo.org>
parents:
3001
diff
changeset
|
189 |
2313 | 190 g_return_if_fail(mainwin_playstatus != NULL); |
3072
84de3244aeaa
replace Playstatus with UiSkinnedPlaystatus
Tomasz Mon <desowin@gmail.com>
parents:
3054
diff
changeset
|
191 ui_skinned_playstatus_set_buffering(mainwin_playstatus, FALSE); |
2313 | 192 } |
193 | |
194 static void | |
195 run_no_output_plugin_dialog(void) | |
196 { | |
197 const gchar *markup = | |
198 N_("<b><big>No output plugin selected.</big></b>\n" | |
199 "You have not selected an output plugin."); | |
200 | |
201 GtkWidget *dialog = | |
202 gtk_message_dialog_new_with_markup(GTK_WINDOW(mainwin), | |
203 GTK_DIALOG_DESTROY_WITH_PARENT, | |
204 GTK_MESSAGE_ERROR, | |
205 GTK_BUTTONS_OK, | |
206 _(markup)); | |
207 gtk_dialog_run(GTK_DIALOG(dialog)); | |
208 gtk_widget_destroy(dialog); | |
209 } | |
210 | |
211 gboolean | |
212 playback_play_file(PlaylistEntry *entry) | |
213 { | |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
214 InputPlayback * playback; |
2313 | 215 g_return_val_if_fail(entry != NULL, FALSE); |
216 | |
217 if (!get_current_output_plugin()) { | |
218 run_no_output_plugin_dialog(); | |
219 mainwin_stop_pushed(); | |
220 return FALSE; | |
221 } | |
222 | |
223 if (cfg.random_skin_on_play) | |
2443
93686e8815a4
[svn] - Changed playback_set_random_skin() to skin_set_random_skin()
mf0102
parents:
2438
diff
changeset
|
224 skin_set_random_skin(); |
2313 | 225 |
226 /* | |
227 * This is slightly uglier than the original version, but should | |
228 * fix the "crash" issues as seen in 0.2 when dealing with this situation. | |
229 * - nenolod | |
230 */ | |
231 if (!entry->decoder && | |
2420 | 232 (((entry->decoder = input_check_file(entry->filename, FALSE)) == NULL) || |
2313 | 233 !input_is_enabled(entry->decoder->filename))) |
234 { | |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
235 set_current_input_playback(NULL); |
2313 | 236 mainwin_set_info_text(); |
237 | |
238 return FALSE; | |
239 } | |
240 | |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
241 playback = g_new0(InputPlayback, 1); |
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
242 |
2313 | 243 entry->decoder->output = &psuedo_output_plugin; |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
244 |
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
245 playback->plugin = entry->decoder; |
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
246 playback->output = &psuedo_output_plugin; |
2438
8750a62abed8
[svn] Provide flags in InputPlayback for common plugin flag needs, and provide a
iabervon
parents:
2436
diff
changeset
|
247 playback->filename = g_strdup(entry->filename); |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
248 |
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
249 set_current_input_playback(playback); |
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
250 |
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
251 entry->decoder->play_file(playback); |
2313 | 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 | |
2420 | 276 g_return_if_fail(ip_data.playing); |
2436
f346d30bf5ab
[svn] Change the input plugin API to use a struct for the currently-playing file.
iabervon
parents:
2420
diff
changeset
|
277 g_return_if_fail(get_current_input_playback()); |
2313 | 278 |
279 /* FIXME WORKAROUND...that should work with all plugins | |
280 * mute the volume, start playback again, do the seek, then pause again | |
281 * -Patrick Sudowe | |
282 */ | |
2420 | 283 if (ip_data.paused) |
2313 | 284 { |
2420 | 285 restore_pause = TRUE; |
286 output_get_volume(&l, &r); | |
287 output_set_volume(0,0); | |
288 playback_pause(); | |
2313 | 289 } |
290 | |
291 free_vis_data(); | |
2454 | 292 get_current_input_playback()->plugin->seek(get_current_input_playback(), time); |
2313 | 293 |
2420 | 294 if (restore_pause) |
2313 | 295 { |
2420 | 296 playback_pause(); |
297 output_set_volume(l, r); | |
2313 | 298 } |
299 } | |
300 | |
301 void | |
302 playback_seek_relative(gint offset) | |
303 { | |
304 gint time = CLAMP(playback_get_time() / 1000 + offset, | |
305 0, playlist_get_current_length(playlist_get_active()) / 1000 - 1); | |
306 playback_seek(time); | |
307 } |