Reference

Realease:0.3.3
Date:August 23, 2012

Note

You need to start the script as administrator in Windows Vista and Windows 7 (because of UAC)

Module contents

MplayerCtrl.PROPERTIES

a dictionary which contains all available properties of the MplayerCtrl, they are also listed here: Properties

MplayerCtrl.DEBUG

bool, if True debug information is printed to sys.stdout

MplayerCtrl.AO_DRIVER

holds the default “audio out” drivers, to change use the mplayer_args kwarg

MplayerCtrl.VO_DRIVER

holds the default “video out” drivers, to change use the mplayer_args kwarg

Exceptions

exception MplayerCtrl.BaseMplayerCtrlException

This exception is used as the base for all other exceptions; useful to catch all exception thrown by the MplayerCtrl

exception MplayerCtrl.AnsError

The Exception is raised, if an ANS_ERROR is returned by the mplayer process. Reasons can be: * wrong value * unknown property * property is unavailable, e.g. the chapter property used while playing a stream

exception MplayerCtrl.BuildProcessError

The Exception is raised, if the path to the mplayer(.exe) is incorrect or another error occurs while building the mplayer

exception MplayerCtrl.NoMplayerRunning

The Exception is raised, if you try to call a method/property of the MplayerCtrl and no mplayer process is running

New in version 0.2.2.

MplayerCtrl Class

class MplayerCtrl.MplayerCtrl(parent, id, mplayer_path, media_file=None, mplayer_args=None, keep_pause=True, *args, **kwargs)

The MplayerCtrl, wraps the Mplayer into a wx.Panel it can be used as a Panel, but it also handles the mplayer process, using the subprocess-module

Note

The MplayerCtrl class inherits from wx.Panel

Builds the “Panel”.

*args and **kwargs are passed to the wx.Panel directly

Changed in version 0.1.3: behavior of passing arguments to the mplayer

media_file can be a URL, a file (path), stream, everything the mplayer is able to play to.

mplayer_args can be a list or tuple containing additional arguments for the mplayer (like [u’-cache’, u‘1024’])

Changed in version 0.2.0: added keep_pause

keep_pause must be True or False. If keep_pause is True the file won’t be unpaused if another command is executed.

Methods

MplayerCtrl.AltSrcStep(value)

(ASX playlist only) When more than one source is available it selects the next/previous one.

MplayerCtrl.AudioDelay(value[, abs])

Set/adjust the audio delay. If [abs] is not given or is zero, adjust the delay by <value> seconds. If [abs] is nonzero, set the delay to <value> seconds.

MplayerCtrl.Brightness(value[, abs])

Set/adjust the audio delay. If [abs] is not given or is zero, adjust the delay by <value> seconds. If [abs] is nonzero, set the delay to <value> seconds.

MplayerCtrl.ChangeRectangele(val1, val2)

Change the position of the rectangle filter rectangle.

  • <val1> Must be one of the following:
    • 0 = width
    • 1 = height
    • 2 = x position
    • 3 = y position
  • <val2>
    • If <val1> is 0 or 1:
      • Integer amount to add/subtract from the width/height. Positive values add to width/height and negative values subtract from it.
    • If <val1> is 2 or 3:
      • Relative integer amount by which to move the upper left rectangle corner. Positive values move the rectangle right/down and negative values move the rectangle left/up
MplayerCtrl.Contrast(value[, abs])

Set/adjust video contrast. If [abs] is not given or is zero, modifies parameter by <value>. If [abs] is non-zero, parameter is set to <value>. <value> is in the range [-100, 100].

MplayerCtrl.DvbSetChannel(channel_number, card_number)

Set DVB channel

MplayerCtrl.Dvdnav(button_name)

Press the given dvdnav button.

  • up
  • down
  • left
  • right
  • menu
  • select
  • prev
  • mouse
MplayerCtrl.Edlmark()

Write the current position into the EDL file.

MplayerCtrl.ForcedSubsOnly([value])

Write the current position into the EDL file.

MplayerCtrl.FrameDrop(value)

Toggle/set frame dropping mode.

MplayerCtrl.FrameStep()

Play one frame, then pause again.

MplayerCtrl.Gamma(value[, abs])

Set/adjust video gamma. If [abs] is not given or is zero, modifies parameter by <value>. If [abs] is non-zero, parameter is set to <value>. <value> is in the range [-100, 100].

MplayerCtrl.GetAudioBitrate()

Returns the audio bitrate of the current file.

MplayerCtrl.GetAudioCodec()

Returns the audio codec name of the current file.

MplayerCtrl.GetAudioSamples()

Returns the audio frequency and number of channels of the current file.

MplayerCtrl.GetFileName()

Retruns the name of the current file.

MplayerCtrl.GetMetaAlbum()

Returns the “Album” metadata of the current file.

MplayerCtrl.GetMetaArtist()

Returns the “Artist” metadata of the current file.

MplayerCtrl.GetMetaComment()

Returns the “Comment” metadata of the current file.

MplayerCtrl.GetMetaGenre()

Returns the “Genre” metadata of the current file.

MplayerCtrl.GetMetaTile()

Returns the “Title” metadata of the current file.

MplayerCtrl.GetMetaTrack()

Returns the “Track” metadata of the current file.

MplayerCtrl.GetMetaYear()

Returns the “Year” metadata of the current file.

MplayerCtrl.GetPercentPos()

Returns the current position in the file, as integer percentage [0-100].

MplayerCtrl.GetProperty()

Returns the current value of a property. All possible properties => Properties. If property isn’t a “get-property”, raises AnsError

MplayerCtrl.GetSubVisibility()

Returns subtitle visibility (1 == on, 0 == off).

MplayerCtrl.GetTimeLength()

Returns the length of the current file in seconds.

MplayerCtrl.GetTimePos()

Returns the current position in the file in seconds, as float.

MplayerCtrl.GetVideoBitrate()

Returns the video bitrate of the current file.

MplayerCtrl.GetVideoCodec()

Returns out the video codec name of the current file.

MplayerCtrl.GetVideoResolution()

Returns the video resolution of the current file.

MplayerCtrl.GetVoFullscreen()

Returns fullscreen status (1 == fullscreened, 0 == windowed).

MplayerCtrl.Hue(value[, abs])

Set/adjust video hue. If [abs] is not given or is zero, modifies parameter by <value>. If [abs] is non-zero, parameter is set to <value>. <value> is in the range [-100, 100].

MplayerCtrl.is_alive()

Returns True if the process is still alive otherwise False.

Changed in version 0.2.0: Method removed in version, is now a property (process_alive)

MplayerCtrl.KeyDownEvent(value)

Inject <value> key code event into MPlayer.

MplayerCtrl.Loadfile(file_url[, append])

Load the given file/URL, stopping playback of the current file/URL. If <append> is nonzero playback continues and the file/URL is appended to the current playlist instead.

MplayerCtrl.Loadlist(file[, append])

Load the given playlist file, stopping playback of the current file. If <append> is nonzero playback continues and the playlist file is appended to the current playlist instead.

MplayerCtrl.Loop(value[, abs])

Adjust/set how many times the movie should be looped. -1 means no loop, and 0 forever.

MplayerCtrl.Menu(command)

Execute an OSD menu command.

  • up Move cursor up.
  • down Move cursor down.
  • ok Accept selection.
  • cancel Cancel selection.
  • hide Hide the OSD menu.
MplayerCtrl.Mute([value])

Toggle sound output muting or set it to [value] when [value] >= 0 (1 == on, 0 == off).

MplayerCtrl.Osd([level])

Toggle OSD mode or set it to [level] when [level] >= 0.

MplayerCtrl.OsdShowPropertyText(string[, duration[, level]])

Show an expanded property string on the OSD, see -playing-msg for a description of the available expansions. If [duration] is >= 0 the text is shown for [duration] ms. [level] sets the minimum OSD level needed for the message to be visible (default: 0 - always show).

MplayerCtrl.OsdShowText(string[, duration[, level]])

Show <string> on the OSD.

MplayerCtrl.Panscan(value, abs)

Increase or decrease the pan-and-scan range by <value>, 1.0 is the maximum. Negative values decrease the pan-and-scan range. If <abs> is != 0, then the pan-and scan range is interpreted as an absolute range.

MplayerCtrl.Pause()

Pause/unpause the playback.

MplayerCtrl.PtStep(value[, force])

Go to the next/previous entry in the playtree. The sign of <value> tells the direction. If no entry is available in the given direction it will do nothing unless [force] is non-zero.

MplayerCtrl.PtUpStep(value[, force])

Similar to pt_step but jumps to the next/previous entry in the parent list. Useful to break out of the inner loop in the playtree.

MplayerCtrl.Quit()

Sends a quit to the mplayer process, if the mplayer is still alive, process will be terminated (py >= 2.6), if that doesn’t work process will be killed (py >= 2.6), but the widget will not be destroyed Returns True, if the process got terminated successfully, otherwise False

MplayerCtrl.RadioSetChannel(channel)

Switch to <channel>. The ‘channels’ radio parameter needs to be set.

MplayerCtrl.RadioSetFreq(freq)

Set the radio tuner frequency. freq in Mhz

MplayerCtrl.RadioStepChannel(value)

Step forwards (1) or backwards (-1) in channel list. Works only when the ‘channels’ radio parameter was set.

MplayerCtrl.RadioStepFreq(value)

Tune frequency by the <value> (positive - up, negative - down).

MplayerCtrl.Saturation(value[, abs])

Set/adjust video saturation. If [abs] is not given or is zero, modifies parameter by <value>. If [abs] is non-zero, parameter is set to <value>. <value> is in the range [-100, 100].

MplayerCtrl.Screenshot(value)

Take a screenshot. Requires the screenshot filter to be loaded.

  • 0 Take a single screenshot.
  • 1 Start/stop taking screenshot of each frame.
MplayerCtrl.Seek(value[, type_])

Seek to some place in the movie.

  • 0 is a relative seek of +/- <value> seconds (default).
  • 1 is a seek to <value> % in the movie.
  • 2 is a seek to an absolute position of <value> seconds.
MplayerCtrl.SeekChapter(value[, type_])

Seek to the start of a chapter.

  • 0 is a relative seek of +/- <value> chapters (default).
  • 1 is a seek to chapter <value>.
MplayerCtrl.SetMenu(menu_name)

Display the menu named <menu_name>.

MplayerCtrl.SetMousePos(x, y)

Tells MPlayer the coordinates of the mouse in the window. This command doesn’t move the mouse!

MplayerCtrl.SetProperty(property, value)

Sets a property. All possible properties => Properties If property isn’t a “set-property”, raises AnsError

MplayerCtrl.SpeedIncr(value)

Add <value> to the current playback speed.

MplayerCtrl.SpeedMult(value)

Multiply the current speed by <value>.

MplayerCtrl.SpeedSet(value)

Set the speed to <value>.

MplayerCtrl.Start([media_file[, mplayer_args]])

Builds a new process, if the old process got killed by Quit(). Returns True if the process is created successfully, otherwise False.

New in version 0.1.2.

MplayerCtrl.StepProperty(property[, value[, direction]])

Change a property by value, or increase by a default if value is not given or zero. The direction is reversed if direction is less than zero. All possible properties => Properties If property isn’t a “step-property”, raises AnsError

MplayerCtrl.Stop()

Stop playback.

MplayerCtrl.SubAlignment([value])

Toggle/set subtitle alignment.

  • 0 top alignment
  • 1 center alignment
  • 2 bottom alignment
MplayerCtrl.SubDelay(value[, abs])

Adjust the subtitle delay by +/- <value> seconds or set it to <value> seconds when [abs] is nonzero.

MplayerCtrl.SubDemux(value)

Display subtitle specifid by [value] for subtitles from DVD or embedded in media file. The [value] is corresponding to ID_SUBTITLE_ID values reported by ‘-identify’. If [value] is -1, will turn off subtitle display. If [value] less than -1, will cycle all DVD subs or embedded subs.

MplayerCtrl.SubFile(value)

Display subtitle specifid by [value] for file subs. The [value] is corresponding to ID_FILE_SUB_ID values reported by ‘-identify’. If [value] is -1, will turn off subtitle display. If [value] less than -1, will cycle all file subs.

MplayerCtrl.SubLoad(subtitle_file)

Loads subtitles from <subtitle_file>.

MplayerCtrl.SubLog()

Logs the current or last displayed subtitle together with filename and time information to ~/.mplayer/subtitle_log. Intended purpose is to allow convenient marking of bogus subtitles which need to be fixed while watching the movie.

MplayerCtrl.SubPos(value[, abs])

Adjust/set subtitle position.

MplayerCtrl.SubRemove(value)

If the [value] argument is present and non-negative, removes the subtitle file with index [value]. If the argument is omitted or negative, removes all subtitle files.

MplayerCtrl.SubScale(value[, abs])

Adjust the subtitle size by +/- <value> or set it to <value> when [abs] is nonzero.

MplayerCtrl.SubSelect(value)

Display subtitle with index [value]. Turn subtitle display off if [value] is -1 or greater than the highest available subtitle index. Cycle through the available subtitles if [value] is omitted or less than -1. Supported subtitle sources are -sub options on the command line, VOBsubs, DVD subtitles, and Ogg and Matroska text streams. This command is mainly for cycling all subtitles, if you want to set a specific subtitle, use SubFile, SubVob, or SubDemux.

MplayerCtrl.SubSource(source)

Display first subtitle from [source]. Here [source] is an integer: SUB_SOURCE_SUBS (0) for file subs SUB_SOURCE_VOBSUB (1) for VOBsub files SUB_SOURCE_DEMUX (2) for subtitle embedded in the media file or DVD subs. If [source] is -1, will turn off subtitle display. If [source] less than -1, will cycle between the first subtitle of each currently available sources.

MplayerCtrl.SubStep(value)

Step forward in the subtitle list by <value> steps or backwards if <value> is negative.

MplayerCtrl.SubVisibility([value])

Toggle/set subtitle visibility.

MplayerCtrl.SubVob(value)

Display subtitle specifid by [value] for vobsubs. The [value] is corresponding to ID_VOBSUB_ID values reported by ‘-identify’. If [value] is -1, will turn off subtitle display. If [value] less than -1, will cycle all vobsubs.

MplayerCtrl.SwitchAngle([value])

Switch to the DVD angle with the ID [value]. Cycle through the available angles if [value] is omitted or negative.

MplayerCtrl.SwitchAudio([value])

Switch to the audio track with the ID [value]. Cycle through the available tracks if [value] is omitted or negative.

MplayerCtrl.SwitchRatio(value)

Change aspect ratio at runtime. [value] is the new aspect ratio expressed as a float (e.g. 1.77778 for 16/9). There might be problems with some video filters.

MplayerCtrl.SwitchTitle([value])

Switch to the DVD title with the ID [value]. Cycle through the available titles if [value] is omitted or negative.

MplayerCtrl.SwitchVsync([value])

Toggle vsync (1 == on, 0 == off). If [value] is not provided, vsync status is inverted.

MplayerCtrl.TeletextAddDigit(value)

Enter/leave teletext page number editing mode and append given digit to previously entered one.

  • 0..9 Append apropriate digit. (Enables editing mode if called from normal mode, and switches to normal mode when third digit is entered.)
  • Delete last digit from page number. (Backspace emulation, works only in page number editing mode.)

Follow given link on current teletext page. value must be 1,2,3,4,5 or 6

MplayerCtrl.TvLastChannel()

Set the current TV channel to the last one.

MplayerCtrl.TvSetBrightness(value[, abs])

Set TV tuner brightness or adjust it if [abs] is set to 0. value from -100 to 100

MplayerCtrl.TvSetChannel(channel)

Set the current TV channel.

MplayerCtrl.TvSetContrast(value[, abs])

Set TV tuner contrast or adjust it if [abs] is set to 0. value from -100 to 100

MplayerCtrl.TvSetFreq(freq)

Set the TV tuner frequency. freq offset in Mhz

MplayerCtrl.TvSetHue(value[, abs])

Set TV tuner hue or adjust it if [abs] is set to 0. value from -100 to 100

MplayerCtrl.TvSetNorm(norm)

Set the TV tuner norm (PAL, SECAM, NTSC, ...).

MplayerCtrl.TvSetSaturation(value[, abs])

Set TV tuner saturation or adjust it if [abs] is set to 0. value from -100 to 100

MplayerCtrl.TvStartScan()

Start automatic TV channel scanning.

MplayerCtrl.TvStepChanlist()

Change channel list.

MplayerCtrl.TvStepChannel(channel)

Select next/previous TV channel.

MplayerCtrl.TvStepFreq(freq)

Set the TV tuner frequency relative to current value. freq offset in Mhz

MplayerCtrl.TvStepNorm()

Change TV norm.

MplayerCtrl.UseMaster()

Switch volume control between master and PCM.

MplayerCtrl.VoBorder([value])

Toggle/set borderless display.

MplayerCtrl.VobsubLang(*args)

This is a stub linked to SubSelect for backwards compatibility.

MplayerCtrl.VoFullscreen([value])

Toggle/set fullscreen mode

MplayerCtrl.VoOntop([value])

Toggle/set stay-on-top.

MplayerCtrl.VoRootwin([value])

Toggle/set playback on the root window.

Properties

MplayerCtrl.mplayer_path

A string containing the current path to the Mplayer(.exe).

MplayerCtrl.keep_pause

If True it tells the mplayer to keep pause if another command is executed.

MplayerCtrl.playing

True if the a file is playing, otherwise False.

MplayerCtrl.process_alive

returns True if a mplayer process if not False. If process_alive returns False you have to build another process with Start() before you can use the methods of the mpc again.

More properties, this properties are accessible through MplayerCtrl.the_prop and MplayerCtrl.GetProperty(‘the_prop’) (or SetProperty() or StepProperty())

property type min max get set step comment
osdlevel int 0 3 X X X as -osdlevel
speed float 0.01 100 X X X as -speed
loop int -1   X X X as -loop
pause bool 0 1 X     1 if paused, use with pausing_keep_force
filename string     X     file playing wo path
path string     X     file playing
demuxer string     X     demuxer used
stream_pos float 0   X X   position in stream
stream_start float 0   X     start pos in stream
stream_end float 0   X     end pos in stream
stream_length float 0   X     (end - start)
chapter int 0   X X X select chapter
chapters int     X     number of chapters
angle int 0   X X X select angle
length float     X     length of file in seconds
percent_pos int 0 100 X X X position in percent
time_pos float 0   X X X position in seconds
metadata dict     X     list of metadata key/value
volume float 0 100 X X X change volume
balance float -1 1 X X X change audio balance
mute bool 0 1 X X X  
audio_delay float -100 100 X X X  
audio_format int     X      
audio_codec string     X      
audio_bitrate int     X      
samplerate int     X      
channels int     X      
switch_audio int -2 255 X X X select audio stream
switch_angle int -2 255 X X X select DVD angle
switch_title int -2 255 X X X select DVD title
fullscreen bool 0 1 X X X  
deinterlace bool 0 1 X X X  
ontop bool 0 1 X X X  
rootwin bool 0 1 X X X  
border bool 0 1 X X X  
framedropping int 0 2 X X X 1 = soft, 2 = hard
gamma int -100 100 X X X  
brightness int -100 100 X X X  
contrast int -100 100 X X X  
saturation int -100 100 X X X  
hue int -100 100 X X X  
panscan float 0 1 X X X  
vsync bool 0 1 X X X  
video_format int     X      
video_codec string     X      
video_bitrate int     X      
width int     X     “display” width
height int     X     “display” height
fps float     X      
aspect float     X      
switch_video int -2 255 X X X select video stream
switch_program int -1 65535 X X X (see TAB default keybind)
sub int -1   X X X select subtitle stream
sub_source int -1 2 X X X select subtitle source
sub_file int -1   X X X select file subtitles
sub_vob int -1   X X X select vobsubs
sub_demux int -1   X X X select subs from demux
sub_delay float     X X X  
sub_pos int 0 100 X X X subtitle position
sub_alignment int 0 2 X X X subtitle alignment
sub_visibility bool 0 1 X X X show/hide subtitles
sub_forced_only bool 0 1 X X X  
sub_scale float 0 100 X X X subtitles font size
tv_brightness int -100 100 X X X  
tv_contrast int -100 100 X X X  
tv_saturation int -100 100 X X X  
tv_hue int -100 100 X X X  
teletext_page int 0 799 X X X  
teletext_subpage int 0 64 X X X  
teletext_mode bool 0 1 X X X 0 - off, 1 - on
teletext_format int 0 3 X X X 0 - opaque, 1 - transparent, 2 - opaque inverted, 3 - transp. inv.
teletext_half_page int 0 2 X X X 0 - off, 1 - top half, 2- bottom half

Events

MplayerCtrl.EVT_MEDIA_STARTED

The event is posted to the Parent of the MplayerCtrl, when a new playback begins

MplayerCtrl.EVT_MEDIA_FINISHED

The event is posted to the Parent of the MplayerCtrl, when the mediafile is finished

MplayerCtrl.EVT_PROCESS_STARTED

The event is posted to the Parent of the MplayerCtrl, when the mplayer process is built and started

MplayerCtrl.EVT_PROCESS_STOPPED

The event is posted to the Parent of the MplayerCtrl, when the process stopped, the event is not posted if the Parent-Window is destroyed

MplayerCtrl.EVT_STDERR

The event is posted to the Parent of the MplayerCtrl, when data arrives from the stderr of the mplayer process. You get the data easily through MplayerCtrl.Stderr.data

MplayerCtrl.EVT_STDOUT

The event is posted to the Parent of the MplayerCtrl, when data arrives from the stdout of the mplayer process. You get the data easily through MplayerCtrl.Stdout.data

New in version 0.2.3.

Event Interface

MplayerCtrl.Stderr.data

A string containing the data read from the stderr of the mplayer process

MplayerCtrl.Stdout.data

A string containing the data read from the stdout of the mplayer process

New in version 0.2.3.

Examples

A very easy example. A wx.Frame with the MplayerCtrl and the MplayerCtrl plays a file (testmovie.mpg):

import wx
import MplayerCtrl as mpc

class Frame(wx.Frame):
    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, id)

        self.mpc = mpc.MplayerCtrl(self, -1, u'mplayer.exe', media_file=u'testmovie.mpg')

        self.Show()

if __name__ == '__main__':
    app = wx.App(redirect=False)
    f = Frame(None, -1)
    app.MainLoop()

Another example, now with events:

import wx
import MplayerCtrl as mpc

class Frame(wx.Frame):
    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, id)

        self.mpc = mpc.MplayerCtrl(self, -1, u'mplayer.exe', media_file=u'testmovie.mpg')

        self.Bind(mpc.EVT_MEDIA_STARTED, self.on_media_started)
        self.Bind(mpc.EVT_MEDIA_FINISHED, self.on_media_finished)
        self.Bind(mpc.EVT_PROCESS_STARTED, self.on_process_started)
        self.Bind(mpc.EVT_PROCESS_STOPPED, self.on_process_stopped)

        self.Show()

    def on_media_started(self, evt):
        print 'Media started!'
    def on_media_finished(self, evt):
        print 'Media finished!'
        self.mpc.Quit() # quits the Mplayer-process
    def on_process_started(self, evt):
        print 'Process started!'
    def on_process_stopped(self, evt):
        print 'Process stopped!'

if __name__ == '__main__':
    app = wx.App(redirect=False)
    f = Frame(None, -1)
    app.MainLoop()

Read more in the Tutorial.

Table Of Contents

Previous topic

Tutorial

Next topic

Release Notes and Changelog

This Page