//reply = new QNetworkReply();
internal = parent;
//buffer->open(QIODevice::ReadWrite);
+ connect(media,SIGNAL(finished()),this,SLOT(markComplete()));
+ media->setTickInterval(200);
+ connect(media,SIGNAL(tick(qint64)),this,SLOT(updatePlayPosition(qint64)));
}
-sPlayer::~sPlayer()
+void sPlayer::setPlaylist(playlist *playList)
{
- manager->~QNetworkAccessManager();
- //reply->~QIODevice();
- buffer->~QBuffer();
- media->~MediaNode();
+ 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::abortDownload()
+void sPlayer::markComplete()
{
- //pd->hide();
- //reply->abort();
+ pl->markPlayed(pl->currentplaying());
+ if(pl->existAt(pl->currentplaying()+1))
+ {
+ pl->setCurrentPlaying(pl->currentplaying()+1);
+ if(pl->bReady(pl->currentplaying()))
+ this->start(pl->currentplaying());
+ }
+ else
+ pl->setCurrentPlaying(-1);
}
-void sPlayer::play(QString StreamKey, QUrl server, QMaemo5Rotator::Orientation orientation)
+void sPlayer::updatePlayPosition(qint64 time)
{
- this->play(StreamKey, server);
-#ifdef Q_WS_MAEMO_5
- if(orientation == QMaemo5Rotator::PortraitOrientation)
- pd->rot->setCurrentOrientation(orientation);
-#endif
- //isPortrait = false; //just make the compilier happy on non-maemo
+ //qDebug() << time << ":" << media->totalTime();
}
-void sPlayer::play(QString StreamKey,QUrl server)
+void sPlayer::pause()
+{
+ if(media->state() == Phonon::PausedState)
+ media->play();
+ if(media->state() == Phonon::PlayingState)
+ media->pause();
+}
+void sPlayer::playNext()
{
- if(playing)
+ if(pl->existAt(pl->currentplaying()+1))
{
- //reply->abort();
+ media->stop();
+ this->markComplete();
}
- pd = new grooveProgressBar();
- //pd->setAttribute();
- 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()
+
+sPlayer::~sPlayer()
+{
+ manager->~QNetworkAccessManager();
+ //reply->~QIODevice();
+ media->~MediaNode();
+}
+void sPlayer::back()
{
- QVariant url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
- if(url.toUrl().isValid())
+ media->stop();
+ if(pl->existAt(pl->currentplaying()-1))
{
- 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)));
+ pl->setCurrentPlaying(pl->currentplaying()-1);
+ if(pl->bReady(pl->currentplaying()))
+ this->start(pl->currentplaying());
}
else
- {
- if(!playing)
+ pl->setCurrentPlaying(-1);
+}
+
+void sPlayer::abortDownload()
+{
+ //pd->hide();
+ //reply->abort();
+}
+
+void sPlayer::start(int p)
+{
+ qDebug() << "got start play";
+ if(p == pl->currentplaying())
{
playing = true;
- media->setCurrentSource(Phonon::MediaSource(buffer));
+ media->setCurrentSource(Phonon::MediaSource(pl->getBuffer(p)));
media->play();
- pd->hide();
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)
+{
+ if(pl->currentplaying() != -1)
+ pl->freeMemory(pl->currentplaying());
+ pl->setCurrentPlaying(p);
+ //pl->beginDownload(p);
+}
+
void sPlayer::stop()
{
+
media->stop();
+ if(pl->currentplaying() != -1)
+ pl->markPlayed(pl->currentplaying());
+ pl->setCurrentPlaying(-1);
+ 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)
+ if(p == pl->currentplaying())
{
- 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(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 >= 10)
- {
- pd->hide();
- playing = true;
- //Start playback at 25% download
- media->setCurrentSource(Phonon::MediaSource(buffer));
- media->play();
- qDebug() << "Playing";
+ stream->setStreamSize(pl->getBuffer(p)->size());
}
}
}