From ab3e68a68ace738d9ea2856c2c6530c85fbac72b Mon Sep 17 00:00:00 2001 From: vanhofen Date: Sat, 9 Nov 2013 18:34:09 +0100 Subject: [PATCH] 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! Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/fe07423ad195165bf354de54542a85796566f6d5 Author: vanhofen Date: 2013-11-09 (Sat, 09 Nov 2013) Origin message was: ------------------ - 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! --- src/driver/audiodec/mp3dec.cpp | 77 ++++++++++++++++++++++++++++++++++ src/driver/audiodec/mp3dec.h | 1 + src/driver/audiometadata.cpp | 4 +- src/driver/audiometadata.h | 1 + src/gui/audioplayer.cpp | 23 +++++++++- 5 files changed, 103 insertions(+), 3 deletions(-) diff --git a/src/driver/audiodec/mp3dec.cpp b/src/driver/audiodec/mp3dec.cpp index 458873e56..f64d3956a 100644 --- a/src/driver/audiodec/mp3dec.cpp +++ b/src/driver/audiodec/mp3dec.cpp @@ -944,6 +944,7 @@ bool CMP3Dec::GetMetaData(FILE* in, const bool nice, CAudioMetaData* const m) { res = GetMP3Info(in, nice, m); GetID3(in, m); + SaveCover(in, m); } 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" // which cannot be called from outside void id3_finish_file(struct id3_file* file) diff --git a/src/driver/audiodec/mp3dec.h b/src/driver/audiodec/mp3dec.h index cafdc4f9c..5f9b97c66 100644 --- a/src/driver/audiodec/mp3dec.h +++ b/src/driver/audiodec/mp3dec.h @@ -73,6 +73,7 @@ public: State* const state, CAudioMetaData* m, time_t* const t, unsigned int* const secondsToSkip); bool GetMetaData(FILE *in, const bool nice, CAudioMetaData* const m); + bool SaveCover(FILE*, CAudioMetaData * const m); CMP3Dec(){}; }; diff --git a/src/driver/audiometadata.cpp b/src/driver/audiometadata.cpp index 600c4f32b..92c6a78fc 100644 --- a/src/driver/audiometadata.cpp +++ b/src/driver/audiometadata.cpp @@ -51,7 +51,7 @@ CAudioMetaData::CAudioMetaData( const CAudioMetaData& src ) audio_start_pos( src.audio_start_pos ), vbr( src.vbr ), hasInfoOrXingTag( src.hasInfoOrXingTag ), artist( src.artist ), 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 ) { } @@ -81,6 +81,7 @@ void CAudioMetaData::operator=( const CAudioMetaData& src ) date = src.date; genre = src.genre; track = src.track; + cover = src.cover; sc_station = src.sc_station; changed = src.changed; } @@ -104,5 +105,6 @@ void CAudioMetaData::clear() date.clear(); genre.clear(); track.clear(); + cover.clear(); changed=false; } diff --git a/src/driver/audiometadata.h b/src/driver/audiometadata.h index 022d59460..ba2a58e0c 100644 --- a/src/driver/audiometadata.h +++ b/src/driver/audiometadata.h @@ -84,6 +84,7 @@ public: std::string date; std::string genre; std::string track; + std::string cover; bool changed; }; #endif /* __AUDIO_METADATA__ */ diff --git a/src/gui/audioplayer.cpp b/src/gui/audioplayer.cpp index beb1be8cb..63e9171c0 100644 --- a/src/gui/audioplayer.cpp +++ b/src/gui/audioplayer.cpp @@ -66,6 +66,7 @@ #include #include "gui/pictureviewer.h" +extern CPictureViewer * g_PicViewer; #include #include @@ -2169,6 +2170,25 @@ void CAudioPlayerGui::updateMetaData(bool screen_saver) m_curr_audiofile.MetaData.album = meta.sc_station; 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()->hasMetaDataChanged() != 0) @@ -2183,8 +2203,7 @@ void CAudioPlayerGui::updateMetaData(bool screen_saver) if (updateMeta || updateScreen) { - m_frameBuffer->paintBoxRel(m_x + 10, m_y + 4 + 2*m_fheight, m_width - 20, - m_sheight, COL_MENUCONTENTSELECTED_PLUS_0); + 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); int xstart = ((m_width - 20 - g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getRenderWidth(m_metainfo))/2)+10; g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL] ->RenderString(m_x + xstart, m_y + 4 + 2*m_fheight + m_sheight,