[英]Getting mp3 cover art via TagLib using Qt
I'm making an audioplayer for my course project in university. 我正在为大学的课程项目制作音频播放器。 I'm a first-year student, so I'm not a professional programmer.
我是一年级学生,所以我不是专业程序员。
I'm using Qt 5.4 and QtCreator 3.3.1. 我正在使用Qt 5.4和QtCreator 3.3.1。 I've included bass.dll and TagLib libraries to work with audiofiles.
我包括了bass.dll和TagLib库,可用于音频文件。 What am I trying to do is to get the song's cover art and pass it to QLabel (or any other widget if more convenient) on my player's GUI.
我想做的是获取歌曲的封面,并将其传递到播放器GUI上的QLabel(或其他窗口小部件,如果更方便的话)。 I haven't really figured out how to do it.
我还没有真正弄清楚该怎么做。 I've been searching for examples for a while but I always end up in having errors or wrong examples.
我一直在寻找示例,但最终总是遇到错误或错误的示例。 Below is the last code I've tried to use.
以下是我尝试使用的最后一个代码。
TagLib::MPEG::File file(reinterpret_cast<const wchar_t*>(curSong->path.constData()));
TagLib::ID3v2::Tag *m_tag = file.ID3v2Tag(true);
TagLib::ID3v2::FrameList frameList = m_tag->frameList("APIC");
if(frameList.isEmpty()) {
return QImage();
}
TagLib::ID3v2::AttachedPictureFrame *coverImg = static_cast<TagLib::ID3v2::AttachedPictureFrame *>(frameList.front());
QImage coverQImg;
coverQImg.loadFromData((const uchar *) coverImg->picture().data(), coverImg->picture().size());
return coverQImg;
This one doesn't work for me because it causes errors such as 这对我不起作用,因为它会导致诸如
C:\Qt\Projects\audioPlayer\mainwindow.cpp:553: error: undefined reference to `TagLib::List<TagLib::ID3v2::Frame*>::List(TagLib::List<TagLib::ID3v2::Frame*> const&)'
I suppose I've messed up with libraries, but I'm sure I've included id3v2frame.h and id3v2tag.h 我想我已经弄乱了库,但是我确定我已经包含了id3v2frame.h和id3v2tag.h
不知道在哪里找到了id3v3frame.h
(最新版本是id3v2frame.h
),但是TagLib::ID3v2::FrameList
是在id3v2tag.h
声明的。
You may explore a solution with ffmpeg
. 您可以使用
ffmpeg
探索解决方案。
ffmpeg -i input.mp3 -an -vcodec copy cover.jpg
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.