本文整理汇总了C++中taglib::mpeg::File类的典型用法代码示例。如果您正苦于以下问题:C++ File类的具体用法?C++ File怎么用?C++ File使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了File类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OpenFile
bool MetaIOID3::writeVolatileMetadata(const Metadata* mdata)
{
QString filename = mdata->Filename();
int rating = mdata->Rating();
int playcount = mdata->PlayCount();
TagLib::MPEG::File *mpegfile = OpenFile(filename);
if (!mpegfile)
return false;
TagLib::ID3v2::Tag *tag = mpegfile->ID3v2Tag();
if (!tag)
{
delete mpegfile;
return false;
}
bool result = (writeRating(tag, rating) && writePlayCount(tag, playcount));
mpegfile->save();
delete mpegfile;
return result;
}
示例2: rating
/** Convert the existing rating number into a smaller range from 1 to 5. */
int FileHelper::rating() const
{
int r = -1;
/// TODO other types?
switch (_fileType) {
case EXT_MP3: {
TagLib::MPEG::File *mpegFile = static_cast<TagLib::MPEG::File*>(_file);
if (mpegFile && mpegFile->hasID3v2Tag()) {
r = this->ratingForID3v2(mpegFile->ID3v2Tag());
}
break;
}
case EXT_FLAC: {
if (TagLib::FLAC::File *flacFile = static_cast<TagLib::FLAC::File*>(_file)) {
if (flacFile->hasID3v2Tag()) {
r = this->ratingForID3v2(flacFile->ID3v2Tag());
} else if (flacFile->hasID3v1Tag()) {
qDebug() << Q_FUNC_INFO << "Not implemented (FLAC ID3v1)";
} else if (flacFile->hasXiphComment()) {
TagLib::StringList list = flacFile->xiphComment()->fieldListMap()["RATING"];
if (!list.isEmpty()) {
r = list.front().toInt();
}
}
}
break;
}
default:
break;
}
return r;
}
示例3: on_pushOpenFolder_clicked
void MainWindow::on_pushOpenFolder_clicked()
{
m_notUsed.clear();
QString dir = QFileDialog::getExistingDirectory(this, tr("Open MP3 Source Directory"),
pSet->value("src_dir").toString(), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if (!dir.isEmpty())
{
pSet->setValue("src_dir", dir);
ui->lineSrcFolder->setText(dir);
cleanTags();
QDir mp3Dir(dir, "*.mp3");
QStringList files = mp3Dir.entryList();
TagLib::MPEG::File* ptlFile;
foreach (QString file, files)
{
QString path = QString("%1/%2").arg(mp3Dir.absolutePath()).arg(file);
ptlFile = new TagLib::MPEG::File(reinterpret_cast<const wchar_t *>(path.utf16()));
if (ptlFile && ptlFile->isOpen())
{
tagFiles.append(ptlFile);
}
else if(ptlFile)
{
m_notUsed.append(path);
delete ptlFile;
}
}
示例4: setRating
/** Set or remove any rating. */
void FileHelper::setRating(int rating)
{
switch (_fileType) {
case EXT_MP3: {
TagLib::MPEG::File *mpegFile = static_cast<TagLib::MPEG::File*>(_file);
if (mpegFile->hasID3v2Tag()) {
this->setRatingForID3v2(rating, mpegFile->ID3v2Tag());
} else if (mpegFile->hasID3v1Tag()) {
qDebug() << Q_FUNC_INFO << "Not implemented for ID3v1Tag";
}
break;
}
case EXT_FLAC: {
TagLib::FLAC::File *flacFile = static_cast<TagLib::FLAC::File*>(_file);
if (flacFile->hasID3v2Tag()) {
this->setRatingForID3v2(rating, flacFile->ID3v2Tag());
} else if (flacFile->hasID3v1Tag()) {
qDebug() << Q_FUNC_INFO << "hasID3v1Tag";
} else if (flacFile->hasXiphComment()) {
TagLib::Ogg::XiphComment *xiph = flacFile->xiphComment();
if (rating == 0) {
xiph->removeField("RATING");
} else {
xiph->addField("RATING", QString::number(rating).toStdString());
}
}
break;
}
default:
break;
}
this->save();
}
示例5: QImage
/*!
* \brief Read the albumart image from the file
*
* \param filename The filename for which we want to find the length.
* \param type The type of image we want - front/back etc
* \returns A pointer to a QImage owned by the caller or NULL if not found.
*/
QImage* MetaIOID3::getAlbumArt(QString filename, ImageType type)
{
QImage *picture = new QImage();
AttachedPictureFrame::Type apicType
= AttachedPictureFrame::FrontCover;
switch (type)
{
case IT_UNKNOWN :
apicType = AttachedPictureFrame::Other;
break;
case IT_FRONTCOVER :
apicType = AttachedPictureFrame::FrontCover;
break;
case IT_BACKCOVER :
apicType = AttachedPictureFrame::BackCover;
break;
case IT_CD :
apicType = AttachedPictureFrame::Media;
break;
case IT_INLAY :
apicType = AttachedPictureFrame::LeafletPage;
break;
default:
return picture;
}
QByteArray fname = filename.toLocal8Bit();
TagLib::MPEG::File *mpegfile = new TagLib::MPEG::File(fname.constData());
if (mpegfile)
{
if (mpegfile->isOpen()
&& !mpegfile->ID3v2Tag()->frameListMap()["APIC"].isEmpty())
{
TagLib::ID3v2::FrameList apicframes =
mpegfile->ID3v2Tag()->frameListMap()["APIC"];
for(TagLib::ID3v2::FrameList::Iterator it = apicframes.begin();
it != apicframes.end(); ++it)
{
AttachedPictureFrame *frame =
static_cast<AttachedPictureFrame *>(*it);
if (frame && frame->type() == apicType)
{
picture->loadFromData((const uchar *)frame->picture().data(),
frame->picture().size());
return picture;
}
}
}
delete mpegfile;
}
delete picture;
return NULL;
}
示例6: hasCover
/** Check if file has an inner picture. */
bool FileHelper::hasCover() const
{
bool atLeastOnePicture = false;
switch (_fileType) {
case EXT_MP3: {
TagLib::MPEG::File *mpegFile = static_cast<TagLib::MPEG::File*>(_file);
if (mpegFile && mpegFile->hasID3v2Tag()) {
// Look for picture frames only
TagLib::ID3v2::FrameList listOfMp3Frames = mpegFile->ID3v2Tag()->frameListMap()["APIC"];
// It's possible to have more than one picture per file!
if (!listOfMp3Frames.isEmpty()) {
for (TagLib::ID3v2::FrameList::ConstIterator it = listOfMp3Frames.begin(); it != listOfMp3Frames.end() ; it++) {
// Cast a Frame* to AttachedPictureFrame*
TagLib::ID3v2::AttachedPictureFrame *pictureFrame = static_cast<TagLib::ID3v2::AttachedPictureFrame*>(*it);
atLeastOnePicture = atLeastOnePicture || (pictureFrame != nullptr && !pictureFrame->picture().isEmpty());
}
}
}
break;
}
case EXT_FLAC: {
if (TagLib::FLAC::File *flacFile = static_cast<TagLib::FLAC::File*>(_file)) {
atLeastOnePicture = !flacFile->pictureList().isEmpty();
}
}
default:
break;
}
return atLeastOnePicture;
}
示例7:
/**
* When make sure an apetag is there, so that saving a mp3 file back
* can include apetags too.
*
* This is needed, since taglib will only create apetags in mp3 files
* if that is explicitly requested.
*
* Only use this for FT_MPEG files. Other types may not have the required
* method, which will cause fatal problems.
*
* @param file TagLib_File pointer to the mp3 in question.
*
* @return void
* @sideeffects none
*/
void
mp3_dotheape(TagLib_File *file)
{
TagLib::MPEG::File *f;
f = reinterpret_cast<TagLib::MPEG::File *>(file);
f->APETag(true);
}
示例8: switch
/*!
* \brief Remove the albumart image from the file
*
* \param filename The music file to remove the albumart
* \param albumart The Album Art image to remove
* \returns True if successful
*/
bool MetaIOID3::removeAlbumArt(const QString &filename, const AlbumArtImage *albumart)
{
if (filename.isEmpty() || !albumart)
return false;
AttachedPictureFrame::Type type = AttachedPictureFrame::Other;
switch (albumart->imageType)
{
case IT_FRONTCOVER:
type = AttachedPictureFrame::FrontCover;
break;
case IT_BACKCOVER:
type = AttachedPictureFrame::BackCover;
break;
case IT_CD:
type = AttachedPictureFrame::Media;
break;
case IT_INLAY:
type = AttachedPictureFrame::LeafletPage;
break;
default:
type = AttachedPictureFrame::Other;
break;
}
TagLib::MPEG::File *mpegfile = OpenFile(filename);
if (!mpegfile)
return false;
TagLib::ID3v2::Tag *tag = mpegfile->ID3v2Tag();
if (!tag)
{
delete mpegfile;
return false;
}
AttachedPictureFrame *apic = findAPIC(tag, type, QStringToTString(albumart->description));
if (!apic)
{
delete mpegfile;
return false;
}
tag->removeFrame(apic);
mpegfile->save();
delete mpegfile;
return true;
}
示例9:
/*!
* \brief Open the file to read the tag
*
* \param filename The filename
* \returns A taglib file object for this format
*/
TagLib::MPEG::File *MetaIOID3::OpenFile(const QString &filename)
{
QByteArray fname = filename.toLocal8Bit();
TagLib::MPEG::File *mpegfile = new TagLib::MPEG::File(fname.constData());
if (!mpegfile->isOpen())
{
delete mpegfile;
mpegfile = NULL;
}
return mpegfile;
}
示例10: save
bool FileHelper::save()
{
if (_fileType == EXT_MP3) {
TagLib::MPEG::File *mpegFile = static_cast<TagLib::MPEG::File*>(_file);
// TagLib updates tags with the latest version (ID3v2.4)
// We just want to save the file with the exact same version!
if (mpegFile->hasID3v2Tag()) {
return mpegFile->save(TagLib::MPEG::File::AllTags, false, mpegFile->ID3v2Tag()->header()->majorVersion());
}
} else if (_fileType != EXT_UNKNOWN) {
return _file->save();
}
return false;
}
示例11: strip
void
MetaBundle::readTags( TagLib::AudioProperties::ReadStyle readStyle )
{
if( m_url.protocol() != "file" )
return;
const QString path = m_url.path();
TagLib::FileRef fileref;
TagLib::Tag *tag = 0;
if( AmarokConfig::recodeID3v1Tags() && path.endsWith( ".mp3", false ) )
{
TagLib::MPEG::File *mpeg = new TagLib::MPEG::File( QFile::encodeName( path ), true, readStyle );
fileref = TagLib::FileRef( mpeg );
if( mpeg->isValid() )
// we prefer ID3v1 over ID3v2 if recoding tags because
// apparently this is what people who ignore ID3 standards want
tag = mpeg->ID3v1Tag() ? (TagLib::Tag*)mpeg->ID3v1Tag() : (TagLib::Tag*)mpeg->ID3v2Tag();
}
else {
fileref = TagLib::FileRef( QFile::encodeName( path ), true, readStyle );
if( !fileref.isNull() )
tag = fileref.tag();
}
if( !fileref.isNull() ) {
if ( tag ) {
#define strip( x ) TStringToQString( x ).stripWhiteSpace()
m_title = strip( tag->title() );
m_artist = strip( tag->artist() );
m_album = strip( tag->album() );
m_comment = strip( tag->comment() );
m_genre = strip( tag->genre() );
m_year = tag->year() ? QString::number( tag->year() ) : QString();
m_track = tag->track() ? QString::number( tag->track() ) : QString();
#undef strip
m_isValidMedia = true;
}
init( fileref.audioProperties() );
}
//FIXME disabled for beta4 as it's simpler to not got 100 bug reports
//else if( KMimeType::findByUrl( m_url )->is( "audio" ) )
// init( KFileMetaInfo( m_url, QString::null, KFileMetaInfo::Everything ) );
}
示例12: TStringToQString
TagLib::Tag *mttFile::getTag( bool create )
{
if ( tag == NULL ) {
fileref = new TagLib::FileRef( QFile::encodeName( fname ).constData() );
if ( fileref ) {
if ( ismpeg ) {
TagLib::MPEG::File *f = dynamic_cast<TagLib::MPEG::File *>(fileref->file());
tag = new TagLib::ID3v2::Tag();
if ( f->ID3v2Tag( create ) != NULL ) {
TagLib::Tag::duplicate( dynamic_cast<TagLib::Tag *>( f->ID3v2Tag( create ) ), tag, true );
// Read extra mp3 tags
int i;
for ( i = 0; i < EF_NUM; i++ ) {
TagLib::ID3v2::FrameList l = f->ID3v2Tag()->frameListMap()[extraFrames[i][0]];
if ( !l.isEmpty() ) {
mp3eframes += extraFrames[i][0];
mp3eframes += TStringToQString( l.front()->toString() );
}
}
}
delete fileref;
fileref = NULL;
return tag;
}
else { // If the file is ogg or flac
tag = new TagLib::Ogg::XiphComment();
if ( fileref->tag() ) // If a tag already exists
TagLib::Tag::duplicate( fileref->tag(), tag, true );
delete fileref;
fileref = NULL;
return tag;
}
}
else {
//qDebug( "fileref = NULL" );
return NULL;
}
delete fileref;
fileref = NULL;
}
else
return tag;
}
示例13: setArtistAlbum
void FileHelper::setArtistAlbum(const QString &artistAlbum)
{
switch (_fileType) {
case EXT_FLAC: {
this->setFlacAttribute("ALBUMARTIST", artistAlbum);
break;
}
case EXT_MP4:{
TagLib::StringList l;
l.append(artistAlbum.toStdString().data());
TagLib::MP4::Item item(l);
this->setMp4Attribute("aART", item);
break;
}
case EXT_MPC:
//mpcFile = static_cast<MPC::File*>(f);
qDebug() << Q_FUNC_INFO << "Not implemented for MPC";
break;
case EXT_MP3:{
TagLib::MPEG::File *mpegFile = static_cast<TagLib::MPEG::File*>(_file);
if (mpegFile->hasID3v2Tag()) {
TagLib::ID3v2::Tag *tag = mpegFile->ID3v2Tag();
QString convertedKey = this->convertKeyToID3v2Key("ARTISTALBUM");
TagLib::ID3v2::FrameList l = tag->frameListMap()[convertedKey.toStdString().data()];
if (!l.isEmpty()) {
tag->removeFrame(l.front());
}
TagLib::ID3v2::TextIdentificationFrame *tif = new TagLib::ID3v2::TextIdentificationFrame(TagLib::ByteVector(convertedKey.toStdString().data()));
tif->setText(artistAlbum.toStdString().data());
tag->addFrame(tif);
} else if (mpegFile->hasID3v1Tag()) {
qDebug() << Q_FUNC_INFO << "Not implemented for ID3v1Tag";
}
break;
}
case EXT_OGG: {
TagLib::Ogg::XiphComment *xiphComment = static_cast<TagLib::Ogg::XiphComment*>(_file->tag());
if (xiphComment) {
xiphComment->addField("ALBUMARTIST", artistAlbum.toStdString().data());
} else {
qDebug() << Q_FUNC_INFO << "Not implemented for this OGG file";
}
break;
}
default:
qDebug() << Q_FUNC_INFO << "Not implemented for this type of file";
break;
}
}
示例14: GetComposer
bool CCover::GetComposer(TagLib::FileRef& fr, std::string& composer)
{
TagLib::MPEG::File * mpgfile = NULL;
TagLib::Ogg::Vorbis::File * oggfile = NULL;
TagLib::FLAC::File * flacfile = NULL;
TagLib::Ogg::XiphComment * xiph = NULL;
TagLib::ID3v2::Tag * id3v2 = NULL;
#ifdef TAGLIB_HAVE_MP4
TagLib::MP4::File * mp4file = NULL;
TagLib::MP4::Tag * mp4 = NULL;
#endif
if ((oggfile = dynamic_cast<TagLib::Ogg::Vorbis::File*>(fr.file()))) {
xiph=oggfile->tag();
//log_debug("ogg");
} else if ((flacfile = dynamic_cast<TagLib::FLAC::File*>(fr.file()))) {
xiph=flacfile->xiphComment();
id3v2=flacfile->ID3v2Tag();
//log_debug("flac");
} else if ((mpgfile = dynamic_cast<TagLib::MPEG::File*>(fr.file()))) {
id3v2=mpgfile->ID3v2Tag();
//log_debug("mpg");
}
#ifdef TAGLIB_HAVE_MP4
else if ((mp4file = dynamic_cast<TagLib::MP4::File*>(fr.file()))) {
mp4=mp4file->tag();
}
#endif
#ifndef TAGLIB_HAVE_MP4
void* mp4 = NULL;
#endif
//log_debug4("xiph=%p, id3v2=%p, mp4=%p", xiph, id3v2, mp4);
bool retval = true;
if (xiph)
retval = xiph_get_field(xiph, "COMPOSER",composer);
else if (id3v2)
retval = id3v2_get_field(id3v2, "TCOM",composer);
#ifdef TAGLIB_HAVE_MP4
else if (mp4)
retval = mp4_get_field(mp4file, "\251wrt",composer);
#endif
else
retval = false;
//log_debug2("composer = %s", composer.c_str());
return retval;
}
示例15: addImage
bool CTagBase::addImage(wchar_t* s)
{
if (!_tagFile) return false;
TagLib::MPEG::File *pAudioFile = (TagLib::MPEG::File *)_tagFile.get();
CString strFileName = s;
ImageFile imageFile((CW2A)strFileName.GetBuffer());
if (!pAudioFile->isValid() || !imageFile.isValid())
return false;
TagLib::ID3v2::Tag *tag = pAudioFile->ID3v2Tag(true);
TagLib::ID3v2::AttachedPictureFrame *frame = new TagLib::ID3v2::AttachedPictureFrame;
frame->setMimeType(imageFile.mimeType());
frame->setPicture(imageFile.data());
tag->addFrame(frame);
return pAudioFile->save();
}