QMPwidget
Classes | Public Types | Public Slots | Signals | Public Member Functions | Protected Member Functions
QMPwidget Class Reference

List of all members.

Classes

struct  MediaInfo

Public Types

enum  State
enum  Mode
enum  SeekMode

Public Slots

void start (const QStringList &args=QStringList())
void load (const QString &url)
void play ()
void pause ()
void stop ()
bool seek (int offset, int whence=AbsoluteSeek)
bool seek (double offset, int whence=AbsoluteSeek)
void toggleFullScreen ()
void writeCommand (const QString &command)

Signals

void stateChanged (int state)
void error (const QString &reason)
void readStandardOutput (const QString &line)
void readStandardError (const QString &line)

Public Member Functions

 QMPwidget (QWidget *parent=0)
virtual ~QMPwidget ()
State state () const
MediaInfo mediaInfo () const
double tell () const
QProcess * process () const
void setMode (Mode mode)
Mode mode () const
void setVideoOutput (const QString &output)
QString videoOutput () const
void setMPlayerPath (const QString &path)
QString mplayerPath () const
QString mplayerVersion ()
void setSeekSlider (QAbstractSlider *slider)
void setVolumeSlider (QAbstractSlider *slider)
void showImage (const QImage &image)
virtual QSize sizeHint () const

Protected Member Functions

virtual void mouseDoubleClickEvent (QMouseEvent *event)
virtual void keyPressEvent (QKeyEvent *event)
virtual void resizeEvent (QResizeEvent *event)

Detailed Description

A Qt widget for embedding MPlayer.

Overview

MPlayer communication

If you want to communicate with MPlayer through its slave mode protocol, you can use the writeCommand() slot. If MPlayer writes to its standard output or standard error channel, the signals readStandardOutput() and readStandardError() will be emitted.

Graphical controls

You can connect sliders for seeking and volume adjustment to an instance of this class. Please use setSeekSlider() and setVolumeSlider(), respectively.

Usage example

A minimal example using this widget to play a low-res version of Big Buck Bunny might look as follows. Please note that the actual movie URL has been shortened for the sake of clarity.

#include <QApplication>
#include "qmpwidget.h"

// Program entry point
int main(int argc, char **argv)
{
        QApplication app(argc, argv);

        QMPwidget widget;
        widget.show();
        widget.start(QStringList("http://tinyurl.com/2vs2kg5"));

        return app.exec();
}

For further information about this project, please refer to the main page.


Member Enumeration Documentation

MPlayer state.

This enumeration is somewhat identical to Phonon's State enumeration, except that it has an additional member which is used when the MPlayer process has not been started yet (NotStartedState)

ConstantValueDescription
QMPwidget::NotStartedState -1 The Mplayer process has not been started yet or has already terminated.
QMPwidget::IdleState 0 The MPlayer process has been started, but is idle and waiting for commands.
QMPwidget::LoadingState 1 The media file is being loaded, but playback has not been started yet.
QMPwidget::StoppedState 2 This constant is deprecated and is not being used
QMPwidget::PlayingState 3
QMPwidget::BufferingState 4
QMPwidget::PausedState 5
QMPwidget::ErrorState 6

Video playback modes.

This enumeration describes valid modes for video playback. Please see Video playback modes for a detailed description of both modes.

ConstantValueDescription
QMPwidget::EmbeddedMode 0 MPlayer will render directly into a Qt widget.
QMPwidget::PipedMode 1 MPlayer will write the video data into a FIFO which will be parsed in a seperate thread.
The frames will be rendered by QMPwidget.

Seeking modes.

This enumeration describes valid modes for seeking the media stream.

ConstantValueDescription
QMPwidget::RelativeSeek 0 Relative seek in seconds
QMPwidget::PercantageSeek 1 Seek to a position given by a percentage of the whole movie duration
QMPwidget::AbsoluteSeek 2 Seek to a position given by an absolute time

Constructor & Destructor Documentation

QMPwidget::QMPwidget ( QWidget *  parent = 0)

Constructor.

Parameters:
parentParent widget
QMPwidget::~QMPwidget ( ) [virtual]

Destructor.

This function will ask the MPlayer process to quit and block until it has really finished.


Member Function Documentation

QMPwidget::State QMPwidget::state ( ) const

Returns the current MPlayer process state.

Returns:
The process state
QMPwidget::MediaInfo QMPwidget::mediaInfo ( ) const

Returns the current media info object.

Please check QMPwidget::MediaInfo::ok to make sure the media information has been fully parsed.

Returns:
The media info object
double QMPwidget::tell ( ) const

Returns the current playback position.

Returns:
The current playback position in seconds
See also:
seek()
QProcess * QMPwidget::process ( ) const

Returns the MPlayer process.

Returns:
The MPlayer process
void QMPwidget::setMode ( Mode  mode)

Sets the video playback mode.

Please see Video playback modes for a discussion of the available modes.

Parameters:
modeThe video playback mode
See also:
mode()
QMPwidget::Mode QMPwidget::mode ( ) const

Returns the current video playback mode.

Returns:
The current video playback mode
See also:
setMode()
void QMPwidget::setVideoOutput ( const QString &  output)

Sets the video output mode.

The video output mode string will be passed to MPlayer using its -vo option. Please see http://www.mplayerhq.hu/DOCS/HTML/en/video.html for an overview of available video output modes.

Per default, this string will have the following values:

SystemConfigurationValue
Windows "directx,directx:noaccel"
X11 Compiled without OpenGL support "xv"
X11 Compiled with OpenGL support "gl2,gl,xv"
Mac OS X Compiled without OpenGL support "quartz"
Mac OS X Compiled with OpenGL support "gl,quartz"
Parameters:
outputThe video output mode string
See also:
videoOutput()
QString QMPwidget::videoOutput ( ) const

Returns the current video output mode.

Returns:
The current video output mode
See also:
setVideoOutput()
void QMPwidget::setMPlayerPath ( const QString &  path)

Sets the path to the MPlayer executable.

Per default, it is assumed the MPlayer executable is available in the current OS path. Therefore, this value is set to "mplayer".

Parameters:
pathPath to the MPlayer executable
See also:
mplayerPath()
QString QMPwidget::mplayerPath ( ) const

Returns the current path to the MPlayer executable.

Returns:
The path to the MPlayer executable
See also:
setMPlayerPath()
QString QMPwidget::mplayerVersion ( )

Returns the version string of the MPlayer executable.

If the mplayer

Returns:
The version string of the MPlayer executable
void QMPwidget::setSeekSlider ( QAbstractSlider *  slider)

Sets a seeking slider for this widget.

void QMPwidget::setVolumeSlider ( QAbstractSlider *  slider)

Sets a volume slider for this widget.

void QMPwidget::showImage ( const QImage &  image)

Shows a custom image.

This function sets a custom image that will be shown instead of the MPlayer video output. In order to show MPlayer's output again, call this function with a null image.

Note:
If the current playback mode is not set to PipeMode, this function will have no effect if MPlayer draws to the widget.
Parameters:
imageCustom image
QSize QMPwidget::sizeHint ( ) const [virtual]

Returns a suitable size hint for this widget.

This function is used internally by Qt.

void QMPwidget::start ( const QStringList &  args = QStringList()) [slot]

Starts the MPlayer process with the given arguments.

If there's another process running, it will be terminated first. MPlayer will be run in idle mode and is avaiting your commands, e.g. via load().

Parameters:
argsMPlayer command line arguments
void QMPwidget::load ( const QString &  url) [slot]

Loads a file or url and starts playback.

Parameters:
urlFile patho or url
void QMPwidget::play ( ) [slot]

Resumes playback.

void QMPwidget::pause ( ) [slot]

Pauses playback.

void QMPwidget::stop ( ) [slot]

Stops playback.

bool QMPwidget::seek ( int  offset,
int  whence = AbsoluteSeek 
) [slot]

Media playback seeking.

Parameters:
offsetSeeking offset in seconds
whenceSeeking mode
Returns:
true If the seeking mode is valid
See also:
tell()
bool QMPwidget::seek ( double  offset,
int  whence = AbsoluteSeek 
) [slot]

Media playback seeking.

Parameters:
offsetSeeking offset in seconds
whenceSeeking mode
Returns:
true If the seeking mode is valid
See also:
tell()
void QMPwidget::toggleFullScreen ( ) [slot]

Toggles full-screen mode.

void QMPwidget::writeCommand ( const QString &  command) [slot]

Sends a command to the MPlayer process.

Since MPlayer is being run in slave mode, it reads commands from the standard input. It is assumed that the interface provided by this class might not be sufficient for some situations, so you can use this functions to directly control the MPlayer process.

For a complete list of commands for MPlayer's slave mode, see http://www.mplayerhq.hu/DOCS/tech/slave.txt .

Parameters:
commandThe command line. A newline character will be added internally.
void QMPwidget::mouseDoubleClickEvent ( QMouseEvent *  event) [protected, virtual]

Mouse double click event handler.

This implementation will toggle full screen and accept the event

Parameters:
eventMouse event
void QMPwidget::keyPressEvent ( QKeyEvent *  event) [protected, virtual]

Keyboard press event handler.

This implementation tries to resemble the classic MPlayer interface. For a full list of supported key codes, see Keyboard control.

Parameters:
eventKey event
void QMPwidget::resizeEvent ( QResizeEvent *  event) [protected, virtual]

Resize event handler.

If you reimplement this function, you need to call this handler, too.

Parameters:
eventResize event
void QMPwidget::stateChanged ( int  state) [signal]

Emitted if the state has changed.

This signal is emitted when the state of the MPlayer process changes.

Parameters:
stateThe new state
void QMPwidget::error ( const QString &  reason) [signal]

Emitted if the state has changed to QMPwidget::ErrorState.

This signal is emitted when the state of the MPlayer process changes to QMPwidget::ErrorState.

Parameters:
reasonTextual error description (may be empty)
void QMPwidget::readStandardOutput ( const QString &  line) [signal]

Signal for reading MPlayer's standard output.

This signal is emitted when MPlayer wrote a line of text to its standard output channel.

void QMPwidget::readStandardError ( const QString &  line) [signal]

Signal for reading MPlayer's standard error.

This signal is emitted when MPlayer wrote a line of text to its standard error channel.


The documentation for this class was generated from the following files:
 All Classes Functions Enumerations