本文整理汇总了C++中taglib::File::audioProperties方法的典型用法代码示例。如果您正苦于以下问题:C++ File::audioProperties方法的具体用法?C++ File::audioProperties怎么用?C++ File::audioProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类taglib::File
的用法示例。
在下文中一共展示了File::audioProperties方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readInfo
bool KMpcPlugin::readInfo( KFileMetaInfo& info, uint what )
{
bool readComment = false;
bool readTech = false;
if (what & (KFileMetaInfo::Fastest |
KFileMetaInfo::DontCare |
KFileMetaInfo::ContentInfo)) readComment = true;
if (what & (KFileMetaInfo::Fastest |
KFileMetaInfo::DontCare |
KFileMetaInfo::TechnicalInfo)) readTech = true;
if ( info.path().isEmpty() ) // remote file
return false;
TagLib::File *file = new TagLib::MPC::File(QFile::encodeName(info.path()).data(), readTech);
if (!file->isOpen())
{
kDebug(7034) << "Couldn't open " << file->name();
delete file;
return false;
}
if(readComment)
{
KFileMetaInfoGroup commentgroup = appendGroup(info, "Comment");
QString date = file->tag()->year() > 0 ? QString::number(file->tag()->year()) : QString();
QString track = file->tag()->track() > 0 ? QString::number(file->tag()->track()) : QString();
appendItem(commentgroup, "Title", TStringToQString(file->tag()->title()).trimmed());
appendItem(commentgroup, "Artist", TStringToQString(file->tag()->artist()).trimmed());
appendItem(commentgroup, "Album", TStringToQString(file->tag()->album()).trimmed());
appendItem(commentgroup, "Date", date);
appendItem(commentgroup, "Comment", TStringToQString(file->tag()->comment()).trimmed());
appendItem(commentgroup, "Tracknumber", track);
appendItem(commentgroup, "Genre", TStringToQString(file->tag()->genre()).trimmed());
}
if (readTech)
{
KFileMetaInfoGroup techgroup = appendGroup(info, "Technical");
TagLib::MPC::Properties *properties =
(TagLib::MPC::Properties*)(file->audioProperties());
appendItem(techgroup, "Bitrate", properties->bitrate());
appendItem(techgroup, "Sample Rate", properties->sampleRate());
appendItem(techgroup, "Channels", properties->channels());
appendItem(techgroup, "Length", properties->length());
appendItem(techgroup, "Version", properties->mpcVersion());
}
delete file;
return true;
}
示例2: processTaglibFile
bool SoundSource::processTaglibFile(TagLib::File& f) {
if (s_bDebugMetadata)
qDebug() << "Parsing" << getFilename();
if (f.isValid()) {
TagLib::Tag *tag = f.tag();
if (tag) {
QString title = TStringToQString(tag->title());
setTitle(title);
QString artist = TStringToQString(tag->artist());
setArtist(artist);
QString album = TStringToQString(tag->album());
setAlbum(album);
QString comment = TStringToQString(tag->comment());
setComment(comment);
QString genre = TStringToQString(tag->genre());
setGenre(genre);
int iYear = tag->year();
QString year = "";
if (iYear > 0) {
year = QString("%1").arg(iYear);
setYear(year);
}
int iTrack = tag->track();
QString trackNumber = "";
if (iTrack > 0) {
trackNumber = QString("%1").arg(iTrack);
setTrackNumber(trackNumber);
}
if (s_bDebugMetadata)
qDebug() << "TagLib" << "title" << title << "artist" << artist << "album" << album << "comment" << comment << "genre" << genre << "year" << year << "trackNumber" << trackNumber;
}
TagLib::AudioProperties *properties = f.audioProperties();
if (properties) {
int lengthSeconds = properties->length();
int bitrate = properties->bitrate();
int sampleRate = properties->sampleRate();
int channels = properties->channels();
if (s_bDebugMetadata)
qDebug() << "TagLib" << "length" << lengthSeconds << "bitrate" << bitrate << "sampleRate" << sampleRate << "channels" << channels;
setDuration(lengthSeconds);
setBitrate(bitrate);
setSampleRate(sampleRate);
setChannels(channels);
}
// If we didn't get any audio properties, this was a failure.
return (properties!=NULL);
}
return false;
}
示例3: di
//Adds dir & its contents to the library
void libraryDialog::addDir2Lib(QDir dir)
{
dir.setFilter(QDir::Files | QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot);
QDirIterator di(dir, QDirIterator::Subdirectories);
while(di.hasNext())
{
di.next();
QString fpath = di.filePath();
QFileInfo f = di.fileInfo();
if(isAudioFile(f))//Add this song to the database
{
wchar_t wname[250]; //TODO: Dynamic. Need to figure out wchar length from QStr length
wname[fpath.toWCharArray(wname)] = 0;
TagLib::FileName fname(wname);
//We'll store tag information in these:
QMap<QString, QString> stmap;
QMap<QString, int> itmap;
TagLib::File* file = NULL;
//MP3 Means we can check for additional info in ID3v2 tags
if(f.suffix() == "mp3")
{
TagLib::MPEG::File* fr = new TagLib::MPEG::File(fname, true, TagLib::AudioProperties::ReadStyle::Fast);
if(fr->ID3v2Tag())
{
//Somehow this means album artist / band. http://www.id3.org/id3v2.4.0-frames
TagLib::ID3v2::FrameList l = fr->ID3v2Tag()->frameList("TPE2");
if(!l.isEmpty())
stmap["albumartist"] = l.front()->toString().toCString();
}
file = dynamic_cast<TagLib::File*>(fr);
}
if(file == NULL)
{
qDebug() << "ERR: " + fpath;
continue; //TODO: Error out here
}
//Try to get audio properties
TagLib::AudioProperties* ap = file->audioProperties();
TagLib::Tag* genTag = file->tag();
stmap["name"] = genTag->title().toCString();
stmap["genre"] = genTag->genre().toCString();
itmap["year"] = genTag->year();
itmap["tracknum"] = genTag->track();
stmap["album"] = genTag->album().toCString();
stmap["artist"] = genTag->artist().toCString();
if(ap != NULL)
itmap["length"] = ap->length();
stmap["path"] = fpath;
//Add collected info to db
DBItem s;
s.strVals = stmap;
s.intVals = itmap;
myparent->dbi->addSong(s);
delete file;
}
else if(f.isDir())
ui.curDirLbl->setText(fpath);
//if(top) //If we're the top level of recursion update prog bar
// ui.progressBar->setValue(di./siz * 100);
qApp->processEvents();
}
}
示例4: readInfo
bool KFlacPlugin::readInfo( KFileMetaInfo& info, uint what )
{
if ( info.path().isEmpty() ) // remote file
return false;
bool readComment = false;
bool readTech = false;
if (what & (KFileMetaInfo::Fastest |
KFileMetaInfo::DontCare |
KFileMetaInfo::ContentInfo)) readComment = true;
if (what & (KFileMetaInfo::Fastest |
KFileMetaInfo::DontCare |
KFileMetaInfo::TechnicalInfo)) readTech = true;
TagLib::File *file = 0;
if (info.mimeType() == "audio/x-flac")
file = new TagLib::FLAC::File(QFile::encodeName(info.path()).data(), readTech);
#ifdef TAGLIB_1_2
else
file = new TagLib::Ogg::FLAC::File(QFile::encodeName(info.path()).data(), readTech);
#endif
if (!file || !file->isValid())
{
kdDebug(7034) << "Couldn't open " << file->name() << endl;
delete file;
return false;
}
if(readComment && file->tag())
{
KFileMetaInfoGroup commentgroup = appendGroup(info, "Comment");
QString date = file->tag()->year() > 0 ? QString::number(file->tag()->year()) : QString::null;
QString track = file->tag()->track() > 0 ? QString::number(file->tag()->track()) : QString::null;
appendItem(commentgroup, "Title", TStringToQString(file->tag()->title()).stripWhiteSpace());
appendItem(commentgroup, "Artist", TStringToQString(file->tag()->artist()).stripWhiteSpace());
appendItem(commentgroup, "Album", TStringToQString(file->tag()->album()).stripWhiteSpace());
appendItem(commentgroup, "Date", date);
appendItem(commentgroup, "Comment", TStringToQString(file->tag()->comment()).stripWhiteSpace());
appendItem(commentgroup, "Tracknumber", track);
appendItem(commentgroup, "Genre", TStringToQString(file->tag()->genre()).stripWhiteSpace());
}
if (readTech && file->audioProperties())
{
KFileMetaInfoGroup techgroup = appendGroup(info, "Technical");
TagLib::FLAC::Properties *properties =
(TagLib::FLAC::Properties*)(file->audioProperties());
appendItem(techgroup, "Bitrate", properties->bitrate());
appendItem(techgroup, "Sample Rate", properties->sampleRate());
appendItem(techgroup, "Sample Width", properties->sampleWidth());
appendItem(techgroup, "Channels", properties->channels());
appendItem(techgroup, "Length", properties->length());
}
delete file;
return true;
}