Hi,<div><br></div><div>I'm not sure the correct address I asked.</div><div><br></div><div>I need to extract album cover from audio file. But i have some problems with flac.</div><div>As i understand, the best way to do it is (file is <span style="color:rgb(255,139,255)">TagLib</span><span style="color:rgb(207,191,173)">::</span><span style="color:rgb(255,139,255)">FLAC</span><span style="color:rgb(207,191,173)">::</span><span style="color:rgb(255,139,255)">File</span><span style="color:rgb(207,191,173)">*</span>):</div>
<div><br></div><div><div><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(100,100,130)"> </span>founded<span style="color:rgb(100,100,130)"> </span><span style="color:rgb(207,191,173)">=</span><span style="color:rgb(100,100,130)"> </span>extractFlac<span style="color:rgb(207,191,173)">(</span>file<span style="color:rgb(207,191,173)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#808bed">if</span><span style="color:#cfbfad">(!</span>founded<span style="color:#cfbfad">)</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#cfbfad">{</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#ff8bff">TagLib</span><span style="color:#cfbfad">::</span><span style="color:#ff8bff">ID3v2</span><span style="color:#cfbfad">::</span><span style="color:#ff8bff">Tag</span><span style="color:#cfbfad">*</span><span style="color:#646482"> </span>tag<span style="color:#646482"> </span><span style="color:#cfbfad">=</span><span style="color:#646482"> </span>file<span style="color:#cfbfad">-></span>ID3v2Tag<span style="color:#cfbfad">();</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#808bed">if</span><span style="color:#cfbfad">(</span>tag<span style="color:#cfbfad">)</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span>founded<span style="color:#646482"> </span><span style="color:#cfbfad">=</span><span style="color:#646482"> </span>extractId3<span style="color:#cfbfad">(</span>tag<span style="color:#cfbfad">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(100,100,130)"> </span><span style="color:rgb(207,191,173)">}</span></pre></div><div><br></div><div><b>extractFlac </b>and <b>extractId3 </b>functions:</div>
<div><br></div><div><pre style="margin-top:0px;margin-bottom:0px"><span style="color:#808bed">bool</span><span style="color:#646482"> </span>extractFlac<span style="color:#cfbfad">(</span><span style="color:#ff8bff">TagLib</span><span style="color:#cfbfad">::</span><span style="color:#ff8bff">FLAC</span><span style="color:#cfbfad">::</span><span style="color:#ff8bff">File</span><span style="color:#cfbfad">*</span><span style="color:#646482"> </span>file<span style="color:#cfbfad">)</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#cfbfad">{</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#808bed">const</span><span style="color:#646482"> </span><span style="color:#ff8bff">TagLib</span><span style="color:#cfbfad">::</span><span style="color:#ff8bff">List</span><span style="color:#cfbfad"><</span><span style="color:#ff8bff">TagLib</span><span style="color:#cfbfad">::</span><span style="color:#ff8bff">FLAC</span><span style="color:#cfbfad">::</span><span style="color:#ff8bff">Picture</span><span style="color:#cfbfad">*></span><span style="color:#646482"> </span>picList<span style="color:#646482"> </span><span style="color:#cfbfad">=</span><span style="color:#646482"> </span>file<span style="color:#cfbfad">-></span>pictureList<span style="color:#cfbfad">();</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#808bed">if</span><span style="color:#cfbfad">(!</span>picList<span style="color:#cfbfad">.</span>isEmpty<span style="color:#cfbfad">())</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#cfbfad">{</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#ff8bff">TagLib</span><span style="color:#cfbfad">::</span><span style="color:#ff8bff">FLAC</span><span style="color:#cfbfad">::</span><span style="color:#ff8bff">Picture</span><span style="color:#cfbfad">*</span><span style="color:#646482"> </span>pic<span style="color:#646482"> </span><span style="color:#cfbfad">=</span><span style="color:#646482"> </span>picList<span style="color:#cfbfad">.</span>front<span style="color:#cfbfad">();</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#808bed">return</span><span style="color:#646482"> </span>saveData<span style="color:#cfbfad">(</span>pic<span style="color:#cfbfad">-></span>data<span style="color:#cfbfad">());</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#cfbfad">}</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#808bed">return</span><span style="color:#646482"> </span><span style="color:#808bed">false</span><span style="color:#cfbfad">;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#cfbfad">}</span></pre></div><div><br></div><div> <span style="color:rgb(128,139,237)">bool</span><span style="color:rgb(100,100,130)"> </span>extractId3<span style="color:rgb(207,191,173)">(</span><span style="color:rgb(255,139,255)">TagLib</span><span style="color:rgb(207,191,173)">::</span><span style="color:rgb(255,139,255)">ID3v2</span><span style="color:rgb(207,191,173)">::</span><span style="color:rgb(255,139,255)">Tag</span><span style="color:rgb(207,191,173)">*</span><span style="color:rgb(100,100,130)"> </span>tag<span style="color:rgb(207,191,173)">)</span></div>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#cfbfad">{</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#808bed">const</span><span style="color:#646482"> </span><span style="color:#ff8bff">TagLib</span><span style="color:#cfbfad">::</span><span style="color:#ff8bff">ID3v2</span><span style="color:#cfbfad">::</span><span style="color:#ff8bff">FrameList</span><span style="color:#cfbfad">&</span><span style="color:#646482"> </span>frameList<span style="color:#646482"> </span><span style="color:#cfbfad">=</span><span style="color:#646482"> </span>tag<span style="color:#cfbfad">-></span>frameList<span style="color:#cfbfad">(</span><font color="#ffcd8b">"APIC"</font><span style="color:#cfbfad">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#808bed">if</span><span style="color:#cfbfad">(!</span>frameList<span style="color:#cfbfad">.</span>isEmpty<span style="color:#cfbfad">())</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#cfbfad">{</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#ff8bff">TagLib</span><span style="color:#cfbfad">::</span><span style="color:#ff8bff">ID3v2</span><span style="color:#cfbfad">::</span><span style="color:#ff8bff">AttachedPictureFrame</span><span style="color:#cfbfad">*</span><span style="color:#646482"> </span>frame<span style="color:#646482"> </span><span style="color:#cfbfad">=</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#808bed">static_cast</span><span style="color:#cfbfad"><</span><span style="color:#ff8bff">TagLib</span><span style="color:#cfbfad">::</span><span style="color:#ff8bff">ID3v2</span><span style="color:#cfbfad">::</span><span style="color:#ff8bff">AttachedPictureFrame</span><span style="color:#cfbfad">*>(</span>frameList<span style="color:#cfbfad">.</span>front<span style="color:#cfbfad">());</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#808bed">return</span><span style="color:#646482"> </span>saveData<span style="color:#cfbfad">(</span>frame<span style="color:#cfbfad">-></span>picture<span style="color:#cfbfad">());</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#cfbfad">}</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#808bed">return</span><span style="color:#646482"> </span><span style="color:#808bed">false</span><span style="color:#cfbfad">;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#cfbfad">}</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:#cfbfad"><br></span></pre><div>But it doesn't work. Function <i>pictureList()</i> of <i>TagLib::FLAC::File</i> always return empty list (file is valid and has cover) and file does not have ID3v2 tag.</div>
<div><br></div><div>I test it on Windows 32 bit and Ubuntu 12.04 32 bit ( <b>TagLib 1.8</b> ). Can you help me?</div><div><br></div><div>And one another question. What about initializing <i>TagLib::FileRef</i> with wchar_t* string on not Windows OS?</div>
<div>I mean <i>TagLib::</i><i>FileName </i>type</div><div><br></div><div><pre style="margin-top:0px;margin-bottom:0px"><span style="color:#409090">#ifdef</span><span style="color:#646482"> </span>_WIN32</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#808bed">class</span><span style="color:#646482"> </span>TAGLIB_EXPORT<span style="color:#646482"> </span><span style="color:#ff8bff">FileName</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#cfbfad">{</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#808bed">public</span><span style="color:#cfbfad">:</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#ff8bff">FileName</span><span style="color:#cfbfad">(</span><span style="color:#808bed">const</span><span style="color:#646482"> </span><span style="color:#808bed">wchar_t</span><span style="color:#646482"> </span><span style="color:#cfbfad">*</span>name<span style="color:#cfbfad">)</span><span style="color:#646482"> </span><span style="color:#cfbfad">:</span><span style="color:#646482"> </span><span style="font-weight:600">m_wname</span><span style="color:#cfbfad">(</span>name<span style="color:#cfbfad">)</span><span style="color:#646482"> </span><span style="color:#cfbfad">{}</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#ff8bff">FileName</span><span style="color:#cfbfad">(</span><span style="color:#808bed">const</span><span style="color:#646482"> </span><span style="color:#808bed">char</span><span style="color:#646482"> </span><span style="color:#cfbfad">*</span>name<span style="color:#cfbfad">)</span><span style="color:#646482"> </span><span style="color:#cfbfad">:</span><span style="color:#646482"> </span><span style="font-weight:600">m_name</span><span style="color:#cfbfad">(</span>name<span style="color:#cfbfad">)</span><span style="color:#646482"> </span><span style="color:#cfbfad">{}</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#808bed">operator</span><span style="color:#646482"> </span><span style="color:#808bed">const</span><span style="color:#646482"> </span><span style="color:#808bed">wchar_t</span><span style="color:#646482"> </span><span style="color:#cfbfad">*()</span><span style="color:#646482"> </span><span style="color:#808bed">const</span><span style="color:#646482"> </span><span style="color:#cfbfad">{</span><span style="color:#646482"> </span><span style="color:#808bed">return</span><span style="color:#646482"> </span><span style="font-weight:600">m_wname</span><span style="color:#cfbfad">.</span>c_str<span style="color:#cfbfad">();</span><span style="color:#646482"> </span><span style="color:#cfbfad">}</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#808bed">operator</span><span style="color:#646482"> </span><span style="color:#808bed">const</span><span style="color:#646482"> </span><span style="color:#808bed">char</span><span style="color:#646482"> </span><span style="color:#cfbfad">*()</span><span style="color:#646482"> </span><span style="color:#808bed">const</span><span style="color:#646482"> </span><span style="color:#cfbfad">{</span><span style="color:#646482"> </span><span style="color:#808bed">return</span><span style="color:#646482"> </span><span style="font-weight:600">m_name</span><span style="color:#cfbfad">.</span>c_str<span style="color:#cfbfad">();</span><span style="color:#646482"> </span><span style="color:#cfbfad">}</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#808bed">private</span><span style="color:#cfbfad">:</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#ff8bff">std</span><span style="color:#cfbfad">::</span><span style="color:#ff8bff">string</span><span style="color:#646482"> </span><span style="font-weight:600">m_name</span><span style="color:#cfbfad">;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#ff8bff">std</span><span style="color:#cfbfad">::</span><span style="color:#ff8bff">wstring</span><span style="color:#646482"> </span><span style="font-weight:600">m_wname</span><span style="color:#cfbfad">;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#cfbfad">};</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#409090">#else</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#646482"> </span><span style="color:#808bed">typedef</span><span style="color:#646482"> </span><span style="color:#808bed">const</span><span style="color:#646482"> </span><span style="color:#808bed">char</span><span style="color:#646482"> </span><span style="color:#cfbfad">*</span>FileName<span style="color:#cfbfad">;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#409090">#endif</span></pre></div><div><br></div><div>I can't work with <i>TagLib::FileRef</i> and wide characters string?</div><div><br></div><div>According to the implementation of FileName class it will work fine on not Windows OS too...</div>
<div><br></div>-- <br>Best regards,<div>Grigoriy Vanika <span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">mailto : <a href="mailto:grish.vanika@gmail.com" target="_blank">grish.vanika@gmail.com</a></span></div>
<br>
</div>