-
Notifications
You must be signed in to change notification settings - Fork 0
/
Song.c
73 lines (71 loc) · 2.82 KB
/
Song.c
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
/*
Author: Reyes Vilchis Juan Jose
Fecha: 10/12/2017
Licencia:
This file is part of ReproductorMusica.
ReproductorMusica 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 3 of the License, or
(at your option) any later version.
Foobar 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 Foobar. If not, see <http://www.gnu.org/licenses/>.*/
#include "Song.h"
#include <stdio.h>
/*La funcion "create_song recibe de parametro una ruta al a cual accedera VLC
para poder crear el mediaplayer y entonces reproducir la cancion"*/
Song* create_song(char* ruta){
Song* s = (Song*)malloc(sizeof(Song));
s->instance = libvlc_new(0,NULL);
s->mediaPlayer = libvlc_media_player_new(s->instance);
s->media = libvlc_media_new_location(s->instance,ruta);
//Regresa apuntador a cancion
return s;
}
/*Open media solo se hará cada que se reproduzca una nueva cancion,
en esta funcion se reproduce se establece el mediaplayer a reproducir y se reproduce.*/
void open_media(Song* s) {
libvlc_media_player_set_media(s->mediaPlayer,s->media);
libvlc_media_parse(s->media);
play_song(s);
}
//"Play_song" recibe de parametros un apuntador a "Song" y la reproduce, primero se debe usar la funcion open media
void play_song(Song* s){
libvlc_media_player_play(s->mediaPlayer);
}
//"pause_song" pausa una cancion, recibe de parametro apuntador a "Song", no olvidar usar antes open_media
void pause_song(Song* s){
libvlc_media_player_pause(s->mediaPlayer);
}
//"stop_song" detiene totalmente la cancion.
void stop_song(Song* s){
libvlc_media_player_stop(s->mediaPlayer);
}
//on_playpause sirve para pausar o detener una cancion,
void on_playpause(Song* s) {
if(libvlc_media_player_is_playing(s->mediaPlayer) == 1) {//Si se esta reproduciendo
pause_song(s);//Pausa la cancion
}
else {//Si no se esta reproduciendo
if(libvlc_media_player_get_length(s->mediaPlayer)==-1){//Si el tamaño del player es -1 significa que no hay media agregada
open_media(s);//Agregamos y reproducimos
}
else{
play_song(s);//Si ya hay media agregada, solo reproducimos
}
}
}
int delete_song(Song **s){
if(*s==0){//Si el apuntador a cancion es 0, devolvemos un error
return -1;
}//en caso contrarios liberamos la memoria
libvlc_media_release((*s)->media);
libvlc_media_player_release((*s)->mediaPlayer);
libvlc_release((*s)->instance);
free(*s);
*s = 0;//El apuntador a cancion ahora será 0
return 0;
}