Difference between revisions of "TMPlayerControl"

From Lazarus wiki
m (Categories)
m (Download: Fixed broken url)
 
(7 intermediate revisions by one other user not shown)
Line 12: Line 12:
 
=== Download ===
 
=== Download ===
 
The latest stable release can be found at svn:
 
The latest stable release can be found at svn:
svn co https://svn.code.sf.net/p/lazarus-ccr/svn/components/mplayer
+
 
 +
<pre>
 +
svn checkout svn://svn.code.sf.net/p/lazarus-ccr/svn/components/mplayer mplayer
 +
</pre>
  
 
mplayer, and additional codecs, can be downloaded from http://www.mplayerhq.hu/.  The additional codecs must be installed separately, but are not necessary for many common formats.
 
mplayer, and additional codecs, can be downloaded from http://www.mplayerhq.hu/.  The additional codecs must be installed separately, but are not necessary for many common formats.
  
== Caveat ==
+
== Distributing mplayer ==
This wiki was written for mplayer 0.1.2. At the time of writing, the patch for mplayer 0.1.2 has not been accepted/applied.
+
{{Warning| mplayer can be easily bundled with your application installation. However mplayer uses FFmpeg and the legal licensing warning at http://www.ffmpeg.org/legal.html could also apply (see last question under Mini-Patent FAQ). <br/>
 +
It is recommended that the end-user install mplayer on their system instead of it being distributed with your application.}}
  
 
== Usage ==
 
== Usage ==
The control can be dropped on any form, and represents the video playback area.
+
The control can be dropped on any form, and incorporates the video playback area.<br/> 
 +
Additional controls such as Trackbars for progess/volume and buttons for playback control need to be added manually, with their values being set during the appropriate events.
  
mplayer must be available on the end user system.  Either installed with the mplayer folder being in the PATH environment variable, or with the MPlayerPath property pointing to the mplayer executable.
+
mplayer must be available on the end user system.  Either installed with the mplayer folder being in the PATH environment variable, or with the MPlayerPath property pointing to the mplayer executable.
TMPlayerControl only implements a very small set of mplayer features:  Play, Stop, Pause, Loop, Volume, Duration, Position and GrabImage.
+
 
TMPlayerControl sets a minor selection of mplayer properties at run time.  Additional parameters can be set via StartParam. See http://mplayerhq.hu/DOCS/man/en/mplayer.1.html#GENERAL%20OPTIONS for a full list of available parameters.   
+
TMPlayerControl only implements a very small set of mplayer features:  '''Play''', '''Stop''', '''Pause''', '''Loop''', '''Volume''', '''Duration''', '''Position''' and '''GrabImage''', essentially focusing on anything required for multimedia playback.
TMPlayerControl controls mplayer in slave mode.  For a full list of available slave comamnds visit http://www.mplayerhq.hu/DOCS/tech/slave.txt or enter the following at the command prompt.
+
 
 +
TMPlayerControl sets a minor selection of mplayer properties at run time.  Additional parameters can be set via '''StartParam'''.<br/> 
 +
See http://mplayerhq.hu/DOCS/man/en/mplayer.1.html#GENERAL%20OPTIONS for a full list of available parameters.
 +
   
 +
TMPlayerControl controls mplayer in slave mode.  Slave commands can be sent directly to mplayer after multimedia is loaded (i.e. after calling Play) by using '''SendMPlayerCommand(Cmd: string);'''<br/>
 +
'''SendMPlayerCommand''' is not needed for simple video playback, and is made available for advanced mplayer features.<br/>
 +
For a full list of available slave comamnds visit http://www.mplayerhq.hu/DOCS/tech/slave.txt or enter the following at the command prompt.
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
mplayer -input cmdlist
 
mplayer -input cmdlist
 
</syntaxhighlight>
 
</syntaxhighlight>
Slave commands can be sent directly to mplayer after multimedia is loaded (i.e. after calling Play) by using SendMPlayerCommand(Cmd: string);
 
  
 
=== Example ===
 
=== Example ===
 
In the examples folder, see FullFeatured\mplayerTestHarness.lpr for a full demonstration of TMPlayerControl capabilities, as well as additional functionality for querying mplayer for available commands.
 
In the examples folder, see FullFeatured\mplayerTestHarness.lpr for a full demonstration of TMPlayerControl capabilities, as well as additional functionality for querying mplayer for available commands.
 +
 +
[[File:FullFeaturedDemo.jpg|400px|thumb|none|FullFeatured example program]]
  
 
=== Methods ===
 
=== Methods ===
 +
The following Methods and Properties are available:
 
{| class="wikitable"
 
{| class="wikitable"
 
! Method
 
! Method
Line 40: Line 53:
 
|-
 
|-
 
| function FindMPlayerPath : Boolean;
 
| function FindMPlayerPath : Boolean;
| TMPlayerControl searches for mplayer in the PATH or in a subfolder of the application called "mplayer". Returns True if found
+
| TMPlayerControl searches for mplayer in the PATH or in a subfolder of the application folder called "mplayer". If found, then sets MPlayerPath and returns True
 
|-
 
|-
 
| property MPlayerPath: string;
 
| property MPlayerPath: string;
| Full path to the mplayer executable. Either populated by FindMPlayerPath, or programmatically
+
| R/W.  Full path to the mplayer executable. Either populated by FindMPlayerPath, or programmatically
 
|-
 
|-
 
| property StartParam: string;
 
| property StartParam: string;
| Any additional parameters to be sent to mplayer before the multimedia file is initialised.see http://mplayerhq.hu/DOCS/man/en/mplayer.1.html#GENERAL%20OPTIONS for a full set of available parameters
+
| R/W.  Any additional parameters to be sent to mplayer before the multimedia file is initialised. See http://mplayerhq.hu/DOCS/man/en/mplayer.1.html#GENERAL%20OPTIONS for a full set of available parameters
 
|-
 
|-
 
| property Filename: string;
 
| property Filename: string;
| The multimedia file to be played
+
| R/W.  The multimedia file to be played
 
|-
 
|-
 
| procedure Play;
 
| procedure Play;
| All the above must be configured correct before this command is called. This initialises mplayer, putting it into slave mode with the file loaded. mplayer will automatically start playing the file.
+
| All the above must be configured correct before this command is called. This initialises mplayer, putting it into slave mode with the file loaded. mplayer will automatically start playing the file.
 
|-
 
|-
 
| procedure Stop;
 
| procedure Stop;
| This stops the video file playing, which in turn stops mplayer. After this is called, many of the properties will no longer be available.
+
| This stops the video file playing, which in turn stops mplayer. After this is called, many of the properties will no longer be available.
 
|-
 
|-
 
| property Loop: integer;
 
| property Loop: integer;
| This instructs mplayer to loop the video. -1 no, 0 forever, 1 once, 2 twice, ...
+
| R/W.  This instructs mplayer to loop the video. -1 no, 0 forever, 1 once, 2 twice, ...
 
|-
 
|-
 
| property Paused: boolean;
 
| property Paused: boolean;
| Is the file paused?
+
| R/W.  Either set or retrieve the paused state.
 
|-
 
|-
 
| function Running: boolean;
 
| function Running: boolean;
| Is mplayer running?
+
| R/O.  Is mplayer running?
 
|-
 
|-
 
| function Playing: boolean;
 
| function Playing: boolean;
| Is mplaying running with a file loaded? There is only a small window in time between the file stopping and mplayer itself stopping running.
+
| R/O.  Is mplaying running with a file loaded? There is only a small window in time between the file stopping and mplayer itself stopping running.
 
|-
 
|-
 
| property ImagePath: string;
 
| property ImagePath: string;
| The folder you want captured image grabs to be saved in.
+
| R/W.  The folder you want captured image grabs to be saved in.
 
|-
 
|-
 
| procedure GrabImage;
 
| procedure GrabImage;
| Instruct mplayer to grab an image. In testing, success of this call is dependent upon a combination of the codec mplayer is using, and the renderer being used. Under windows, optimal results were returned with the direct3d renderer (-vo direct3d)
+
| Instruct mplayer to grab an image. In testing, success of this call is dependent upon a combination of the codec mplayer is using, and the renderer being used. Under windows, optimal results were returned with the direct3d renderer (-vo direct3d)
 
|-
 
|-
 
| property LastImageFilename: String;
 
| property LastImageFilename: String;
| The filename of the last image grabbed. The filename of the last image grabbed is also passed as a parameter to the OnGrabImage event.
+
| R/O.  The filename of the last image grabbed. The filename of the last image grabbed is also passed as a parameter to the OnGrabImage event.
 
|-
 
|-
 
| property Volume: integer;
 
| property Volume: integer;
| 0 = mute. 100 = max
+
| R/W.  0 = mute. 100 = max
 
|-
 
|-
 
| property Rate: single;
 
| property Rate: single;
| Playback rate. 1 = normal speed. mplayer allows values between 0.1 and 100 (i.e. no reverse)
+
| R/W.  Playback rate. 1 = normal speed. mplayer allows values between 0.1 and 100 (i.e. no reverse)
 
|-
 
|-
 
| property Duration: single;
 
| property Duration: single;
| The length of the loaded video file in seconds.
+
| R/O.  The length of the loaded video file in seconds.
 
|-
 
|-
 
| property Position: single;
 
| property Position: single;
| The current position of the video file in seconds. This information is queried every half second, so during playback at normal speed, there is only a half second accuracy.
+
| R/W.  Used to set or retrieve the current position of the video file in seconds.  
 +
Current video position is queried every half second, so during playback at normal speed, there is only a half second accuracy.
 
|-
 
|-
 
| property VideoInfo: TVideoInfo;
 
| property VideoInfo: TVideoInfo;
| Only populated after OnPlay event. Record containing Codec, bitrate, width, height etc
+
| R/O.  Only populated after OnPlay event. Record containing Codec, bitrate, width, height etc
 
|-
 
|-
 
| property AudioInfo: TAudioInfo;
 
| property AudioInfo: TAudioInfo;
| Only populated after OnPlay event. Recording containing Codec, SampleRate, Bitrate etc.
+
| R/O.  Only populated after OnPlay event. Record containing Codec, SampleRate, Bitrate etc.
 
|-
 
|-
 
| procedure SendMPlayerCommand(Cmd: string);
 
| procedure SendMPlayerCommand(Cmd: string);
| Additional commands can be sent directly to mplayer, and the results can be queried with the OnFeedback event. See http://www.mplayerhq.hu/DOCS/tech/slave.txt for a full list of available commands
+
| Additional commands can be sent directly to mplayer, and the results can be queried with the OnFeedback event. See http://www.mplayerhq.hu/DOCS/tech/slave.txt for a full list of available commands
 
|}
 
|}
 
=== Events ===
 
=== Events ===
Line 124: Line 138:
 
|-
 
|-
 
| OnClick, OnMouseUp, OnMouseDown, OnMouseWheel
 
| OnClick, OnMouseUp, OnMouseDown, OnMouseWheel
| Standard LCL events
+
| Standard LCL events.  OnMouseWheel can be used to allow the video to scroll through the video.  An example of this is provided in the FullFeatured demo.
 
|}
 
|}
 +
 +
== See also ==
 +
[[Video Playback Libraries]]
  
 
[[Category:Video]]
 
[[Category:Video]]
 
[[Category:Multimedia]]
 
[[Category:Multimedia]]
[[Category:Video Playback Libraries]]
 
 
[[Category:Lazarus-CCR]]
 
[[Category:Lazarus-CCR]]

Latest revision as of 11:13, 28 December 2019

Introduction

TMPlayerControl is a LCL control that embeds "mplayer" - a movie player available on several platforms. TMPlayerControl only works under X/gtk2 and Windows. TMPlayerControl can be used to play any mplayer supported video or audio file.

Authors

Mattias Gaertner (package maintainer)
Michael Koecher (contributor)
Mike Thompson (contributor)

License

Modified LGPL (same as FPC RTL and Lazarus LCL).

Download

The latest stable release can be found at svn:

svn checkout svn://svn.code.sf.net/p/lazarus-ccr/svn/components/mplayer mplayer

mplayer, and additional codecs, can be downloaded from http://www.mplayerhq.hu/. The additional codecs must be installed separately, but are not necessary for many common formats.

Distributing mplayer

Warning-icon.png

Warning: mplayer can be easily bundled with your application installation. However mplayer uses FFmpeg and the legal licensing warning at http://www.ffmpeg.org/legal.html could also apply (see last question under Mini-Patent FAQ).
It is recommended that the end-user install mplayer on their system instead of it being distributed with your application.

Usage

The control can be dropped on any form, and incorporates the video playback area.
Additional controls such as Trackbars for progess/volume and buttons for playback control need to be added manually, with their values being set during the appropriate events.

mplayer must be available on the end user system. Either installed with the mplayer folder being in the PATH environment variable, or with the MPlayerPath property pointing to the mplayer executable.

TMPlayerControl only implements a very small set of mplayer features: Play, Stop, Pause, Loop, Volume, Duration, Position and GrabImage, essentially focusing on anything required for multimedia playback.

TMPlayerControl sets a minor selection of mplayer properties at run time. Additional parameters can be set via StartParam.
See http://mplayerhq.hu/DOCS/man/en/mplayer.1.html#GENERAL%20OPTIONS for a full list of available parameters.

TMPlayerControl controls mplayer in slave mode. Slave commands can be sent directly to mplayer after multimedia is loaded (i.e. after calling Play) by using SendMPlayerCommand(Cmd: string);
SendMPlayerCommand is not needed for simple video playback, and is made available for advanced mplayer features.
For a full list of available slave comamnds visit http://www.mplayerhq.hu/DOCS/tech/slave.txt or enter the following at the command prompt.

mplayer -input cmdlist

Example

In the examples folder, see FullFeatured\mplayerTestHarness.lpr for a full demonstration of TMPlayerControl capabilities, as well as additional functionality for querying mplayer for available commands.

FullFeatured example program

Methods

The following Methods and Properties are available:

Method Description
function FindMPlayerPath : Boolean; TMPlayerControl searches for mplayer in the PATH or in a subfolder of the application folder called "mplayer". If found, then sets MPlayerPath and returns True
property MPlayerPath: string; R/W. Full path to the mplayer executable. Either populated by FindMPlayerPath, or programmatically
property StartParam: string; R/W. Any additional parameters to be sent to mplayer before the multimedia file is initialised. See http://mplayerhq.hu/DOCS/man/en/mplayer.1.html#GENERAL%20OPTIONS for a full set of available parameters
property Filename: string; R/W. The multimedia file to be played
procedure Play; All the above must be configured correct before this command is called. This initialises mplayer, putting it into slave mode with the file loaded. mplayer will automatically start playing the file.
procedure Stop; This stops the video file playing, which in turn stops mplayer. After this is called, many of the properties will no longer be available.
property Loop: integer; R/W. This instructs mplayer to loop the video. -1 no, 0 forever, 1 once, 2 twice, ...
property Paused: boolean; R/W. Either set or retrieve the paused state.
function Running: boolean; R/O. Is mplayer running?
function Playing: boolean; R/O. Is mplaying running with a file loaded? There is only a small window in time between the file stopping and mplayer itself stopping running.
property ImagePath: string; R/W. The folder you want captured image grabs to be saved in.
procedure GrabImage; Instruct mplayer to grab an image. In testing, success of this call is dependent upon a combination of the codec mplayer is using, and the renderer being used. Under windows, optimal results were returned with the direct3d renderer (-vo direct3d)
property LastImageFilename: String; R/O. The filename of the last image grabbed. The filename of the last image grabbed is also passed as a parameter to the OnGrabImage event.
property Volume: integer; R/W. 0 = mute. 100 = max
property Rate: single; R/W. Playback rate. 1 = normal speed. mplayer allows values between 0.1 and 100 (i.e. no reverse)
property Duration: single; R/O. The length of the loaded video file in seconds.
property Position: single; R/W. Used to set or retrieve the current position of the video file in seconds.

Current video position is queried every half second, so during playback at normal speed, there is only a half second accuracy.

property VideoInfo: TVideoInfo; R/O. Only populated after OnPlay event. Record containing Codec, bitrate, width, height etc
property AudioInfo: TAudioInfo; R/O. Only populated after OnPlay event. Record containing Codec, SampleRate, Bitrate etc.
procedure SendMPlayerCommand(Cmd: string); Additional commands can be sent directly to mplayer, and the results can be queried with the OnFeedback event. See http://www.mplayerhq.hu/DOCS/tech/slave.txt for a full list of available commands

Events

The following events are available:

Event Description
OnPlay This event is broadcast immediately after mplayer finishes initialising the file to be played. At the point this event is launched the VideoInfo and AudioInfo records will be populated
OnPlaying This event is broadcast regularly while the multimedia file is playing. You can use this event to keep a TTrackbar synchronised with the playback
OnStop This event is broadcast when the multimedia file stops. As soon as this event is launched the VideoInfo and AudioInfo records are cleared
OnFeedback mplayer is polled frequently by TMPlayerControl. Most text output on the standard console will be available through the TStringList parameter. Some housekeeping information (such as the frequent requests for video position) are removed from this TStringList parameter.
OnError mplayer is polled frequently by TMPlayerControl. All text output on the error console will be available through the TStringList parameter.
OnGrabImage This event is raised following an GrabImage request. If successfull, then the filename to the image is returned.
OnClick, OnMouseUp, OnMouseDown, OnMouseWheel Standard LCL events. OnMouseWheel can be used to allow the video to scroll through the video. An example of this is provided in the FullFeatured demo.

See also

Video Playback Libraries