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();
24 void sPlayer::play(QString StreamKey,QUrl server)
34 req.setHeader(req.ContentTypeHeader,QVariant("application/x-www-form-urlencoded"));
35 reply = manager->post(req,QString("streamKey=" + StreamKey.toAscii()).toAscii());
36 buffer->open(buffer->ReadWrite | buffer->Truncate);
37 connect(reply,SIGNAL(finished()),this,SLOT(start()));
38 connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(putb(qint64,qint64)));
41 startStreamT = QTime::currentTime();
45 QVariant url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
46 if(url.toUrl().isValid())
49 req.setUrl(url.toUrl());
51 reply = manager->get(req);
52 connect(reply,SIGNAL(finished()),this,SLOT(start()));
53 connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(putb(qint64,qint64)));
60 media->setCurrentSource(Phonon::MediaSource(buffer));
62 qDebug() << "Playing";
69 buffer->open(QIODevice::ReadWrite | QIODevice::Truncate);
70 buffer->write(reply->readAll());
72 media->setCurrentSource(Phonon::MediaSource(buffer));
76 void sPlayer::putb(qint64 b, qint64 t)
78 //qDebug() << "Download: " << b << "Total: " << t;
81 QVariant url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
82 if(url.toUrl().isValid())
85 req.setUrl(url.toUrl());
87 reply = manager->get(req);
88 connect(reply,SIGNAL(finished()),this,SLOT(start()));
89 connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(putb(qint64,qint64)));
100 buffer->buffer().append(reply->readAll());
101 //qDebug() << buffer->bytesAvailable();
104 StreamIO* stream = (StreamIO*) media->currentSource().stream();
105 stream->setStreamSize(buffer->size());
110 qint64 last = buffer->pos();
111 buffer->seek(buffer->bytesAvailable()+buffer->pos());
112 qDebug() << buffer->write(reply->readAll());
113 qDebug() << buffer->pos();
116 //buffer->data().append(reply->readAll());*/
117 //qDebug() << "Download speed (KB/S): " << b/(startStreamT.msecsTo(QTime::currentTime()) + 1)*100/1024;
118 if ( b >= t*0.05 && !playing && b/(startStreamT.msecsTo(QTime::currentTime()) + 1)*100/1024 >= 35)
121 //Start playback at 25% download
122 media->setCurrentSource(Phonon::MediaSource(buffer));
124 qDebug() << "Playing";