00001 /* Copyright (C) 2009 Väinö Lappi <djap84@gmail.com> 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00016 00017 */ 00018 00019 /* 00020 * MPlayerControlAPI.h 00021 * 00022 * Created on: 27.4.2009 00023 * Author: djap 00024 */ 00025 00026 #ifndef MPLAYERCONTROLAPI_H_ 00027 #define MPLAYERCONTROLAPI_H_ 00028 00029 #define _MPLAYER_START_SUCCESS 0 00030 #define _MPLAYER_START_ERROR_ALLREADY_PLAYING -1 00031 #define _MPLAYER_START_ERROR_FAILED_TO_START -2 00032 #define _MPLAYER_START_ERROR_NOTHING_TO_PLAY -3 00033 00034 #include <QProcess> 00035 #include <QObject> 00036 #include <QSemaphore> 00037 #include <QtGui/QWidget> 00038 #include <QTimer> 00039 00062 class MPlayerControlAPI: public QObject { 00063 Q_OBJECT 00064 public: 00065 MPlayerControlAPI(); 00066 virtual ~MPlayerControlAPI(); 00067 00073 void SetWindowID(WId graphicArea); 00074 00083 void SetFile(const QString &fileName); 00084 00093 QString GetFile(); 00094 00102 int Play(); 00103 00112 int Pause(); 00113 00127 int TogglePlayPause(); 00128 00135 bool Stop(); 00136 00137 00144 void SetVolume(int vol); 00145 00146 00153 void Seek(int pos); 00154 00161 bool isPlaying(); 00162 00168 QString getMplayerVersion(); 00169 00178 int initMplayerProcess(); 00179 private: 00186 bool iHasVideoWidth; 00193 bool iHasVideoHeight; 00202 qreal iVideoWidth; 00211 qreal iVideoHeight; 00216 QString iFileName; 00226 QString iMplayerVersion; 00227 00232 bool iIsPlaying; 00237 WId iMplayerVideoOutputWindowId; 00242 QProcess *iMplayerProcess; 00247 bool iPaused; 00252 int iVolume; 00257 QTimer iPlayingProgressTimer; 00266 QSemaphore *iPlayingProgressSem; 00267 00268 public slots: 00290 void NewDataInStdout(); 00298 void playingProgressTimerTimedOut(); 00299 signals: 00304 void startPlayingProgressTimer(); 00309 void stopPlayingProgressTimer(); 00314 void log(const QString &msg); //For debugging 00319 void finishedPlaying(); //Emitted when mplayer finishes playing a file. Not emitted if this happens in response for calling stop() 00325 void playingProgress(quint64 value); //emitted about 10 times a second when playing, value is the playing time of current file in 1/10th of seconds 00331 void gotLength(qreal length); //Emitted when parser reading mplayer's output finds length of the file we are starting to play. length is length of the file in seconds. 00337 void gotAspectRatio(qreal aspectRatio); 00338 //information for "now playing" 00344 void gotMediaTitle(const QString &title); 00350 void gotMediaArtist(const QString &artist); 00356 void gotMediaCreationDate(const QString &creationDate); 00362 void gotMediaAlbum(const QString &album); 00368 void gotMediaFilename(const QString &fileName); 00369 }; 00370 00371 #endif /* MPLAYERCONTROLAPI_H_ */