Added playlist property to QMediaContent
This is a part of changes to QMediaPlayer related to playlist handling. Updated unit test. Change-Id: Ic2460dc4d3121788cd5eb08df71e6d45aac032bc Reviewed-by: Michael Goddard <michael.goddard@nokia.com> Reviewed-by: Dmytro Poplavskiy <dmytro.poplavskiy@nokia.com>
This commit is contained in:
committed by
Qt by Nokia
parent
e2eaa283fb
commit
87de0979e5
@@ -41,7 +41,9 @@
|
|||||||
|
|
||||||
#include <QtCore/qurl.h>
|
#include <QtCore/qurl.h>
|
||||||
#include <QtCore/qvariant.h>
|
#include <QtCore/qvariant.h>
|
||||||
|
#include <QtCore/QWeakPointer>
|
||||||
|
|
||||||
|
#include <qmediaplaylist.h>
|
||||||
#include "qmediacontent.h"
|
#include "qmediacontent.h"
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@@ -62,21 +64,44 @@ namespace
|
|||||||
class QMediaContentPrivate : public QSharedData
|
class QMediaContentPrivate : public QSharedData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QMediaContentPrivate() {}
|
QMediaContentPrivate():
|
||||||
|
isPlaylistOwned(false)
|
||||||
|
{}
|
||||||
|
|
||||||
QMediaContentPrivate(const QMediaResourceList &r):
|
QMediaContentPrivate(const QMediaResourceList &r):
|
||||||
resources(r) {}
|
resources(r),
|
||||||
|
isPlaylistOwned(false)
|
||||||
|
{}
|
||||||
|
|
||||||
QMediaContentPrivate(const QMediaContentPrivate &other):
|
QMediaContentPrivate(const QMediaContentPrivate &other):
|
||||||
QSharedData(other),
|
QSharedData(other),
|
||||||
resources(other.resources)
|
resources(other.resources),
|
||||||
|
playlist(other.playlist),
|
||||||
|
isPlaylistOwned(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
QMediaContentPrivate(QMediaPlaylist *pls, const QUrl &url, bool isOwn):
|
||||||
|
playlist(pls),
|
||||||
|
isPlaylistOwned(isOwn)
|
||||||
|
{
|
||||||
|
resources << QMediaResource(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
~QMediaContentPrivate()
|
||||||
|
{
|
||||||
|
if (isPlaylistOwned && !playlist.isNull())
|
||||||
|
playlist.data()->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
bool operator ==(const QMediaContentPrivate &other) const
|
bool operator ==(const QMediaContentPrivate &other) const
|
||||||
{
|
{
|
||||||
return resources == other.resources;
|
return resources == other.resources && playlist == other.playlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMediaResourceList resources;
|
QMediaResourceList resources;
|
||||||
|
|
||||||
|
QWeakPointer<QMediaPlaylist> playlist;
|
||||||
|
bool isPlaylistOwned;
|
||||||
private:
|
private:
|
||||||
QMediaContentPrivate& operator=(const QMediaContentPrivate &other);
|
QMediaContentPrivate& operator=(const QMediaContentPrivate &other);
|
||||||
};
|
};
|
||||||
@@ -99,6 +124,10 @@ private:
|
|||||||
A non-null QMediaContent will always have a primary or canonical reference to
|
A non-null QMediaContent will always have a primary or canonical reference to
|
||||||
the content available through the canonicalUrl() or canonicalResource()
|
the content available through the canonicalUrl() or canonicalResource()
|
||||||
methods, any additional resources are optional.
|
methods, any additional resources are optional.
|
||||||
|
|
||||||
|
Alternatively QMediaContent can represent a playlist and contain a pointer to a
|
||||||
|
valid QMediaPlaylist object. In this case URL is optional and can either be empty
|
||||||
|
or point to the playlist URL.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -161,6 +190,20 @@ QMediaContent::QMediaContent(const QMediaContent &other):
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Constructs a media content with \a playlist.
|
||||||
|
|
||||||
|
\a contentUrl of a playlist is an optional parameter and can be empty.
|
||||||
|
|
||||||
|
Set \a takeOwnership to true if you want QMediaContent to take ownership of the playlist.
|
||||||
|
\a takeOwnership is set to false by default.
|
||||||
|
*/
|
||||||
|
|
||||||
|
QMediaContent::QMediaContent(QMediaPlaylist *playlist, const QUrl &contentUrl, bool takeOwnership):
|
||||||
|
d(new QMediaContentPrivate(playlist, contentUrl, takeOwnership))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Destroys the media content object.
|
Destroys the media content object.
|
||||||
*/
|
*/
|
||||||
@@ -249,5 +292,16 @@ QMediaResourceList QMediaContent::resources() const
|
|||||||
: QMediaResourceList();
|
: QMediaResourceList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns a playlist for this media content or 0 if this QMediaContent is not a playlist.
|
||||||
|
*/
|
||||||
|
|
||||||
|
QMediaPlaylist *QMediaContent::playlist() const
|
||||||
|
{
|
||||||
|
return d.constData() != 0
|
||||||
|
? d->playlist.data()
|
||||||
|
: 0;
|
||||||
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
|||||||
@@ -49,13 +49,13 @@
|
|||||||
|
|
||||||
#include <qtmultimediadefs.h>
|
#include <qtmultimediadefs.h>
|
||||||
|
|
||||||
|
|
||||||
QT_BEGIN_HEADER
|
QT_BEGIN_HEADER
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
QT_MODULE(Multimedia)
|
QT_MODULE(Multimedia)
|
||||||
|
|
||||||
|
class QMediaPlaylist;
|
||||||
|
|
||||||
class QMediaContentPrivate;
|
class QMediaContentPrivate;
|
||||||
class Q_MULTIMEDIA_EXPORT QMediaContent
|
class Q_MULTIMEDIA_EXPORT QMediaContent
|
||||||
@@ -67,6 +67,7 @@ public:
|
|||||||
QMediaContent(const QMediaResource &contentResource);
|
QMediaContent(const QMediaResource &contentResource);
|
||||||
QMediaContent(const QMediaResourceList &resources);
|
QMediaContent(const QMediaResourceList &resources);
|
||||||
QMediaContent(const QMediaContent &other);
|
QMediaContent(const QMediaContent &other);
|
||||||
|
QMediaContent(QMediaPlaylist *playlist, const QUrl &contentUrl = QUrl(), bool takeOwnership = false);
|
||||||
~QMediaContent();
|
~QMediaContent();
|
||||||
|
|
||||||
QMediaContent& operator=(const QMediaContent &other);
|
QMediaContent& operator=(const QMediaContent &other);
|
||||||
@@ -82,6 +83,7 @@ public:
|
|||||||
|
|
||||||
QMediaResourceList resources() const;
|
QMediaResourceList resources() const;
|
||||||
|
|
||||||
|
QMediaPlaylist *playlist() const;
|
||||||
private:
|
private:
|
||||||
QSharedDataPointer<QMediaContentPrivate> d;
|
QSharedDataPointer<QMediaContentPrivate> d;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -43,6 +43,7 @@
|
|||||||
#include <QtNetwork/qnetworkrequest.h>
|
#include <QtNetwork/qnetworkrequest.h>
|
||||||
|
|
||||||
#include <qmediacontent.h>
|
#include <qmediacontent.h>
|
||||||
|
#include <qmediaplaylist.h>
|
||||||
|
|
||||||
//TESTED_COMPONENT=src/multimedia
|
//TESTED_COMPONENT=src/multimedia
|
||||||
|
|
||||||
@@ -61,6 +62,7 @@ private slots:
|
|||||||
void testAssignment();
|
void testAssignment();
|
||||||
void testEquality();
|
void testEquality();
|
||||||
void testResources();
|
void testResources();
|
||||||
|
void testPlaylist();
|
||||||
};
|
};
|
||||||
|
|
||||||
void tst_QMediaContent::testNull()
|
void tst_QMediaContent::testNull()
|
||||||
@@ -172,6 +174,42 @@ void tst_QMediaContent::testResources()
|
|||||||
QCOMPARE(res[1], QMediaResource(QUrl("http://example.com/movie-big.mov")));
|
QCOMPARE(res[1], QMediaResource(QUrl("http://example.com/movie-big.mov")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QMediaContent::testPlaylist()
|
||||||
|
{
|
||||||
|
QMediaContent media(QUrl("http://example.com/movie.mov"));
|
||||||
|
QVERIFY(media.canonicalUrl().isValid());
|
||||||
|
QVERIFY(!media.playlist());
|
||||||
|
|
||||||
|
{
|
||||||
|
QWeakPointer<QMediaPlaylist> playlist(new QMediaPlaylist);
|
||||||
|
media = QMediaContent(playlist.data(), QUrl("http://example.com/sample.m3u"), true);
|
||||||
|
QVERIFY(media.canonicalUrl().isValid());
|
||||||
|
QCOMPARE(media.playlist(), playlist.data());
|
||||||
|
media = QMediaContent();
|
||||||
|
// Make sure playlist is destroyed by QMediaContent
|
||||||
|
QTRY_VERIFY(!playlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
QMediaPlaylist *playlist = new QMediaPlaylist;
|
||||||
|
media = QMediaContent(playlist, QUrl("http://example.com/sample.m3u"), true);
|
||||||
|
// Delete playlist outside QMediaContent
|
||||||
|
delete playlist;
|
||||||
|
QVERIFY(!media.playlist());
|
||||||
|
media = QMediaContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
QWeakPointer<QMediaPlaylist> playlist(new QMediaPlaylist);
|
||||||
|
media = QMediaContent(playlist.data(), QUrl(), false);
|
||||||
|
QVERIFY(!media.canonicalUrl().isValid());
|
||||||
|
QCOMPARE(media.playlist(), playlist.data());
|
||||||
|
media = QMediaContent();
|
||||||
|
QVERIFY(playlist);
|
||||||
|
delete playlist.data();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QMediaContent)
|
QTEST_MAIN(tst_QMediaContent)
|
||||||
|
|
||||||
#include "tst_qmediacontent.moc"
|
#include "tst_qmediacontent.moc"
|
||||||
|
|||||||
Reference in New Issue
Block a user