aboutsummaryrefslogtreecommitdiffstats
path: root/package/fonera-mp3/src/lib/mp3_playtime.c
blob: 89325943ff9b6ec3acc88636f4dd6fefdb60a33b (plain)
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
/*
* FOXMP3 
* Copyright (c) 2006 acmesystems.it - john@acmesystems.it
*
* 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., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
*
* Feedback, Bugs...  info@acmesystems.it
*
*/


#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include "mp3.h"


static MP3_PLAYTIME *mp3_playtime;

void sig_alarm_handler(int sig){
	alarm(1);
	mp3_playtime->playtime++;
	mp3_playtime->playtime_secs++;
	if(mp3_playtime->playtime_secs > 59){
		mp3_playtime->playtime_mins++;
		mp3_playtime->playtime_secs = 0;
	}
	state_generic_event(MP3_EVENT_GENERIC_PLAYTIME, 0, NULL);
};

void mp3_playtime_init(MP3_PLAYTIME *playtime){
	mp3_playtime = playtime;
	signal(SIGALRM, sig_alarm_handler);
};

void mp3_playtime_start(void){
	mp3_playtime->playtime = 0;
	mp3_playtime->playtime_secs = 0;
	mp3_playtime->playtime_mins = 0;
	alarm(1);
	state_generic_event(MP3_EVENT_GENERIC_PLAYTIME, 0, NULL);
};

void mp3_playtime_stop(void){
	alarm(0);
	mp3_playtime->playtime = 0;
	mp3_playtime->playtime_secs = 0;
	mp3_playtime->playtime_mins = 0;
};