00001 #include "audiowidget.h"
00002 #include "../opieplayer2/lib.h"
00003 #include "../opieplayer2/threadutil.h"
00004
00005 #include <opie2/odebug.h>
00006
00007 #include <qlayout.h>
00008 #include <qtextview.h>
00009 #include <qslider.h>
00010 #include <qlabel.h>
00011
00012 AudioWidget::AudioWidget( QWidget * parent, const char * name, WFlags f)
00013 :QWidget(parent,name,f)
00014 {
00015 m_xineLib = 0;
00016
00017 m_MainLayout = new QVBoxLayout(this);
00018 m_MainLayout->setAutoAdd(true);
00019 m_InfoBox = new QTextView(this);
00020 }
00021
00022 AudioWidget::~AudioWidget()
00023 {
00024 }
00025
00026 int AudioWidget::playFile(const DocLnk&aLnk,XINE::Lib*aLib)
00027 {
00028 m_current = aLnk;
00029 if (m_xineLib != aLib) {
00030 if (m_xineLib) disconnect(m_xineLib);
00031 m_xineLib = aLib;
00032 }
00033 if (!m_xineLib) {
00034 return -1;
00035 }
00036 int res = m_xineLib->play(m_current.file(),0,0);
00037 if (res != 1) {
00038 return -2;
00039 }
00040 if (!m_xineLib->hasVideo()) {
00041 m_xineLib->setShowVideo( false );
00042 }
00043
00044
00045 QString title = m_xineLib->metaInfo(0);
00046
00047 QString artist = m_xineLib->metaInfo(2);
00048
00049 QString album = m_xineLib->metaInfo(4);
00050
00051 int l = m_xineLib->length();
00052 QString laenge = secToString(l);
00053 QString text = "<qt><center><table border=\"0\">";
00054 if (artist.length()) {
00055 text+="<tr><td>"+tr("Artist: ")+"</td><td><b>"+artist+"</b></td></tr>";
00056 }
00057 if (title.length()) {
00058 text+="<tr><td>"+tr("Title: ")+"</td><td><font size=\"+2\">"+title+"</font></td></tr>";
00059 } else {
00060 text+="<tr><td>"+tr("Filename: ")+"</td><td><b>"+m_current.name()+"</b></td></tr>";
00061 }
00062 if (album.length()) {
00063 text+="<tr><td>"+tr("Album: ")+"</td><td><b>"+album+"</b></td></tr>";
00064 }
00065 text+="<tr><td>"+tr("Length: ")+"</td><td><b>"+laenge+"</b></td></tr>";
00066 text+="</table></center></qt>";
00067 m_InfoBox->setText(text);
00068 return l;
00069 }
00070
00071 QString AudioWidget::secToString(int sec)
00072 {
00073 int l = sec;
00074 int h = l/3600;
00075 l-=h*3600;
00076 int m = l/60;
00077 l-=m*60;
00078 QString s = "";
00079 if (h>0) {
00080 s.sprintf("%2i:%2i:%2i",h,m,l);
00081 } else {
00082 s.sprintf("%02i:%02i",m,l);
00083 }
00084 return s;
00085 }
00086
00087 void AudioWidget::stopPlaying()
00088 {
00089 if (m_xineLib) {
00090 m_xineLib->stop();
00091 }
00092 }
00093
00094 void AudioWidget::updatePos(int )
00095 {
00096 }