×
Namespaces

Variants
Actions
Revision as of 07:01, 20 November 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Using Qt Mobility to get metadata from media files

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Tested on: Nokia 5800 XpressMusic
Compatibility
Platform(s): Qt 4.x
Symbian
S60 5th Edition
Article
Keywords: QMediaPlayer, QMediaObject
Created: User:Kbwiki (29 Jun 2010)
Last edited: hamishwillee (20 Nov 2012)

Description

With the QMediaObject::availableMetaData() and QMediaObject::metaData() functions we can retrieve the metadata in a media file (audio/video). The metadata information can be only retrieved while the file is playing.

Qt Mobility APIs are included in the Qt SDK.

Solution

Define the QtMobility/Multimedia configuration in the .pro file:

  CONFIG += mobility
MOBILITY = multimedia

Header files:

  #include <QMediaPlayer>
#include <qtmedianamespace.h>

Implementation:

  // Use QMediaPlayer as a class member
QMediaPlayer *player;
 
// create the player and start playback
player = new QMediaPlayer(this);
player->setMedia(QUrl::fromLocalFile("C:\\Data\\sample.mp3"));
player->setVolume( 25 );
player->play();

A method to get the metadata of the media file:

  void MediaMetaDataExample::GetMetaData()
{
// Get the list of keys there is metadata available for
QList<QtMediaServices::MetaData> metadatalist = player->availableMetaData();
 
// Get the size of the list
int list_size = metadatalist.size();
 
// Define variables to store metadata key and value
QtMediaServices::MetaData metadata_key;
QVariant var_data;
 
for (int indx = 0; indx < list_size; indx++) {
// Get the key from the list
metadata_key = metadatalist.at(indx);
 
// Get the value for the key
var_data = player->metaData(metadata_key);
 
switch(metadata_key) {
case QtMediaServices::Title:
// Retrieve title (using var_data.toString())
break;
case QtMediaServices::SubTitle:
// Retrieve subtitle
break;
case QtMediaServices::Author:
// Retrieve author
break;
 
// ... see QtMediaServices for rest of the values
 
default:
break;
}
}
}

A method to get the extended metadata of the media file:

  void MediaMetaDataExample::GetExtendedMetaData()
{
// Retrieve extended metadata key list
QStringList extn_metadata = player->availableExtendedMetaData();
int count_extn = extn_metadata.count();
QString extn_metadata_key;
QVariant extn_metadata_value;
for( int indx = 0; indx < count_extn; indx++ )
{
extn_metadata_key = extn_metadata.at(indx);
extn_metadata_value = player->extendedMetaData(extn_metadata_key);
 
// Process extended metadata here
// Need to convert QVariant into proper type
}
}

This page was last modified on 20 November 2012, at 07:01.
128 page views in the last 30 days.