Mercurial > hg > svcore
diff data/fileio/MP3FileReader.cpp @ 271:822bd7fd526c
* Add support for reading mp3 and Ogg file title tags
author | Chris Cannam |
---|---|
date | Mon, 02 Jul 2007 13:53:38 +0000 |
parents | e08f486e8d8c |
children | f1f47660483d |
line wrap: on
line diff
--- a/data/fileio/MP3FileReader.cpp Tue Jun 26 12:27:47 2007 +0000 +++ b/data/fileio/MP3FileReader.cpp Mon Jul 02 13:53:38 2007 +0000 @@ -25,6 +25,10 @@ #include <iostream> +#ifdef HAVE_ID3TAG +#include <id3tag.h> +#endif + #include <QApplication> #include <QFileInfo> #include <QProgressDialog> @@ -95,6 +99,8 @@ ::close(fd); + loadTags(); + if (decodeMode == DecodeAtOnce) { m_progress = new QProgressDialog @@ -135,6 +141,43 @@ } void +MP3FileReader::loadTags() +{ + m_title = ""; + +#ifdef HAVE_ID3TAG + + id3_file *file = id3_file_open(m_path.toLocal8Bit().data(), + ID3_FILE_MODE_READONLY); + if (!file) return; + + id3_tag *tag = id3_file_tag(file); + + if (tag) { + id3_frame *frame = id3_tag_findframe(tag, "TIT2", 0); // work title + + if (frame && frame->nfields >= 2) { + unsigned int nstrings = id3_field_getnstrings(&frame->fields[1]); + + if (nstrings > 0) { + id3_ucs4_t const *ustr = id3_field_getstrings(&frame->fields[1], 0); + + if (ustr) { + id3_utf8_t *u8str = id3_ucs4_utf8duplicate(ustr); + if (u8str) { + m_title = QString::fromUtf8((const char *)u8str); + free(u8str); + } + } + } + } + } + + id3_file_close(file); +#endif +} + +void MP3FileReader::DecodeThread::run() { if (!m_reader->decode(m_reader->m_filebuffer, m_reader->m_fileSize)) {