3 sPlayer::sPlayer(QObject *parent) :
6 manager = new QNetworkAccessManager();
7 buffer = new QBuffer();
8 audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory,this);
9 media = new Phonon::MediaObject(this);
10 Phonon::createPath(media, audioOutput);
12 //reply = new QNetworkReply();
14 //buffer->open(QIODevice::ReadWrite);
18 manager->~QNetworkAccessManager();
19 //reply->~QIODevice();
23 void sPlayer::abortDownload()
28 void sPlayer::play(QString StreamKey, QUrl server, QMaemo5Rotator::Orientation orientation)
30 this->play(StreamKey, server);
32 if(orientation == QMaemo5Rotator::PortraitOrientation)
33 pd->rot->setCurrentOrientation(orientation);
35 //isPortrait = false; //just make the compilier happy on non-maemo
38 void sPlayer::play(QString StreamKey,QUrl server)
44 pd = new grooveProgressBar();
51 req.setHeader(req.ContentTypeHeader,QVariant("application/x-www-form-urlencoded"));
52 reply = manager->post(req,QString("streamKey=" + StreamKey.toAscii()).toAscii());
53 buffer->open(buffer->ReadWrite | buffer->Truncate);
54 connect(reply,SIGNAL(finished()),this,SLOT(start()));
55 connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(putb(qint64,qint64)));
56 //connect(pd,SIGNAL(canceled()),this,SLOT(abortDownload()));
59 startStreamT = QTime::currentTime();
63 QVariant url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
64 if(url.toUrl().isValid())
67 req.setUrl(url.toUrl());
69 reply = manager->get(req);
70 connect(reply,SIGNAL(finished()),this,SLOT(start()));
71 connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(putb(qint64,qint64)));
78 media->setCurrentSource(Phonon::MediaSource(buffer));
81 qDebug() << "Playing";
88 buffer->open(QIODevice::ReadWrite | QIODevice::Truncate);
89 buffer->write(reply->readAll());
91 media->setCurrentSource(Phonon::MediaSource(buffer));
100 void sPlayer::putb(qint64 b, qint64 t)
102 //qDebug() << "Download: " << b << "Total: " << t;
105 QVariant url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
106 if(url.toUrl().isValid())
109 req.setUrl(url.toUrl());
111 reply = manager->get(req);
112 connect(reply,SIGNAL(finished()),this,SLOT(start()));
113 connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(putb(qint64,qint64)));
123 if(pd->maximum() != t)
127 buffer->buffer().append(reply->readAll());
128 //qDebug() << buffer->bytesAvailable();
131 StreamIO* stream = (StreamIO*) media->currentSource().stream();
132 stream->setStreamSize(buffer->size());
137 qint64 last = buffer->pos();
138 buffer->seek(buffer->bytesAvailable()+buffer->pos());
139 qDebug() << buffer->write(reply->readAll());
140 qDebug() << buffer->pos();
143 //buffer->data().append(reply->readAll());*/
144 //qDebug() << "Download speed (KB/S): " << b/(startStreamT.msecsTo(QTime::currentTime()) + 1)*100/1024;
145 if ( b >= t*0.05 && !playing && b/(startStreamT.msecsTo(QTime::currentTime()) + 1)*100/1024 >= 10)
149 //Start playback at 25% download
150 media->setCurrentSource(Phonon::MediaSource(buffer));
152 qDebug() << "Playing";