- audioplayer: show cover from id3-tag or folder.jpg in header

if exist a file called folder.jpg in same dir as the audiofile
  or a audiocover is defined in id3-tag it will be displayed in header.

  cover in tag is preferred.

  ported from mohusch. original patch by tangocash. thx!
This commit is contained in:
svenhoefer
2013-11-09 18:34:09 +01:00
parent 1e8764be2e
commit fe07423ad1
5 changed files with 103 additions and 3 deletions

View File

@@ -944,6 +944,7 @@ bool CMP3Dec::GetMetaData(FILE* in, const bool nice, CAudioMetaData* const m)
{ {
res = GetMP3Info(in, nice, m); res = GetMP3Info(in, nice, m);
GetID3(in, m); GetID3(in, m);
SaveCover(in, m);
} }
else else
{ {
@@ -1344,6 +1345,82 @@ void CMP3Dec::GetID3(FILE* in, CAudioMetaData* const m)
} }
} }
bool CMP3Dec::SaveCover(FILE * in, CAudioMetaData * const m)
{
struct id3_frame const *frame;
const char * coverfile = "/tmp/cover.jpg";
/* text information */
struct id3_file *id3file = id3_file_fdopen(fileno(in), ID3_FILE_MODE_READONLY);
if(id3file == 0)
{
printf("CMP3Dec::SaveCover: error open id3 file\n");
return false;
}
else
{
id3_tag * tag = id3_file_tag(id3file);
if(tag)
{
frame = id3_tag_findframe(tag, "APIC", 0);
if (frame)
{
printf("CMP3Dec::SaveCover: Cover found\n");
// Picture file data
unsigned int j;
union id3_field const *field;
for (j = 0; (field = id3_frame_field(frame, j)); j++)
{
switch (id3_field_type(field))
{
case ID3_FIELD_TYPE_BINARYDATA:
id3_length_t size;
id3_byte_t const *data;
data = id3_field_getbinarydata(field, &size);
if ( data )
{
m->cover = coverfile;
FILE * pFile;
pFile = fopen ( coverfile , "wb" );
fwrite (data , 1 , size , pFile );
fclose (pFile);
}
break;
case ID3_FIELD_TYPE_INT8:
//pic->type = id3_field_getint(field);
break;
default:
break;
}
}
}
id3_tag_delete(tag);
}
else
{
printf("CMP3Dec::SaveCover: error open id3 tag\n");
return false;
}
id3_finish_file(id3file);
}
if(0)
{
printf("CMP3Dec::SaveCover:id3: not enough memory to display tag\n");
return false;
}
return true;
}
// this is a copy of static libid3tag function "finish_file" // this is a copy of static libid3tag function "finish_file"
// which cannot be called from outside // which cannot be called from outside
void id3_finish_file(struct id3_file* file) void id3_finish_file(struct id3_file* file)

View File

@@ -73,6 +73,7 @@ public:
State* const state, CAudioMetaData* m, State* const state, CAudioMetaData* m,
time_t* const t, unsigned int* const secondsToSkip); time_t* const t, unsigned int* const secondsToSkip);
bool GetMetaData(FILE *in, const bool nice, CAudioMetaData* const m); bool GetMetaData(FILE *in, const bool nice, CAudioMetaData* const m);
bool SaveCover(FILE*, CAudioMetaData * const m);
CMP3Dec(){}; CMP3Dec(){};
}; };

View File

@@ -51,7 +51,7 @@ CAudioMetaData::CAudioMetaData( const CAudioMetaData& src )
audio_start_pos( src.audio_start_pos ), vbr( src.vbr ), audio_start_pos( src.audio_start_pos ), vbr( src.vbr ),
hasInfoOrXingTag( src.hasInfoOrXingTag ), artist( src.artist ), hasInfoOrXingTag( src.hasInfoOrXingTag ), artist( src.artist ),
title( src.title ), album( src.album ), sc_station( src.sc_station ), title( src.title ), album( src.album ), sc_station( src.sc_station ),
date( src.date ), genre( src.genre ), track( src.track ), date( src.date ), genre( src.genre ), track( src.track ),cover(src.cover),
changed( src.changed ) changed( src.changed )
{ {
} }
@@ -81,6 +81,7 @@ void CAudioMetaData::operator=( const CAudioMetaData& src )
date = src.date; date = src.date;
genre = src.genre; genre = src.genre;
track = src.track; track = src.track;
cover = src.cover;
sc_station = src.sc_station; sc_station = src.sc_station;
changed = src.changed; changed = src.changed;
} }
@@ -104,5 +105,6 @@ void CAudioMetaData::clear()
date.clear(); date.clear();
genre.clear(); genre.clear();
track.clear(); track.clear();
cover.clear();
changed=false; changed=false;
} }

View File

@@ -84,6 +84,7 @@ public:
std::string date; std::string date;
std::string genre; std::string genre;
std::string track; std::string track;
std::string cover;
bool changed; bool changed;
}; };
#endif /* __AUDIO_METADATA__ */ #endif /* __AUDIO_METADATA__ */

View File

@@ -66,6 +66,7 @@
#include <gui/widget/stringinput_ext.h> #include <gui/widget/stringinput_ext.h>
#include "gui/pictureviewer.h" #include "gui/pictureviewer.h"
extern CPictureViewer * g_PicViewer;
#include <system/settings.h> #include <system/settings.h>
#include <system/helpers.h> #include <system/helpers.h>
@@ -2169,6 +2170,25 @@ void CAudioPlayerGui::updateMetaData(bool screen_saver)
m_curr_audiofile.MetaData.album = meta.sc_station; m_curr_audiofile.MetaData.album = meta.sc_station;
updateLcd = true; updateLcd = true;
} }
std::string cover = m_curr_audiofile.Filename.substr(0, m_curr_audiofile.Filename.rfind('/')) + "/folder.jpg";
if (!meta.cover.empty())
cover = "/tmp/cover.jpg";
if ((access(cover.c_str(), F_OK) == 0) && !screen_saver)
{
g_PicViewer->DisplayImage(cover, m_x + 2, m_y + 2, m_title_height - 14, m_title_height - 14, m_frameBuffer->TM_NONE);
if(g_settings.rounded_corners)
{
//repaint frame to cover up the corners of the cover; FIXME
if (!m_show_playlist)
m_frameBuffer->paintBoxFrame(m_x, m_y, m_width, m_title_height - 10 - m_fheight, 2, COL_MENUCONTENT_PLUS_6, RADIUS_MID);
else
m_frameBuffer->paintBoxFrame(m_x, m_y, m_width, m_title_height - 10, 2, COL_MENUCONTENT_PLUS_6, RADIUS_MID);
}
}
} }
//if (CAudioPlayer::getInstance()->getScBuffered() != 0) //if (CAudioPlayer::getInstance()->getScBuffered() != 0)
if (CAudioPlayer::getInstance()->hasMetaDataChanged() != 0) if (CAudioPlayer::getInstance()->hasMetaDataChanged() != 0)
@@ -2183,8 +2203,7 @@ void CAudioPlayerGui::updateMetaData(bool screen_saver)
if (updateMeta || updateScreen) if (updateMeta || updateScreen)
{ {
m_frameBuffer->paintBoxRel(m_x + 10, m_y + 4 + 2*m_fheight, m_width - 20, m_frameBuffer->paintBoxRel(m_x + 10 + m_title_height, m_y + 4 + 2*m_fheight, m_width - 20 - m_title_height, m_sheight, COL_MENUCONTENTSELECTED_PLUS_0);
m_sheight, COL_MENUCONTENTSELECTED_PLUS_0);
int xstart = ((m_width - 20 - g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getRenderWidth(m_metainfo))/2)+10; int xstart = ((m_width - 20 - g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getRenderWidth(m_metainfo))/2)+10;
g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL] g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]
->RenderString(m_x + xstart, m_y + 4 + 2*m_fheight + m_sheight, ->RenderString(m_x + xstart, m_y + 4 + 2*m_fheight + m_sheight,