#include <MPlayerControlAPI.h>
Public Slots | |
void | NewDataInStdout () |
Receive messages printed out by mplayer. | |
void | playingProgressTimerTimedOut () |
Called when iPlayingProgressTimer times out. | |
Signals | |
void | startPlayingProgressTimer () |
Internal signal. Emitted to start iPlayingProgressTimer. | |
void | stopPlayingProgressTimer () |
Internal signal. Emitted to stop iPlayingProgressTimer. | |
void | log (const QString &msg) |
Can be used to get log about what is happening in here. | |
void | finishedPlaying () |
Emitted when mplayer finishes playing a file. Doesn't get emitted however if the playing gets stopped by calling Stop(). | |
void | playingProgress (quint64 value) |
Emitted when NewDataInStdout() receives information about the progress of the file currently being played from mplayer. | |
void | gotLength (qreal length) |
Emitted when NewDataInStdout() receives the total length of file from mplayer. | |
void | gotAspectRatio (qreal aspectRatio) |
Emitted when video aspect ratio is determined by calculation from width and height or reported by mplayer. | |
void | gotMediaTitle (const QString &title) |
Emitted when NewDataInStdout() receives title of file from mplayer. | |
void | gotMediaArtist (const QString &artist) |
Emitted when NewDataInStdout() receives artist of file from mplayer. | |
void | gotMediaCreationDate (const QString &creationDate) |
Emitted when NewDataInStdout() receives creation date of file from mplayer. | |
void | gotMediaAlbum (const QString &album) |
Emitted when NewDataInStdout() receives album from which the file is from from mplayer. | |
void | gotMediaFilename (const QString &fileName) |
Emitted when NewDataInStdout() receives filename from mplayer. | |
Public Member Functions | |
void | SetWindowID (WId graphicArea) |
Redirect video output to own window/widget. | |
void | SetFile (const QString &fileName) |
Set name of the file that should be played next. | |
QString | GetFile () |
Get name of the file that is set to be played next. | |
int | Play () |
Start playing. | |
int | Pause () |
Pause or resume playing from pause. | |
int | TogglePlayPause () |
Pause or resume playing from pause or start playing. | |
bool | Stop () |
Stop playing. | |
void | SetVolume (int vol) |
Set the volume. | |
void | Seek (int pos) |
Seek from currently played file. | |
bool | isPlaying () |
Check if mplayer is currently playing something. | |
QString | getMplayerVersion () |
Get the version of mplayer. | |
int | initMplayerProcess () |
Start process for mplayer. | |
Private Attributes | |
bool | iHasVideoWidth |
Track wether we have any information about possible width of video currently being played. | |
bool | iHasVideoHeight |
Track wether we have any information about possible height of video currently being played. | |
qreal | iVideoWidth |
Stores the width of video currently being played. | |
qreal | iVideoHeight |
Stores the height of video currently being played. | |
QString | iFileName |
Stores the name of file that is set to be played next by SetFile(const QString &fileName). | |
QString | iMplayerVersion |
Stores the version of mplayer. | |
bool | iIsPlaying |
True if we are playing something or paused, else false. | |
WId | iMplayerVideoOutputWindowId |
ID of the window to which mplayer should redirect it's video output. | |
QProcess * | iMplayerProcess |
mplayers process. | |
bool | iPaused |
true if paused, else false. | |
int | iVolume |
Stores the current volume setting. | |
QTimer | iPlayingProgressTimer |
Timer used for querying playing progress from mplayer with certain intervall. | |
QSemaphore * | iPlayingProgressSem |
Semaphore for preventing us to query playing progress faster than we get responses from mplayer. |
Introduces functions for doing following things with mplayer.
QString MPlayerControlAPI::GetFile | ( | ) |
Get name of the file that is set to be played next.
The function will return the name of the file that is set to be played next.
QString MPlayerControlAPI::getMplayerVersion | ( | ) |
Get the version of mplayer.
void MPlayerControlAPI::gotAspectRatio | ( | qreal | aspectRatio | ) | [signal] |
Emitted when video aspect ratio is determined by calculation from width and height or reported by mplayer.
aspectRatio | Aspect ratio of video. |
void MPlayerControlAPI::gotLength | ( | qreal | length | ) | [signal] |
Emitted when NewDataInStdout() receives the total length of file from mplayer.
length | Length of file in seconds. |
void MPlayerControlAPI::gotMediaAlbum | ( | const QString & | album | ) | [signal] |
Emitted when NewDataInStdout() receives album from which the file is from from mplayer.
album | Name of the album this is from. |
void MPlayerControlAPI::gotMediaArtist | ( | const QString & | artist | ) | [signal] |
Emitted when NewDataInStdout() receives artist of file from mplayer.
artist | Performing artist's name. |
void MPlayerControlAPI::gotMediaCreationDate | ( | const QString & | creationDate | ) | [signal] |
Emitted when NewDataInStdout() receives creation date of file from mplayer.
creationDate | Creation date of the file. |
void MPlayerControlAPI::gotMediaFilename | ( | const QString & | fileName | ) | [signal] |
Emitted when NewDataInStdout() receives filename from mplayer.
fileName | Name of the file that is currently being played withouth complete path. |
void MPlayerControlAPI::gotMediaTitle | ( | const QString & | title | ) | [signal] |
Emitted when NewDataInStdout() receives title of file from mplayer.
title | Title of the file (such as song name). |
int MPlayerControlAPI::initMplayerProcess | ( | ) |
Start process for mplayer.
This function must be succesfully called before this API can be used for playing anything.
_MPLAYER_START_SUCCESS on success.
bool MPlayerControlAPI::isPlaying | ( | ) |
Check if mplayer is currently playing something.
void MPlayerControlAPI::NewDataInStdout | ( | ) | [slot] |
Receive messages printed out by mplayer.
This slot receives messages printed out by mplayer and parses any interesting information from them. Following things are captured from mplayer's output.
int MPlayerControlAPI::Pause | ( | ) |
Pause or resume playing from pause.
Can be used to pause or resume playing from pause. Doesn't resume playing if playing is stopped.
int MPlayerControlAPI::Play | ( | ) |
Start playing.
_MPLAYER_START_ERROR_NOTHING_TO_PLAY if nothing has been set to be played. SetFile(const QString &fileName) must be called before calling Play()
void MPlayerControlAPI::playingProgress | ( | quint64 | value | ) | [signal] |
Emitted when NewDataInStdout() receives information about the progress of the file currently being played from mplayer.
value | Location in file measured as 0.1 seconds. |
void MPlayerControlAPI::playingProgressTimerTimedOut | ( | ) | [slot] |
Called when iPlayingProgressTimer times out.
Tests first if iIsPlaying is true. If not, then nothing is done. If is then will test iPlayingProgressSem and if the value is greater than 0, will send query to mplayer about playing progress, decrease the value of the semaphore by one and restart iPlayingProgressTimer.
void MPlayerControlAPI::Seek | ( | int | pos | ) |
Seek from currently played file.
pos | a number between 0 and maximum value passed by signal void gotLength(qreal length) |
void MPlayerControlAPI::SetFile | ( | const QString & | fileName | ) |
Set name of the file that should be played next.
fileName | String holding the filename |
void MPlayerControlAPI::SetVolume | ( | int | vol | ) |
Set the volume.
vol | a number from 0 to 100. 0 means silent, 100 means full volume. |
void MPlayerControlAPI::SetWindowID | ( | WId | graphicArea | ) |
Redirect video output to own window/widget.
graphicArea | Window ID of the widget that mplayer should use as video output. |
bool MPlayerControlAPI::Stop | ( | ) |
Stop playing.
int MPlayerControlAPI::TogglePlayPause | ( | ) |
Pause or resume playing from pause or start playing.
Function is written for convenience to combine Pause() and Play() and does the wollowing:
error code returned by Play() if attempted to start playing.
MPlayerControlAPI::iHasVideoHeight [private] |
Track wether we have any information about possible height of video currently being played.
Reset by Play() when changing file. Set by NewDataInStdout() when it receives height of video.
MPlayerControlAPI::iHasVideoWidth [private] |
Track wether we have any information about possible width of video currently being played.
Reset by Play() when changing file. Set by NewDataInStdout() when it receives width of video.
MPlayerControlAPI::iMplayerVersion [private] |
Stores the version of mplayer.
The string contains information about mplayer shortly after calling initMplayerProcess(). The time between calling initMplayerProcess() and information getting stored to this string depends on how fast mplayer process starts and reports it's version via stdout ( NewDataInStdout() ). Call QString getMplayerVersion() to query for this information.
MPlayerControlAPI::iPlayingProgressSem [private] |
Semaphore for preventing us to query playing progress faster than we get responses from mplayer.
This semaphore is first tested by playingProgressTimerTimedOut() and if the value is greater than 0, playingProgressTimerTimedOut() will send query to mplayer about playing progress and decrease the value of the semaphore by one. When NewDataInStdout() receives response to this query (that can be either playing progress or error stating that it couldn't be read) it will increase the value of this semaphore by one allowing more queries to be sent.
MPlayerControlAPI::iVideoHeight [private] |
Stores the height of video currently being played.
Once both height and width have been received from mplayer process (MPlayerControlAPI::iHasVideoWidth and MPlayerControlAPI::iHasVideoHeight are both true) iVideoWidth and iVideoHeight are used to calculate and report the aspect ratio of the video being played. The aspect ratio is allso queried separately but it is sometimes reported as 0 by mplayer.
MPlayerControlAPI::iVideoWidth [private] |
Stores the width of video currently being played.
Once both height and width have been received from mplayer process (MPlayerControlAPI::iHasVideoWidth and MPlayerControlAPI::iHasVideoHeight are both true) iVideoWidth and iVideoHeight are used to calculate and report the aspect ratio of the video being played. The aspect ratio is allso queried separately but it is sometimes reported as 0 by mplayer.