-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpgplayer.cpp
139 lines (119 loc) · 2.69 KB
/
mpgplayer.cpp
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
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "mpgplayer.h"
#include "pulse/simple.h"
#include <QFile>
mpgplayer::mpgplayer(QObject *parent) :
QThread(parent)
{
net = TWait;
playing=false;
}
void mpgplayer::run()
{
if(mpg123_init() != MPG123_OK)
qDebug("Error initilizing mpg123");
const char **test = mpg123_supported_decoders();
int error;
mpg123_handle *mh = mpg123_new(test[0],&error);
if(!mpg123_feature(MPG123_FEATURE_DECODE_LAYER3))
{
qDebug("You do not seem to have mp3 decoding support");
return;
}
mpg123_format_none(mh);
if(mpg123_format(mh,samplerate,MPG123_STEREO,MPG123_ENC_SIGNED_16)!=MPG123_OK)
qDebug("Error in initilizing format decoder");
qDebug(test[0]);
mpg123_open(mh,"/home/eli/Projects/groove-evan/Animal.mp3");
net = TData;
pa_simple *s;
pa_sample_spec ss;
ss.format = PA_SAMPLE_S16NE;
ss.rate = samplerate;
ss.channels = 2;
s =pa_simple_new(NULL,"Groove",PA_STREAM_PLAYBACK ,NULL,"Music",&ss,NULL,NULL,NULL);
unsigned char bytes[1024];
size_t bsize = 1024;
size_t done = 0;
bool stop = false;
playing=true;
while(!stop)
{
switch(net)
{
case TWait: usleep(100); break;
case TData:
if(mpg123_read(mh,bytes,bsize,&done)==MPG123_DONE)
{
net=TFinish;
}
pa_simple_write(s,bytes,done,&error);
break;
case TAbort:
stop = true;
break;
case TFinish:
pa_simple_drain(s,&error);
stop = true;
break;
default: break;
}
}
qDebug("Finsihed playback");
pa_simple_free(s);
mpg123_exit();
}
void mpgplayer::setPlaylist(playlist *playList)
{
this->pl = playList;
connect(pl,SIGNAL(bufferReady(int)),this,SLOT(start(int)));
connect(pl,SIGNAL(downloadProgress(int,qint64,qint64)),this,SLOT(putb(int,qint64,qint64)));
//connect(pl,SIGNAL(downloadComplete(int)),this,SLOT(start(int)));
}
void mpgplayer::markComplete()
{
}
void mpgplayer::updatePlayPosition(qint64 time)
{
//qDebug() << time << ":" << media->totalTime();
}
void mpgplayer::pause()
{
if(playing)
net = TWait;
else
net = TData;
playing = !playing;
}
void mpgplayer::playNext()
{
}
mpgplayer::~mpgplayer()
{
}
void mpgplayer::back()
{
}
void mpgplayer::abortDownload()
{
//pd->hide();
//reply->abort();
}
void mpgplayer::play()
{
}
void mpgplayer::play(int p)
{
}
void mpgplayer::stop()
{
}
void mpgplayer::putb(int p, qint64 b, qint64 t)
{
//qDebug() << "Download: " << b << "Total: " << t;
if(p == pl->currentplaying())
{
if(pl->bReady(p))
{
}
}
}