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)
34 pd = new QProgressDialog("Downloading / Buffering.", "Cancel", 0, 100);
37 pd->setAttribute(Qt::WA_Maemo5AutoOrientation,true);
42 req.setHeader(req.ContentTypeHeader,QVariant("application/x-www-form-urlencoded"));
43 reply = manager->post(req,QString("streamKey=" + StreamKey.toAscii()).toAscii());
44 buffer->open(buffer->ReadWrite | buffer->Truncate);
45 connect(reply,SIGNAL(finished()),this,SLOT(start()));
46 connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(putb(qint64,qint64)));
47 connect(pd,SIGNAL(canceled()),this,SLOT(abortDownload()));
50 startStreamT = QTime::currentTime();
54 QVariant url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
55 if(url.toUrl().isValid())
58 req.setUrl(url.toUrl());
60 reply = manager->get(req);
61 connect(reply,SIGNAL(finished()),this,SLOT(start()));
62 connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(putb(qint64,qint64)));
69 media->setCurrentSource(Phonon::MediaSource(buffer));
71 qDebug() << "Playing";
78 buffer->open(QIODevice::ReadWrite | QIODevice::Truncate);
79 buffer->write(reply->readAll());
81 media->setCurrentSource(Phonon::MediaSource(buffer));
90 void sPlayer::putb(qint64 b, qint64 t)
92 //qDebug() << "Download: " << b << "Total: " << t;
95 QVariant url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
96 if(url.toUrl().isValid())
99 req.setUrl(url.toUrl());
101 reply = manager->get(req);
102 connect(reply,SIGNAL(finished()),this,SLOT(start()));
103 connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(putb(qint64,qint64)));
113 if(pd->maximum() != t)
117 buffer->buffer().append(reply->readAll());
118 //qDebug() << buffer->bytesAvailable();
121 StreamIO* stream = (StreamIO*) media->currentSource().stream();
122 stream->setStreamSize(buffer->size());
127 qint64 last = buffer->pos();
128 buffer->seek(buffer->bytesAvailable()+buffer->pos());
129 qDebug() << buffer->write(reply->readAll());
130 qDebug() << buffer->pos();
133 //buffer->data().append(reply->readAll());*/
134 //qDebug() << "Download speed (KB/S): " << b/(startStreamT.msecsTo(QTime::currentTime()) + 1)*100/1024;
135 if ( b >= t*0.05 && !playing && b/(startStreamT.msecsTo(QTime::currentTime()) + 1)*100/1024 >= 25)
139 //Start playback at 25% download
140 media->setCurrentSource(Phonon::MediaSource(buffer));
142 qDebug() << "Playing";