QMediaPlaylist: Added ability to load from provided QNetworkRequest.
Change-Id: I7d8fc8a432810ff87650808b9ca6af53f7356d4e Reviewed-by: Dmytro Poplavskiy <dmytro.poplavskiy@nokia.com>
This commit is contained in:
committed by
Qt by Nokia
parent
c00033dfe2
commit
92b58ac1a7
@@ -543,21 +543,21 @@ QPlaylistFileParser::FileType QPlaylistFileParser::findPlaylistType(const QStrin
|
|||||||
return UNKNOWN;
|
return UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QPlaylistFileParser::start(const QUrl& url, bool utf8)
|
void QPlaylistFileParser::start(const QNetworkRequest& request, bool utf8)
|
||||||
{
|
{
|
||||||
Q_D(QPlaylistFileParser);
|
Q_D(QPlaylistFileParser);
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
d->m_type = UNKNOWN;
|
d->m_type = UNKNOWN;
|
||||||
d->m_utf8 = utf8;
|
d->m_utf8 = utf8;
|
||||||
d->m_root = url;
|
d->m_root = request.url();
|
||||||
|
|
||||||
if (url.isLocalFile() && !QFile::exists(url.toLocalFile())) {
|
if (d->m_root.isLocalFile() && !QFile::exists(d->m_root.toLocalFile())) {
|
||||||
emit error(NetworkError, QString(tr("%1 does not exist")).arg(url.toString()));
|
emit error(NetworkError, QString(tr("%1 does not exist")).arg(d->m_root.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
d->m_source = d->m_mgr.get(QNetworkRequest(url));
|
d->m_source = d->m_mgr.get(request);
|
||||||
|
|
||||||
connect(d->m_source, SIGNAL(readyRead()), this, SLOT(_q_handleData()));
|
connect(d->m_source, SIGNAL(readyRead()), this, SLOT(_q_handleData()));
|
||||||
connect(d->m_source, SIGNAL(finished()), this, SLOT(_q_handleData()));
|
connect(d->m_source, SIGNAL(finished()), this, SLOT(_q_handleData()));
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public:
|
|||||||
|
|
||||||
static FileType findPlaylistType(const QString& uri, const QString& mime, const void *data, quint32 size);
|
static FileType findPlaylistType(const QString& uri, const QString& mime, const void *data, quint32 size);
|
||||||
|
|
||||||
void start(const QUrl& url, bool utf8 = false);
|
void start(const QNetworkRequest &request, bool utf8 = false);
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class QMediaNetworkPlaylistProviderPrivate: public QMediaPlaylistProviderPrivate
|
|||||||
{
|
{
|
||||||
Q_DECLARE_NON_CONST_PUBLIC(QMediaNetworkPlaylistProvider)
|
Q_DECLARE_NON_CONST_PUBLIC(QMediaNetworkPlaylistProvider)
|
||||||
public:
|
public:
|
||||||
bool load(const QUrl &location);
|
bool load(const QNetworkRequest &request);
|
||||||
|
|
||||||
QPlaylistFileParser parser;
|
QPlaylistFileParser parser;
|
||||||
QList<QMediaContent> resources;
|
QList<QMediaContent> resources;
|
||||||
@@ -62,10 +62,10 @@ public:
|
|||||||
QMediaNetworkPlaylistProvider *q_ptr;
|
QMediaNetworkPlaylistProvider *q_ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool QMediaNetworkPlaylistProviderPrivate::load(const QUrl &location)
|
bool QMediaNetworkPlaylistProviderPrivate::load(const QNetworkRequest &request)
|
||||||
{
|
{
|
||||||
parser.stop();
|
parser.stop();
|
||||||
parser.start(location, false);
|
parser.start(request, false);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -129,10 +129,10 @@ bool QMediaNetworkPlaylistProvider::isReadOnly() const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QMediaNetworkPlaylistProvider::load(const QUrl &location, const char *format)
|
bool QMediaNetworkPlaylistProvider::load(const QNetworkRequest &request, const char *format)
|
||||||
{
|
{
|
||||||
Q_UNUSED(format);
|
Q_UNUSED(format);
|
||||||
return d_func()->load(location);
|
return d_func()->load(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
int QMediaNetworkPlaylistProvider::mediaCount() const
|
int QMediaNetworkPlaylistProvider::mediaCount() const
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ public:
|
|||||||
QMediaNetworkPlaylistProvider(QObject *parent=0);
|
QMediaNetworkPlaylistProvider(QObject *parent=0);
|
||||||
virtual ~QMediaNetworkPlaylistProvider();
|
virtual ~QMediaNetworkPlaylistProvider();
|
||||||
|
|
||||||
virtual bool load(const QUrl &location, const char *format = 0);
|
virtual bool load(const QNetworkRequest &request, const char *format = 0);
|
||||||
|
|
||||||
virtual int mediaCount() const;
|
virtual int mediaCount() const;
|
||||||
virtual QMediaContent media(int pos) const;
|
virtual QMediaContent media(int pos) const;
|
||||||
|
|||||||
@@ -370,7 +370,7 @@ void QMediaPlayerPrivate::loadPlaylist()
|
|||||||
pendingPlaylist = QMediaContent(new QMediaPlaylist, q->currentMedia().canonicalUrl(), true);
|
pendingPlaylist = QMediaContent(new QMediaPlaylist, q->currentMedia().canonicalUrl(), true);
|
||||||
QObject::connect(pendingPlaylist.playlist(), SIGNAL(loaded()), q, SLOT(_q_handlePlaylistLoaded()));
|
QObject::connect(pendingPlaylist.playlist(), SIGNAL(loaded()), q, SLOT(_q_handlePlaylistLoaded()));
|
||||||
QObject::connect(pendingPlaylist.playlist(), SIGNAL(loadFailed()), q, SLOT(_q_handlePlaylistLoadFailed()));
|
QObject::connect(pendingPlaylist.playlist(), SIGNAL(loadFailed()), q, SLOT(_q_handlePlaylistLoadFailed()));
|
||||||
pendingPlaylist.playlist()->load(pendingPlaylist.canonicalUrl());
|
pendingPlaylist.playlist()->load(pendingPlaylist.canonicalRequest());
|
||||||
} else if (playlist) {
|
} else if (playlist) {
|
||||||
playlist->next();
|
playlist->next();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -437,22 +437,22 @@ bool QMediaPlaylistPrivate::writeItems(QMediaPlaylistWriter *writer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Load playlist from \a location. If \a format is specified, it is used,
|
Load playlist using network \a request. If \a format is specified, it is used,
|
||||||
otherwise format is guessed from location name and data.
|
otherwise format is guessed from playlist name and data.
|
||||||
|
|
||||||
New items are appended to playlist.
|
New items are appended to playlist.
|
||||||
|
|
||||||
QMediaPlaylist::loaded() signal is emitted if playlist was loaded successfully,
|
QMediaPlaylist::loaded() signal is emitted if playlist was loaded successfully,
|
||||||
otherwise the playlist emits loadFailed().
|
otherwise the playlist emits loadFailed().
|
||||||
*/
|
*/
|
||||||
void QMediaPlaylist::load(const QUrl &location, const char *format)
|
void QMediaPlaylist::load(const QNetworkRequest &request, const char *format)
|
||||||
{
|
{
|
||||||
Q_D(QMediaPlaylist);
|
Q_D(QMediaPlaylist);
|
||||||
|
|
||||||
d->error = NoError;
|
d->error = NoError;
|
||||||
d->errorString.clear();
|
d->errorString.clear();
|
||||||
|
|
||||||
if (d->playlist()->load(location,format))
|
if (d->playlist()->load(request,format))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (isReadOnly()) {
|
if (isReadOnly()) {
|
||||||
@@ -464,8 +464,8 @@ void QMediaPlaylist::load(const QUrl &location, const char *format)
|
|||||||
|
|
||||||
foreach (QString const& key, playlistIOLoader()->keys()) {
|
foreach (QString const& key, playlistIOLoader()->keys()) {
|
||||||
QMediaPlaylistIOInterface* plugin = qobject_cast<QMediaPlaylistIOInterface*>(playlistIOLoader()->instance(key));
|
QMediaPlaylistIOInterface* plugin = qobject_cast<QMediaPlaylistIOInterface*>(playlistIOLoader()->instance(key));
|
||||||
if (plugin && plugin->canRead(location,format)) {
|
if (plugin && plugin->canRead(request.url(), format)) {
|
||||||
QMediaPlaylistReader *reader = plugin->createReader(location,QByteArray(format));
|
QMediaPlaylistReader *reader = plugin->createReader(request.url(), QByteArray(format));
|
||||||
if (reader && d->readItems(reader)) {
|
if (reader && d->readItems(reader)) {
|
||||||
delete reader;
|
delete reader;
|
||||||
emit loaded();
|
emit loaded();
|
||||||
@@ -482,6 +482,21 @@ void QMediaPlaylist::load(const QUrl &location, const char *format)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Load playlist from \a location. If \a format is specified, it is used,
|
||||||
|
otherwise format is guessed from location name and data.
|
||||||
|
|
||||||
|
New items are appended to playlist.
|
||||||
|
|
||||||
|
QMediaPlaylist::loaded() signal is emitted if playlist was loaded successfully,
|
||||||
|
otherwise the playlist emits loadFailed().
|
||||||
|
*/
|
||||||
|
|
||||||
|
void QMediaPlaylist::load(const QUrl &location, const char *format)
|
||||||
|
{
|
||||||
|
load(QNetworkRequest(location), format);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Load playlist from QIODevice \a device. If \a format is specified, it is used,
|
Load playlist from QIODevice \a device. If \a format is specified, it is used,
|
||||||
otherwise format is guessed from device data.
|
otherwise format is guessed from device data.
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ public:
|
|||||||
bool removeMedia(int start, int end);
|
bool removeMedia(int start, int end);
|
||||||
bool clear();
|
bool clear();
|
||||||
|
|
||||||
|
void load(const QNetworkRequest &request, const char *format = 0);
|
||||||
void load(const QUrl &location, const char *format = 0);
|
void load(const QUrl &location, const char *format = 0);
|
||||||
void load(QIODevice * device, const char *format = 0);
|
void load(QIODevice * device, const char *format = 0);
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ QMediaPlaylistProvider::~QMediaPlaylistProvider()
|
|||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Loads a playlist from from a URL \a location. If no playlist \a format is specified the loader
|
Loads a playlist using network \a request. If no playlist \a format is specified the loader
|
||||||
will inspect the URL or probe the headers to guess the format.
|
will inspect the URL or probe the headers to guess the format.
|
||||||
|
|
||||||
New items are appended to playlist.
|
New items are appended to playlist.
|
||||||
@@ -106,9 +106,9 @@ QMediaPlaylistProvider::~QMediaPlaylistProvider()
|
|||||||
Returns true if the provider supports the format and loading from the locations URL protocol,
|
Returns true if the provider supports the format and loading from the locations URL protocol,
|
||||||
otherwise this will return false.
|
otherwise this will return false.
|
||||||
*/
|
*/
|
||||||
bool QMediaPlaylistProvider::load(const QUrl &location, const char *format)
|
bool QMediaPlaylistProvider::load(const QNetworkRequest &request, const char *format)
|
||||||
{
|
{
|
||||||
Q_UNUSED(location);
|
Q_UNUSED(request);
|
||||||
Q_UNUSED(format);
|
Q_UNUSED(format);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ public:
|
|||||||
QMediaPlaylistProvider(QObject *parent=0);
|
QMediaPlaylistProvider(QObject *parent=0);
|
||||||
virtual ~QMediaPlaylistProvider();
|
virtual ~QMediaPlaylistProvider();
|
||||||
|
|
||||||
virtual bool load(const QUrl &location, const char *format = 0);
|
virtual bool load(const QNetworkRequest &request, const char *format = 0);
|
||||||
virtual bool load(QIODevice * device, const char *format = 0);
|
virtual bool load(QIODevice * device, const char *format = 0);
|
||||||
virtual bool save(const QUrl &location, const char *format = 0);
|
virtual bool save(const QUrl &location, const char *format = 0);
|
||||||
virtual bool save(QIODevice * device, const char *format);
|
virtual bool save(QIODevice * device, const char *format);
|
||||||
|
|||||||
@@ -429,6 +429,12 @@ void tst_QMediaPlaylist::loadM3uFile()
|
|||||||
//ensure #2 suffix is not stripped from path
|
//ensure #2 suffix is not stripped from path
|
||||||
testFileName = QFINDTESTDATA("testdata/testfile2#suffix");
|
testFileName = QFINDTESTDATA("testdata/testfile2#suffix");
|
||||||
QCOMPARE(playlist.media(6).canonicalUrl(), QUrl::fromLocalFile(testFileName));
|
QCOMPARE(playlist.media(6).canonicalUrl(), QUrl::fromLocalFile(testFileName));
|
||||||
|
// check ability to load from QNetworkRequest
|
||||||
|
QSignalSpy loadSpy(&playlist, SIGNAL(loaded()));
|
||||||
|
QSignalSpy loadFailedSpy(&playlist, SIGNAL(loadFailed()));
|
||||||
|
playlist.load(QNetworkRequest(QUrl::fromLocalFile(QFINDTESTDATA("testdata/test.m3u"))));
|
||||||
|
QTRY_VERIFY(!loadSpy.isEmpty());
|
||||||
|
QVERIFY(loadFailedSpy.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QMediaPlaylist::playbackMode_data()
|
void tst_QMediaPlaylist::playbackMode_data()
|
||||||
|
|||||||
Reference in New Issue
Block a user