3 playlist::playlist(QObject *parent) :
6 manager = new QNetworkAccessManager();
7 this->currentdownloaditem = -1;
8 pList = new QList<songElement *>;
10 void playlist::beginDownload(int position)
12 startStreamT = QTime::currentTime();
13 this->currentdownloaditem = position;
16 void playlist::setGscom(gscom *comm)
19 connect(gs,SIGNAL(sKeyFound()),this,SLOT(skeyFound()));
21 void playlist::skeyFound()
23 emit this->unfreeze();
24 pList->at(this->currentSkeyItem)->streamkey = new QString(gs->streamID);
25 pList->at(this->currentSkeyItem)->server = new QUrl(gs->sku);
26 if(this->currentdownloaditem == -1)
27 this->beginDownload(this->currentSkeyItem);
30 void playlist::addSong(QStandardItem item)
33 playlist::songElement *newelement = new playlist::songElement;
34 newelement->buffer = new QBuffer();
35 newelement->downloaded =false;
36 newelement->songId = new QString(item.text());
37 newelement->played = false;
38 newelement->server = new QUrl();
39 newelement->streamkey = new QString("noneatm");
40 newelement->bufferready = false;
41 newelement->type = playlist::EStream;
42 pList->append(newelement);
43 gs->getSong(item.text());
45 //this->currentdownloaditem = pList->size()-1;
48 void playlist::downloadDone(int position)
50 if(pList->size() < position+1)
51 beginDownload(position+1);
53 this->currentdownloaditem = -1;
54 pList->at(position)->downloaded = true;
57 void playlist::downloadSlot(qint64 b, qint64 t)
59 //qDebug() << "Download: " << b << "Total: " << t;
62 QVariant url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
63 if(url.toUrl().isValid())
66 req.setUrl(url.toUrl());
68 reply = manager->get(req);
69 startStreamT = QTime::currentTime();
70 //connect(reply,SIGNAL(finished()),this,SLOT(start()));
71 connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(downloadSlot(qint64,qint64)));
76 emit this->sFailure(this->currentdownloaditem,playlist::Other);
82 emit this->downloadProgress(this->currentdownloaditem,b,t);
83 pList->at(this->currentdownloaditem)->buffer->buffer().append(reply->readAll());
84 //qDebug() << buffer->bytesAvailable();
88 qint64 last = buffer->pos();
89 buffer->seek(buffer->bytesAvailable()+buffer->pos());
90 qDebug() << buffer->write(reply->readAll());
91 qDebug() << buffer->pos();
94 //buffer->data().append(reply->readAll());*/
95 //qDebug() << "Download speed (KB/S): " << b/(startStreamT.msecsTo(QTime::currentTime()) + 1)*100/1024;
96 if ( b >= t*0.05 && !pList->at(currentdownloaditem)->bufferready && b/(startStreamT.msecsTo(QTime::currentTime()) + 1)*100/1024 >= 10)
98 emit this->bufferReady(this->currentdownloaditem);
99 qDebug() << "Buffer Ready";
103 emit this->downloadComplete(this->currentdownloaditem);