MPlayerControlAPI Class Reference

API for controlling mplayer process. More...

#include <MPlayerControlAPI.h>

List of all members.

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.


Detailed Description

API for controlling mplayer process.

Introduces functions for doing following things with mplayer.


Member Function Documentation

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.

Returns:
name of the file that is set to be played when Play() is called.

QString MPlayerControlAPI::getMplayerVersion (  ) 

Get the version of mplayer.

Returns:
String containing 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.

Parameters:
aspectRatio Aspect ratio of video.

void MPlayerControlAPI::gotLength ( qreal  length  )  [signal]

Emitted when NewDataInStdout() receives the total length of file from mplayer.

Parameters:
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.

Parameters:
album Name of the album this is from.

void MPlayerControlAPI::gotMediaArtist ( const QString &  artist  )  [signal]

Emitted when NewDataInStdout() receives artist of file from mplayer.

Parameters:
artist Performing artist's name.

void MPlayerControlAPI::gotMediaCreationDate ( const QString &  creationDate  )  [signal]

Emitted when NewDataInStdout() receives creation date of file from mplayer.

Parameters:
creationDate Creation date of the file.

void MPlayerControlAPI::gotMediaFilename ( const QString &  fileName  )  [signal]

Emitted when NewDataInStdout() receives filename from mplayer.

Parameters:
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.

Parameters:
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.

Returns:
_MPLAYER_START_ERROR_FAILED_TO_START if mplayer process couldn't be started for some reason.

_MPLAYER_START_SUCCESS on success.

bool MPlayerControlAPI::isPlaying (  ) 

Check if mplayer is currently playing something.

Returns:
true if mplayer is playing (or paused), false if mplayer is stopped.

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.

In addition the following things are taken from possible ID tags in files.

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.

Returns:
allways 0 (TODO errors...)

int MPlayerControlAPI::Play (  ) 

Start playing.

Returns:
_MPLAYER_START_ERROR_ALLREADY_PLAYING if mplayer is allready playing something.

_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.

Parameters:
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.

Parameters:
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.

Parameters:
fileName String holding the filename
The function will set the name of the file that should be played next. This function does not start playing the file. To start playing you must call Play() after setting filename.

void MPlayerControlAPI::SetVolume ( int  vol  ) 

Set the volume.

Parameters:
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.

Parameters:
graphicArea Window ID of the widget that mplayer should use as video output.

bool MPlayerControlAPI::Stop (  ) 

Stop playing.

Returns:
false if mplayer was allready stopped, else true.

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:

  • If mplayer is playing something, will pause the playing.
  • If mplayer is paused, will resume playing.
  • If mplayer isn't playing anything, will attempt to start playing by calling Play().
Returns:
_MPLAYER_START_SUCCESS If paused or resumed from pause.

error code returned by Play() if attempted to start playing.


Member Data Documentation

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.

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.

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.

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.

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.

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.


The documentation for this class was generated from the following files:

Generated on Thu Mar 3 17:42:04 2011 for Xiaoning's Diary by  doxygen 1.5.9