test
::test(QWidget *parent, Qt
::WFlags flags
){
ui.setupUi(this);
pl = new Phonon::VideoPlayer(Phonon::MusicCategory, this);
// this plays fine, meaning the video player does work:
// pl->load(Phonon::MediaSource(QUrl("http://localhost/hello.mp3")));
// pl->play();
// return;
loaded = false;
networkManager = new QNetworkAccessManager(this);
connect(networkManager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(networkManagerFinished(QNetworkReply*)));
connect(networkManager, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)),
this, SLOT(authenticationRequired(QNetworkReply*, QAuthenticator*)));
networkReply
= networkManager
->get
(QNetworkRequest
(QUrl("http://localhost/hello.mp3")));
connect(networkReply, SIGNAL(downloadProgress(qint64, qint64)),
this, SLOT(downloadProgress(qint64, qint64)));
}
test::~test()
{
}
void test::downloadProgress(qint64 cur,qint64 tot)
{
if(!loaded && cur > 1024)
{
qDebug() << "Loading...";
pl
->load
(Phonon
::MediaSource((QIODevice*)sender
()));
connect(pl->mediaObject(), SIGNAL(stateChanged(Phonon::State,Phonon::State)),
this, SLOT(onStateChanged(Phonon::State, Phonon::State)));
loaded = true;
}
}
void test::onStateChanged(Phonon::State newState,Phonon::State oldState)
{
// here we always get Phonon::ErrorState
qDebug() << "New state: " << newState;
}
void test::networkManagerFinished(QNetworkReply *reply)
{
// this works, it saves the file in full, and I can play it
byteArrayToFile(&byteArray, "d:/hello.mp3");
}
void test::authenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator)
{
// this is not used on localhost, but it does authenticate properly when using with the site on line
qDebug() << "Authenticating";
authenticator->setUser("username");
authenticator->setPassword("password");
}
test::test(QWidget *parent, Qt::WFlags flags)
: QDialog(parent, flags)
{
ui.setupUi(this);
pl = new Phonon::VideoPlayer(Phonon::MusicCategory, this);
// this plays fine, meaning the video player does work:
// pl->load(Phonon::MediaSource(QUrl("http://localhost/hello.mp3")));
// pl->play();
// return;
loaded = false;
networkManager = new QNetworkAccessManager(this);
connect(networkManager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(networkManagerFinished(QNetworkReply*)));
connect(networkManager, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)),
this, SLOT(authenticationRequired(QNetworkReply*, QAuthenticator*)));
networkReply = networkManager->get(QNetworkRequest(QUrl("http://localhost/hello.mp3")));
connect(networkReply, SIGNAL(downloadProgress(qint64, qint64)),
this, SLOT(downloadProgress(qint64, qint64)));
}
test::~test()
{
}
void test::downloadProgress(qint64 cur,qint64 tot)
{
if(!loaded && cur > 1024)
{
qDebug() << "Loading...";
pl->load(Phonon::MediaSource((QIODevice*)sender()));
connect(pl->mediaObject(), SIGNAL(stateChanged(Phonon::State,Phonon::State)),
this, SLOT(onStateChanged(Phonon::State, Phonon::State)));
loaded = true;
}
}
void test::onStateChanged(Phonon::State newState,Phonon::State oldState)
{
// here we always get Phonon::ErrorState
qDebug() << "New state: " << newState;
}
void test::networkManagerFinished(QNetworkReply *reply)
{
// this works, it saves the file in full, and I can play it
QByteArray byteArray = reply->readAll();
byteArrayToFile(&byteArray, "d:/hello.mp3");
}
void test::authenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator)
{
// this is not used on localhost, but it does authenticate properly when using with the site on line
qDebug() << "Authenticating";
authenticator->setUser("username");
authenticator->setPassword("password");
}
To copy to clipboard, switch view to plain text mode
Bookmarks