1 /**********************************************************
2  *
3  * mp3splt-gtk -- utility based on mp3splt,
4  *                for mp3/ogg splitting without decoding
5  *
6  * Copyright: (C) 2005-2014 Alexandru Munteanu
7  * Contact: m@ioalex.net
8  *
9  *
10  * http://mp3splt.sourceforge.net/
11  *
12  *********************************************************/
13 
14 /**********************************************************
15  *
16  * This program is free software; you ca nredistribute it and/or
17  * modify it under the terms of the GNU General Public License
18  * as published by the Free Software Foundation; either version 2
19  * of the License, or (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
29  * USA.
30  *
31  *********************************************************/
32 
33 /*!********************************************************
34  * \file
35  * Functions to access the currently selected player
36  *
37  * this file is used to play for the appropriate player,
38  * for example if we choose snackamp, the player will use
39  * snackamp
40  **********************************************************/
41 
42 #include "player_control.h"
43 
44 //!returns the elapsed time of the player
player_get_elapsed_time(ui_state * ui)45 gint player_get_elapsed_time(ui_state *ui)
46 {
47   if (ui->infos->selected_player == PLAYER_SNACKAMP)
48   {
49     return snackamp_get_time_elapsed(ui);
50   }
51   else if (ui->infos->selected_player == PLAYER_AUDACIOUS)
52   {
53 #ifndef __WIN32__
54 #ifndef NO_AUDACIOUS
55     return myaudacious_get_time_elapsed(ui);
56 #endif
57 #endif
58   }
59   else
60   {
61 #ifndef NO_GSTREAMER
62     return gstreamer_get_time_elapsed(ui);
63 #endif
64   }
65 
66   return 0;
67 }
68 
69 //!returns total time of the song
player_get_total_time(ui_state * ui)70 gint player_get_total_time(ui_state *ui)
71 {
72   if (ui->infos->selected_player == PLAYER_SNACKAMP)
73   {
74     return snackamp_get_total_time(ui);
75   }
76   else if (ui->infos->selected_player == PLAYER_AUDACIOUS)
77   {
78 #ifndef __WIN32__
79 #ifndef NO_AUDACIOUS
80     return myaudacious_get_total_time(ui);
81 #endif
82 #endif
83   }
84   else
85   {
86 #ifndef NO_GSTREAMER
87     return gstreamer_get_total_time(ui);
88 #endif
89   }
90 
91   return 0;
92 }
93 
94 //!returns FALSE if the player is not running, else TRUE
player_is_running(ui_state * ui)95 gint player_is_running(ui_state *ui)
96 {
97   if (ui->infos->selected_player == PLAYER_SNACKAMP)
98   {
99     return snackamp_is_running(ui);
100   }
101   else if (ui->infos->selected_player == PLAYER_AUDACIOUS)
102   {
103 #ifndef __WIN32__
104 #ifndef NO_AUDACIOUS
105     return myaudacious_is_running(ui);
106 #endif
107 #endif
108   }
109   else
110   {
111 #ifndef NO_GSTREAMER
112     return gstreamer_is_running(ui);
113 #endif
114   }
115 
116   return 0;
117 }
118 
119 //!starts the player
player_start(ui_state * ui)120 void player_start(ui_state *ui)
121 {
122   if (ui->infos->selected_player == PLAYER_SNACKAMP)
123   {
124     snackamp_start(ui);
125   }
126   else if (ui->infos->selected_player == PLAYER_AUDACIOUS)
127   {
128 #ifndef __WIN32__
129 #ifndef NO_AUDACIOUS
130     myaudacious_start(ui);
131 #endif
132 #endif
133   }
134   else
135   {
136 #ifndef NO_GSTREAMER
137     gstreamer_start(ui);
138 #endif
139   }
140 }
141 
142 //!start player and add files to playlist
player_start_add_files(GList * list,ui_state * ui)143 void player_start_add_files(GList *list, ui_state *ui)
144 {
145   if (ui->infos->selected_player == PLAYER_SNACKAMP)
146   {
147     snackamp_start_with_songs(list, ui);
148   }
149   else if (ui->infos->selected_player == PLAYER_AUDACIOUS)
150   {
151 #ifndef __WIN32__
152 #ifndef NO_AUDACIOUS
153     myaudacious_start_with_songs(list, ui);
154 #endif
155 #endif
156   }
157   else
158   {
159 #ifndef NO_GSTREAMER
160     gstreamer_start_with_songs(list, ui);
161 #endif
162   }
163 }
164 
165 //!add files to playlist
player_add_files(GList * list,ui_state * ui)166 void player_add_files(GList *list, ui_state *ui)
167 {
168   if (ui->infos->selected_player == PLAYER_SNACKAMP)
169   {
170     snackamp_add_files(list, ui);
171   }
172   else if (ui->infos->selected_player == PLAYER_AUDACIOUS)
173   {
174 #ifndef __WIN32__
175 #ifndef NO_AUDACIOUS
176     myaudacious_add_files(list, ui);
177 #endif
178 #endif
179   }
180   else
181   {
182 #ifndef NO_GSTREAMER
183     gstreamer_add_files(list, ui);
184 #endif
185   }
186 }
187 
188 //!add files to playlist
player_add_files_and_select(GList * list,ui_state * ui)189 void player_add_files_and_select(GList *list, ui_state *ui)
190 {
191   if (ui->infos->selected_player == PLAYER_SNACKAMP)
192   {
193     snackamp_add_files(list, ui);
194     snackamp_select_last_file(ui);
195   }
196   else if (ui->infos->selected_player == PLAYER_AUDACIOUS)
197   {
198 #ifndef __WIN32__
199 #ifndef NO_AUDACIOUS
200     myaudacious_add_files(list, ui);
201     myaudacious_select_last_file(ui);
202 #endif
203 #endif
204   }
205   else
206   {
207 #ifndef NO_GSTREAMER
208     gstreamer_add_files(list, ui);
209     gstreamer_select_last_file(ui);
210 #endif
211   }
212 }
213 
214 //!add files to playlist
player_add_play_files(GList * list,ui_state * ui)215 void player_add_play_files(GList *list, ui_state *ui)
216 {
217   player_add_files(list, ui);
218 
219   if (ui->infos->selected_player == PLAYER_SNACKAMP)
220   {
221     snackamp_next(ui);
222   }
223   else if (ui->infos->selected_player == PLAYER_AUDACIOUS)
224   {
225 #ifndef __WIN32__
226 #ifndef NO_AUDACIOUS
227     myaudacious_play_last_file(ui);
228 #endif
229 #endif
230   }
231   else
232   {
233 #ifndef NO_GSTREAMER
234     gstreamer_play_last_file(ui);
235 #endif
236   }
237 }
238 
239 //!starts the player
player_start_play_with_songs(GList * list,ui_state * ui)240 void player_start_play_with_songs(GList *list, ui_state *ui)
241 {
242   if (ui->infos->selected_player == PLAYER_SNACKAMP)
243   {
244     snackamp_start_with_songs(list, ui);
245     snackamp_play_last_file(ui);
246   }
247   else if (ui->infos->selected_player == PLAYER_AUDACIOUS)
248   {
249 #ifndef __WIN32__
250 #ifndef NO_AUDACIOUS
251     myaudacious_start_with_songs(list, ui);
252     myaudacious_play_last_file(ui);
253 #endif
254 #endif
255   }
256   else
257   {
258 #ifndef NO_GSTREAMER
259     gstreamer_start_with_songs(list, ui);
260     gstreamer_play_last_file(ui);
261 #endif
262   }
263 }
264 
265 //!plays the song
player_play(ui_state * ui)266 void player_play(ui_state *ui)
267 {
268   if (ui->infos->selected_player == PLAYER_SNACKAMP)
269   {
270     snackamp_play(ui);
271   }
272   else if (ui->infos->selected_player == PLAYER_AUDACIOUS)
273   {
274 #ifndef __WIN32__
275 #ifndef NO_AUDACIOUS
276     myaudacious_play(ui);
277 #endif
278 #endif
279   }
280   else
281   {
282 #ifndef NO_GSTREAMER
283     gstreamer_play(ui);
284 #endif
285   }
286 }
287 
288 //!stops the song
player_stop(ui_state * ui)289 void player_stop(ui_state *ui)
290 {
291   if (ui->infos->selected_player == PLAYER_SNACKAMP)
292   {
293     snackamp_stop(ui);
294   }
295   else if (ui->infos->selected_player == PLAYER_AUDACIOUS)
296   {
297 #ifndef __WIN32__
298 #ifndef NO_AUDACIOUS
299     myaudacious_stop(ui);
300 #endif
301 #endif
302   }
303   else
304   {
305 #ifndef NO_GSTREAMER
306     gstreamer_stop(ui);
307 #endif
308   }
309 }
310 
311 //!pause the song
player_pause(ui_state * ui)312 void player_pause(ui_state *ui)
313 {
314   if (ui->infos->selected_player == PLAYER_SNACKAMP)
315   {
316     snackamp_pause(ui);
317   }
318   else if (ui->infos->selected_player == PLAYER_AUDACIOUS)
319   {
320 #ifndef __WIN32__
321 #ifndef NO_AUDACIOUS
322     myaudacious_pause(ui);
323 #endif
324 #endif
325   }
326   else
327   {
328 #ifndef NO_GSTREAMER
329     gstreamer_pause(ui);
330 #endif
331   }
332 }
333 
334 //!pass to the next song
player_next(ui_state * ui)335 void player_next(ui_state *ui)
336 {
337   if (ui->infos->selected_player == PLAYER_SNACKAMP)
338   {
339     snackamp_next(ui);
340   }
341   else if (ui->infos->selected_player == PLAYER_AUDACIOUS)
342   {
343 #ifndef __WIN32__
344 #ifndef NO_AUDACIOUS
345     myaudacious_next(ui);
346 #endif
347 #endif
348   }
349   else
350   {
351 #ifndef NO_GSTREAMER
352     gstreamer_next(ui);
353 #endif
354   }
355 }
356 
357 //!pass to the previous song
player_prev(ui_state * ui)358 void player_prev(ui_state *ui)
359 {
360   if (ui->infos->selected_player == PLAYER_SNACKAMP)
361   {
362     snackamp_prev(ui);
363   }
364   else if (ui->infos->selected_player == PLAYER_AUDACIOUS)
365   {
366 #ifndef __WIN32__
367 #ifndef NO_AUDACIOUS
368     myaudacious_prev(ui);
369 #endif
370 #endif
371   }
372   else
373   {
374 #ifndef NO_GSTREAMER
375     gstreamer_prev(ui);
376 #endif
377   }
378 }
379 
380 //!jumps to a position in the song
player_seek(gint position,ui_state * ui)381 void player_seek(gint position, ui_state *ui)
382 {
383   clear_previous_distances(ui);
384 
385   if (ui->infos->selected_player == PLAYER_SNACKAMP)
386   {
387     snackamp_jump(position, ui);
388   }
389   else if (ui->infos->selected_player == PLAYER_AUDACIOUS)
390   {
391 #ifndef __WIN32__
392 #ifndef NO_AUDACIOUS
393     myaudacious_jump(position, ui);
394 #endif
395 #endif
396   }
397   else
398   {
399 #ifndef NO_GSTREAMER
400     gstreamer_jump(position, ui);
401 #endif
402   }
403 }
404 
405 /*!get infos about the song
406 
407 \param total_infos The result of this function call
408 */
player_get_song_infos(gchar * total_infos,ui_state * ui)409 void player_get_song_infos(gchar *total_infos, ui_state *ui)
410 {
411   if (ui->infos->selected_player == PLAYER_SNACKAMP)
412   {
413     snackamp_get_song_infos(total_infos, ui);
414   }
415   else if (ui->infos->selected_player == PLAYER_AUDACIOUS)
416   {
417 #ifndef __WIN32__
418 #ifndef NO_AUDACIOUS
419     myaudacious_get_song_infos(total_infos, ui);
420 #endif
421 #endif
422   }
423   else
424   {
425 #ifndef NO_GSTREAMER
426     gstreamer_get_song_infos(total_infos, ui);
427 #endif
428   }
429 }
430 
431 //!returns TRUE if the player is playing, else FALSE
player_is_playing(ui_state * ui)432 gint player_is_playing(ui_state *ui)
433 {
434   if (ui->infos->selected_player == PLAYER_SNACKAMP)
435   {
436     return snackamp_is_playing(ui);
437   }
438   else if (ui->infos->selected_player == PLAYER_AUDACIOUS)
439   {
440 #ifndef __WIN32__
441 #ifndef NO_AUDACIOUS
442     return myaudacious_is_playing(ui);
443 #endif
444 #endif
445   }
446   else
447   {
448 #ifndef NO_GSTREAMER
449     return gstreamer_is_playing(ui);
450 #endif
451   }
452 
453   return FALSE;
454 }
455 
456 //! Check if the player is paused
player_is_paused(ui_state * ui)457 gint player_is_paused(ui_state *ui)
458 {
459   if (ui->infos->selected_player == PLAYER_SNACKAMP)
460   {
461     return snackamp_is_paused(ui);
462   }
463   else if (ui->infos->selected_player == PLAYER_AUDACIOUS)
464   {
465 #ifndef __WIN32__
466 #ifndef NO_AUDACIOUS
467     return myaudacious_is_paused(ui);
468 #endif
469 #endif
470   }
471   else
472   {
473 #ifndef NO_GSTREAMER
474     return gstreamer_is_paused(ui);
475 #endif
476   }
477 
478   return 0;
479 }
480 
481 /*!gets the filename of the current song
482 
483 The returned string must be g_free'd after use
484 */
player_get_filename(ui_state * ui)485 gchar *player_get_filename(ui_state *ui)
486 {
487   if (ui->infos->selected_player == PLAYER_SNACKAMP)
488   {
489     return snackamp_get_filename(ui);
490   }
491   else if (ui->infos->selected_player == PLAYER_AUDACIOUS)
492   {
493 #ifndef __WIN32__
494 #ifndef NO_AUDACIOUS
495     return myaudacious_get_filename(ui);
496 #endif
497 #endif
498   }
499   else
500   {
501 #ifndef NO_GSTREAMER
502     return gstreamer_get_filename(ui);
503 #endif
504   }
505 
506   return 0;
507 }
508 
509 /*!Get the title of the song
510 
511 The returned string must be g_freed after use
512 */
player_get_title(ui_state * ui)513 gchar *player_get_title(ui_state *ui)
514 {
515   if (ui->infos->selected_player == PLAYER_SNACKAMP)
516   {
517     return snackamp_get_title_song(ui);
518   }
519   else if (ui->infos->selected_player == PLAYER_AUDACIOUS)
520   {
521 #ifndef __WIN32__
522 #ifndef NO_AUDACIOUS
523     return myaudacious_get_title_song(ui);
524 #endif
525 #endif
526   }
527   else
528   {
529 #ifndef NO_GSTREAMER
530     return gstreamer_get_title_song(ui);
531 #endif
532   }
533 
534   return 0;
535 }
536 
537 //!gets the volume of the player
player_get_volume(ui_state * ui)538 gint player_get_volume(ui_state *ui)
539 {
540   if (ui->infos->selected_player == PLAYER_SNACKAMP)
541   {
542     return snackamp_get_volume(ui);
543   }
544   else if (ui->infos->selected_player == PLAYER_AUDACIOUS)
545   {
546 #ifndef __WIN32__
547 #ifndef NO_AUDACIOUS
548     return myaudacious_get_volume(ui);
549 #endif
550 #endif
551   }
552   else
553   {
554 #ifndef NO_GSTREAMER
555     return gstreamer_get_volume(ui);
556 #endif
557   }
558 
559   return 0;
560 }
561 
562 //!sets the volume of the player
player_set_volume(gint volume,ui_state * ui)563 void player_set_volume(gint volume, ui_state *ui)
564 {
565   if (ui->infos->selected_player == PLAYER_SNACKAMP)
566   {
567     snackamp_set_volume(volume, ui);
568   }
569   else if (ui->infos->selected_player == PLAYER_AUDACIOUS)
570   {
571 #ifndef __WIN32__
572 #ifndef NO_AUDACIOUS
573     myaudacious_set_volume(volume, ui);
574 #endif
575 #endif
576   }
577   else
578   {
579 #ifndef NO_GSTREAMER
580     gstreamer_set_volume(volume, ui);
581 #endif
582   }
583 }
584 
585 //!returns the number of songs in the playlist
player_get_playlist_number(ui_state * ui)586 gint player_get_playlist_number(ui_state *ui)
587 {
588   if (ui->infos->selected_player == PLAYER_SNACKAMP)
589   {
590     return snackamp_get_playlist_number(ui);
591   }
592   else if (ui->infos->selected_player == PLAYER_AUDACIOUS)
593   {
594 #ifndef __WIN32__
595 #ifndef NO_AUDACIOUS
596     return myaudacious_get_playlist_number(ui);
597 #endif
598 #endif
599   }
600   else
601   {
602 #ifndef NO_GSTREAMER
603     return gstreamer_get_playlist_number(ui);
604 #endif
605   }
606 
607   return 0;
608 }
609 
610 //!quits the player
player_quit(ui_state * ui)611 gint player_quit(ui_state *ui)
612 {
613   if (ui->infos->selected_player == PLAYER_GSTREAMER)
614   {
615 #ifndef NO_GSTREAMER
616     gstreamer_quit(ui);
617 #endif
618   }
619 
620   return 0;
621 }
622 
623