-
Notifications
You must be signed in to change notification settings - Fork 0
/
play.c
126 lines (108 loc) · 2.38 KB
/
play.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* See LICENSE file for copyright and license details. */
#include "play.h"
void
play_exit(struct info *data)
{
libvlc_media_player_release(data->vlc_mp);
libvlc_release(data->vlc_inst);
}
int
play_init(struct info *data)
{
data->vlc_inst = libvlc_new(0, NULL);
if (data->vlc_inst == NULL)
goto error;
data->vlc_mp = libvlc_media_player_new(data->vlc_inst);
if (data->vlc_mp == NULL)
goto error;
/* Prevent VLC from printing errors to the console by directing stderr
* to /dev/null. These error messages mess up the ncurses window.
*/
(void)freopen("/dev/null", "wb", stderr);
return SUCCESS;
error:
if (data->vlc_inst)
libvlc_release(data->vlc_inst);
return ERROR;
}
void
play_next(struct info *data)
{
char errormsg[] = "Next mix not found.";
int errn;
struct track *t;
libvlc_media_t *media;
/* Check if we are already on the last track.
* If so request a similar mix and continue playing.
*/
if (data->m->track_count > 0) {
if (data->m->track[data->m->track_count-1]->last == TRUE) {
errn = search_nextmix(data);
if (errn == ERROR) {
draw_error(errormsg);
data->state = START;
return;
}
}
}
t = mix_nexttrack(data);
if (t == NULL)
return;
media = libvlc_media_new_location(data->vlc_inst, t->url);
if (media == NULL)
return;
libvlc_media_player_set_media(data->vlc_mp, media);
(void)libvlc_media_player_play(data->vlc_mp);
libvlc_media_release(media);
}
void
play_nextmix(struct info *data)
{
char errormsg[] = "Next mix not found.";
int errn;
errn = search_nextmix(data);
if (errn == ERROR) {
draw_error(errormsg);
data->state = START;
return;
}
data->scroll = 0;
play_next(data);
}
void
play_skip(struct info *data)
{
char errormsg[] = "Skip not allowed.";
struct track *t;
t = data->m->track[data->m->track_count-1];
if (t == NULL)
return;
if (t->skip_allowed == TRUE && t->last == FALSE) {
play_next(data);
} else
draw_error(errormsg);
}
int
play_isoverthirtymark(struct info *data)
{
if (libvlc_media_player_get_time(data->vlc_mp) >= (30 * 1000))
return TRUE;
else
return FALSE;
}
int
play_ended(struct info *data)
{
/* VLC states: IDLE/CLOSE=0, OPENING=1, BUFFERING=2, PLAYING=3,
* PAUSE=4, STOPPING=5, ENDED=6, ERROR=7
*/
if (libvlc_media_player_get_state(data->vlc_mp) >= 6)
return TRUE;
else
return FALSE;
}
void
play_togglepause(struct info *data)
{
libvlc_media_player_pause(data->vlc_mp);
}