- audioplayer: fix cover handling

This commit is contained in:
svenhoefer
2013-11-14 23:52:21 +01:00
parent 3c8d47fa49
commit 22c3cec0ca
2 changed files with 33 additions and 36 deletions

View File

@@ -41,6 +41,7 @@
#endif #endif
#include <string.h> #include <string.h>
#include <sstream>
#include <errno.h> #include <errno.h>
#include <string> #include <string>
#include <linux/soundcard.h> #include <linux/soundcard.h>
@@ -1345,10 +1346,11 @@ void CMP3Dec::GetID3(FILE* in, CAudioMetaData* const m)
} }
} }
static int cover_count = 0;
bool CMP3Dec::SaveCover(FILE * in, CAudioMetaData * const m) bool CMP3Dec::SaveCover(FILE * in, CAudioMetaData * const m)
{ {
struct id3_frame const *frame; struct id3_frame const *frame;
const char * coverfile = "/tmp/cover.jpg";
/* text information */ /* text information */
struct id3_file *id3file = id3_file_fdopen(fileno(in), ID3_FILE_MODE_READONLY); struct id3_file *id3file = id3_file_fdopen(fileno(in), ID3_FILE_MODE_READONLY);
@@ -1383,11 +1385,17 @@ bool CMP3Dec::SaveCover(FILE * in, CAudioMetaData * const m)
data = id3_field_getbinarydata(field, &size); data = id3_field_getbinarydata(field, &size);
if ( data ) if ( data )
{ {
m->cover = coverfile; std::ostringstream cover;
cover.str("");
cover << "/tmp/cover_" << cover_count++ << ".jpg";
FILE * pFile; FILE * pFile;
pFile = fopen ( coverfile , "wb" ); pFile = fopen ( cover.str().c_str() , "wb" );
fwrite (data , 1 , size , pFile ); if (pFile)
fclose (pFile); {
fwrite (data , 1 , size , pFile );
fclose (pFile);
m->cover = cover.str().c_str();
}
} }
break; break;

View File

@@ -965,6 +965,10 @@ bool CAudioPlayerGui::clearPlaylist(void)
{ {
bool result = false; bool result = false;
CAudioPlayList::const_iterator it;
for (it = m_playlist.begin(); it!=m_playlist.end(); ++it)
unlink(it->MetaData.cover.c_str());
if (!(m_playlist.empty())) if (!(m_playlist.empty()))
{ {
m_playlist.clear(); m_playlist.clear();
@@ -1777,21 +1781,25 @@ void CAudioPlayerGui::paintInfo()
return; return;
int c_rad_mid = RADIUS_MID; int c_rad_mid = RADIUS_MID;
int title_height = m_title_height;
if (m_state == CAudioPlayerGui::STOP && m_show_playlist) if (m_state == CAudioPlayerGui::STOP && m_show_playlist)
m_frameBuffer->paintBackgroundBoxRel(m_x, m_y, m_width, m_title_height); m_frameBuffer->paintBackgroundBoxRel(m_x, m_y, m_width, m_title_height);
else else
{ {
if (!m_show_playlist) if (!m_show_playlist) // no playlist -> smaller Info-Box
{ title_height -= m_fheight;
// no playlist -> smaller Info-Box
m_frameBuffer->paintBoxRel(m_x + 1, m_y + 1 , m_width - 2, m_title_height - 12 - m_fheight, COL_MENUCONTENTSELECTED_PLUS_0, c_rad_mid); m_frameBuffer->paintBoxRel(m_x + 1, m_y + 1 , m_width - 2, title_height - 12, COL_MENUCONTENTSELECTED_PLUS_0, c_rad_mid);
m_frameBuffer->paintBoxFrame(m_x, m_y, m_width, m_title_height - 10 - m_fheight, 2, COL_MENUCONTENT_PLUS_6, c_rad_mid); m_frameBuffer->paintBoxFrame(m_x, m_y, m_width, title_height - 10, 2, COL_MENUCONTENT_PLUS_6, c_rad_mid);
}
else std::string cover = m_curr_audiofile.Filename.substr(0, m_curr_audiofile.Filename.rfind('/')) + "/folder.jpg";
{
m_frameBuffer->paintBoxRel(m_x + 1, m_y + 1 , m_width - 2, m_title_height - 12, COL_MENUCONTENTSELECTED_PLUS_0, c_rad_mid); if (!m_curr_audiofile.MetaData.cover.empty())
m_frameBuffer->paintBoxFrame(m_x, m_y, m_width, m_title_height - 10, 2, COL_MENUCONTENT_PLUS_6, c_rad_mid); cover = m_curr_audiofile.MetaData.cover;
}
if (access(cover.c_str(), F_OK) == 0)
g_PicViewer->DisplayImage(cover, m_x + 2 + c_rad_mid/2, m_y + 2 + c_rad_mid/2, title_height - 14 - c_rad_mid, title_height - 14 - c_rad_mid, m_frameBuffer->TM_NONE);
// first line (Track number) // first line (Track number)
std::string tmp; std::string tmp;
@@ -2170,25 +2178,6 @@ 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)
@@ -2484,7 +2473,7 @@ void CAudioPlayerGui::removeFromPlaylist(long pos)
// must be called before m_playlist.erase() // must be called before m_playlist.erase()
firstChar = getFirstChar(m_playlist[pos]); firstChar = getFirstChar(m_playlist[pos]);
} }
unlink(m_playlist[pos].MetaData.cover.c_str());
m_playlist.erase(m_playlist.begin() + pos); m_playlist.erase(m_playlist.begin() + pos);
m_playlistHasChanged = true; m_playlistHasChanged = true;