summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@qt.io>2016-08-17 13:55:10 +0200
committerYoann Lopes <yoann.lopes@qt.io>2016-09-27 11:11:12 +0000
commit81a48edb548a9ad86414b3a115d718c932c11058 (patch)
tree762c905f5ebdbaa980c7b5090cf4404288926631
parentc4bf444f5cf71518fb52bc4f19515a9a662a107d (diff)
AVFoundation: fix metadata control
Correctly emit metaDataAvailableChanged and metaDataChanged signals. Task-number: QTBUG-46368 Change-Id: Ic79acd519b47f4d864fa335c8f75758fe9185c39 Reviewed-by: Christian Stromme <christian.stromme@qt.io>
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfmediaplayermetadatacontrol.h2
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfmediaplayermetadatacontrol.mm110
2 files changed, 59 insertions, 53 deletions
diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayermetadatacontrol.h b/src/plugins/avfoundation/mediaplayer/avfmediaplayermetadatacontrol.h
index d40e70c2..e28fc293 100644
--- a/src/plugins/avfoundation/mediaplayer/avfmediaplayermetadatacontrol.h
+++ b/src/plugins/avfoundation/mediaplayer/avfmediaplayermetadatacontrol.h
@@ -58,7 +58,7 @@ private Q_SLOTS:
private:
AVFMediaPlayerSession *m_session;
- QMap<QString, QVariant> m_tags;
+ QVariantMap m_tags;
void *m_asset;
};
diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayermetadatacontrol.mm b/src/plugins/avfoundation/mediaplayer/avfmediaplayermetadatacontrol.mm
index 336f8637..b84ff595 100644
--- a/src/plugins/avfoundation/mediaplayer/avfmediaplayermetadatacontrol.mm
+++ b/src/plugins/avfoundation/mediaplayer/avfmediaplayermetadatacontrol.mm
@@ -75,6 +75,41 @@ QStringList AVFMediaPlayerMetaDataControl::availableMetaData() const
return m_tags.keys();
}
+static QString itemKey(AVMetadataItem *item)
+{
+ NSString *keyString = [item commonKey];
+
+ if (keyString.length != 0) {
+ if ([keyString isEqualToString:AVMetadataCommonKeyTitle]) {
+ return QMediaMetaData::Title;
+ } else if ([keyString isEqualToString: AVMetadataCommonKeySubject]) {
+ return QMediaMetaData::SubTitle;
+ } else if ([keyString isEqualToString: AVMetadataCommonKeyDescription]) {
+ return QMediaMetaData::Description;
+ } else if ([keyString isEqualToString: AVMetadataCommonKeyPublisher]) {
+ return QMediaMetaData::Publisher;
+ } else if ([keyString isEqualToString: AVMetadataCommonKeyCreationDate]) {
+ return QMediaMetaData::Date;
+ } else if ([keyString isEqualToString: AVMetadataCommonKeyType]) {
+ return QMediaMetaData::MediaType;
+ } else if ([keyString isEqualToString: AVMetadataCommonKeyLanguage]) {
+ return QMediaMetaData::Language;
+ } else if ([keyString isEqualToString: AVMetadataCommonKeyCopyrights]) {
+ return QMediaMetaData::Copyright;
+ } else if ([keyString isEqualToString: AVMetadataCommonKeyAlbumName]) {
+ return QMediaMetaData::AlbumTitle;
+ } else if ([keyString isEqualToString: AVMetadataCommonKeyAuthor]) {
+ return QMediaMetaData::Author;
+ } else if ([keyString isEqualToString: AVMetadataCommonKeyArtist]) {
+ return QMediaMetaData::ContributingArtist;
+ } else if ([keyString isEqualToString: AVMetadataCommonKeyArtwork]) {
+ return QMediaMetaData::PosterUrl;
+ }
+ }
+
+ return QString();
+}
+
void AVFMediaPlayerMetaDataControl::updateTags()
{
#ifdef QT_DEBUG_AVF
@@ -83,67 +118,38 @@ void AVFMediaPlayerMetaDataControl::updateTags()
AVAsset *currentAsset = (AVAsset*)m_session->currentAssetHandle();
//Don't read the tags from the same asset more than once
- if (currentAsset == m_asset) {
+ if (currentAsset == m_asset)
return;
- }
m_asset = currentAsset;
+ QVariantMap oldTags = m_tags;
//Since we've changed assets, clear old tags
m_tags.clear();
-
- NSArray *metadataFormats = [currentAsset availableMetadataFormats];
- for ( NSString *format in metadataFormats) {
-#ifdef QT_DEBUG_AVF
- qDebug() << "format: " << [format UTF8String];
-#endif
- NSArray *metadataItems = [currentAsset metadataForFormat:format];
- for (AVMetadataItem* item in metadataItems) {
- NSString *keyString = [item commonKey];
- NSString *value = [item stringValue];
-
- if (keyString.length != 0) {
- //Process "commonMetadata" tags here:
- if ([keyString isEqualToString:AVMetadataCommonKeyTitle]) {
- m_tags.insert(QMediaMetaData::Title, QString([value UTF8String]));
- } else if ([keyString isEqualToString: AVMetadataCommonKeyCreator]) {
- m_tags.insert(QMediaMetaData::Author, QString([value UTF8String]));
- } else if ([keyString isEqualToString: AVMetadataCommonKeySubject]) {
- m_tags.insert(QMediaMetaData::SubTitle, QString([value UTF8String]));
- } else if ([keyString isEqualToString: AVMetadataCommonKeyDescription]) {
- m_tags.insert(QMediaMetaData::Description, QString([value UTF8String]));
- } else if ([keyString isEqualToString: AVMetadataCommonKeyPublisher]) {
- m_tags.insert(QMediaMetaData::Publisher, QString([value UTF8String]));
- } else if ([keyString isEqualToString: AVMetadataCommonKeyContributor]) {
- m_tags.insert(QMediaMetaData::ContributingArtist, QString([value UTF8String]));
- } else if ([keyString isEqualToString: AVMetadataCommonKeyCreationDate]) {
- m_tags.insert(QMediaMetaData::Date, QString([value UTF8String]));
- } else if ([keyString isEqualToString: AVMetadataCommonKeyType]) {
- m_tags.insert(QMediaMetaData::MediaType, QString([value UTF8String]));
- } else if ([keyString isEqualToString: AVMetadataCommonKeyLanguage]) {
- m_tags.insert(QMediaMetaData::Language, QString([value UTF8String]));
- } else if ([keyString isEqualToString: AVMetadataCommonKeyCopyrights]) {
- m_tags.insert(QMediaMetaData::Copyright, QString([value UTF8String]));
- } else if ([keyString isEqualToString: AVMetadataCommonKeyAlbumName]) {
- m_tags.insert(QMediaMetaData::AlbumTitle, QString([value UTF8String]));
- } else if ([keyString isEqualToString: AVMetadataCommonKeyAuthor]) {
- m_tags.insert(QMediaMetaData::Author, QString([value UTF8String]));
- } else if ([keyString isEqualToString: AVMetadataCommonKeyArtist]) {
- m_tags.insert(QMediaMetaData::AlbumArtist, QString([value UTF8String]));
- } else if ([keyString isEqualToString: AVMetadataCommonKeyArtwork]) {
- m_tags.insert(QMediaMetaData::PosterUrl, QString([value UTF8String]));
+ bool changed = false;
+
+ // TODO: also process ID3, iTunes and QuickTime metadata
+
+ NSArray *metadataItems = [currentAsset commonMetadata];
+ for (AVMetadataItem* item in metadataItems) {
+ const QString key = itemKey(item);
+ if (!key.isEmpty()) {
+ const QString value = QString::fromNSString([item stringValue]);
+ if (!value.isNull()) {
+ m_tags.insert(key, value);
+ if (value != oldTags.value(key)) {
+ changed = true;
+ Q_EMIT metaDataChanged(key, value);
}
}
-
- if ([format isEqualToString:AVMetadataFormatID3Metadata]) {
- //TODO: Process ID3 metadata
- } else if ([format isEqualToString:AVMetadataFormatiTunesMetadata]) {
- //TODO: Process iTunes metadata
- } else if ([format isEqualToString:AVMetadataFormatQuickTimeUserData]) {
- //TODO: Process QuickTime metadata
- }
}
}
- Q_EMIT metaDataChanged();
+ if (oldTags.isEmpty() != m_tags.isEmpty()) {
+ Q_EMIT metaDataAvailableChanged(!m_tags.isEmpty());
+ changed = true;
+ }
+
+ if (changed)
+ Q_EMIT metaDataChanged();
}