X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=splayer.cpp;h=a2349b25c2f8580c4cf6b8d7a6cfe65856786d48;hb=ece7001a5b569241115c0187d654b92e247c68f6;hp=dae3fccb24c1627d66923c2ca6bc7ccc846499e9;hpb=2f9c66b9177f647336c61dda586b1918bcb2f2a3;p=groove diff --git a/splayer.cpp b/splayer.cpp index dae3fcc..a2349b2 100644 --- a/splayer.cpp +++ b/splayer.cpp @@ -12,12 +12,26 @@ sPlayer::sPlayer(QObject *parent) : //reply = new QNetworkReply(); internal = parent; //buffer->open(QIODevice::ReadWrite); + connect(media,SIGNAL(finished()),this,SLOT(markComplete())); } +void sPlayer::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 sPlayer::markComplete() +{ + pl->markPlayed(pl->currentplaying()); + pl->setCurrentPlaying(-1); +} + sPlayer::~sPlayer() { manager->~QNetworkAccessManager(); //reply->~QIODevice(); - buffer->~QBuffer(); media->~MediaNode(); } void sPlayer::abortDownload() @@ -26,125 +40,49 @@ void sPlayer::abortDownload() //reply->abort(); } -void sPlayer::play(QString StreamKey,QUrl server) +void sPlayer::start(int p) { - if(playing) - { - //reply->abort(); - } - pd = new grooveProgressBar(); - //pd->setAttribute(); - -#ifdef Q_WS_MAEMO_5 - pd->setAttribute(Qt::WA_Maemo5AutoOrientation,true); - //pd->setModal(false); -#endif - pd->show(); - pd->setValue(0); - QNetworkRequest req; - req.setUrl(server); - qDebug() << server; - req.setHeader(req.ContentTypeHeader,QVariant("application/x-www-form-urlencoded")); - reply = manager->post(req,QString("streamKey=" + StreamKey.toAscii()).toAscii()); - buffer->open(buffer->ReadWrite | buffer->Truncate); - connect(reply,SIGNAL(finished()),this,SLOT(start())); - connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(putb(qint64,qint64))); - //connect(pd,SIGNAL(canceled()),this,SLOT(abortDownload())); - media->stop(); - playing = false; - startStreamT = QTime::currentTime(); -} -void sPlayer::start() -{ - QVariant url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); - if(url.toUrl().isValid()) - { - QNetworkRequest req; - req.setUrl(url.toUrl()); - qDebug() << url; - reply = manager->get(req); - connect(reply,SIGNAL(finished()),this,SLOT(start())); - connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(putb(qint64,qint64))); - } - else - { - if(!playing) + qDebug() << "got start play"; + if(p == pl->currentplaying()) { playing = true; - media->setCurrentSource(Phonon::MediaSource(buffer)); + media->setCurrentSource(Phonon::MediaSource(pl->getBuffer(p))); media->play(); qDebug() << "Playing"; } - } - /*else + +} +void sPlayer::play() +{ + if(pl->currentplaying() != -1) { - media->stop(); - buffer->close(); - buffer->open(QIODevice::ReadWrite | QIODevice::Truncate); - buffer->write(reply->readAll()); - reply->close(); - media->setCurrentSource(Phonon::MediaSource(buffer)); - media->play(); - }*/ + //pl->setCurrentPlaying(pl->findFirstNotPlayed()); + } + else + return; } +void sPlayer::play(int p) +{ + pl->setCurrentPlaying(p); + //pl->beginDownload(p); +} + void sPlayer::stop() { + pl->setCurrentPlaying(-1); media->stop(); + playing = false; } -void sPlayer::putb(qint64 b, qint64 t) +void sPlayer::putb(int p, qint64 b, qint64 t) { //qDebug() << "Download: " << b << "Total: " << t; - if(b == 0 && t == 0) - { - QVariant url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); - if(url.toUrl().isValid()) - { - QNetworkRequest req; - req.setUrl(url.toUrl()); - qDebug() << url; - reply = manager->get(req); - connect(reply,SIGNAL(finished()),this,SLOT(start())); - connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(putb(qint64,qint64))); - } - else - { - //buffer->close(); - reply->close(); - } - } - else + if(p == pl->currentplaying()) { - if(pd->maximum() != t) - pd->setMaximum(t); - pd->setValue(b); - - buffer->buffer().append(reply->readAll()); - //qDebug() << buffer->bytesAvailable(); - if(playing) + if(pl->bReady(p)) { StreamIO* stream = (StreamIO*) media->currentSource().stream(); - stream->setStreamSize(buffer->size()); - } - - /* - //buffer->seek(b); - qint64 last = buffer->pos(); - buffer->seek(buffer->bytesAvailable()+buffer->pos()); - qDebug() << buffer->write(reply->readAll()); - qDebug() << buffer->pos(); - //buffer->putChar() - buffer->seek(last); - //buffer->data().append(reply->readAll());*/ - //qDebug() << "Download speed (KB/S): " << b/(startStreamT.msecsTo(QTime::currentTime()) + 1)*100/1024; - if ( b >= t*0.05 && !playing && b/(startStreamT.msecsTo(QTime::currentTime()) + 1)*100/1024 >= 25) - { - pd->hide(); - playing = true; - //Start playback at 25% download - media->setCurrentSource(Phonon::MediaSource(buffer)); - media->play(); - qDebug() << "Playing"; + stream->setStreamSize(pl->getBuffer(p)->size()); } } }