========= Reference ========= .. module:: MplayerCtrl :Realease: |version| :Date: |today| * `Mplayer-Documentation `_ (args etc.) * Commands: http://www.mplayerhq.hu/DOCS/tech/slave.txt (similiar to the MplayerCtrl (e.g. get_property changed to GetProperty and gamma to Gamma) .. note:: You need to start the script as administrator in Windows Vista and Windows 7 (because of UAC) Module contents --------------- .. data:: PROPERTIES a dictionary which contains all available properties of the :class:`MplayerCtrl`, they are also listed here: :ref:`reference-props` .. data:: DEBUG bool, if True debug information is printed to sys.stdout .. data:: AO_DRIVER holds the default "audio out" drivers, to change use the mplayer_args kwarg .. data:: 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 .. versionadded:: 0.2.2 MplayerCtrl Class ----------------- .. class:: 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 .. versionchanged:: 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']) .. versionchanged:: 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 ======= .. method:: AltSrcStep(value) (ASX playlist only) When more than one source is available it selects the next/previous one. .. method:: AudioDelay(value[, abs]) Set/adjust the audio delay. If [abs] is not given or is zero, adjust the delay by seconds. If [abs] is nonzero, set the delay to seconds. .. method:: Brightness(value[, abs]) Set/adjust the audio delay. If [abs] is not given or is zero, adjust the delay by seconds. If [abs] is nonzero, set the delay to seconds. .. method:: ChangeRectangele(val1, val2) Change the position of the rectangle filter rectangle. * Must be one of the following: * 0 = width * 1 = height * 2 = x position * 3 = y position * * If 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 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 .. method:: Contrast(value[, abs]) Set/adjust video contrast. If [abs] is not given or is zero, modifies parameter by . If [abs] is non-zero, parameter is set to . is in the range [-100, 100]. .. method:: DvbSetChannel(channel_number, card_number) Set DVB channel .. method:: Dvdnav(button_name) Press the given dvdnav button. * up * down * left * right * menu * select * prev * mouse .. method:: Edlmark() Write the current position into the EDL file. .. method:: ForcedSubsOnly([value]) Write the current position into the EDL file. .. method:: FrameDrop(value) Toggle/set frame dropping mode. .. method:: FrameStep() Play one frame, then pause again. .. method:: Gamma(value[, abs]) Set/adjust video gamma. If [abs] is not given or is zero, modifies parameter by . If [abs] is non-zero, parameter is set to . is in the range [-100, 100]. .. method:: GetAudioBitrate() Returns the audio bitrate of the current file. .. method:: GetAudioCodec() Returns the audio codec name of the current file. .. method:: GetAudioSamples() Returns the audio frequency and number of channels of the current file. .. method:: GetFileName() Retruns the name of the current file. .. method:: GetMetaAlbum() Returns the "Album" metadata of the current file. .. method:: GetMetaArtist() Returns the "Artist" metadata of the current file. .. method:: GetMetaComment() Returns the "Comment" metadata of the current file. .. method:: GetMetaGenre() Returns the "Genre" metadata of the current file. .. method:: GetMetaTile() Returns the "Title" metadata of the current file. .. method:: GetMetaTrack() Returns the "Track" metadata of the current file. .. method:: GetMetaYear() Returns the "Year" metadata of the current file. .. method:: GetPercentPos() Returns the current position in the file, as integer percentage [0-100]. .. method:: GetProperty() Returns the current value of a property. All possible properties => :ref:`reference-props`. If property isn't a "get-property", raises :exc:`~MplayerCtrl.AnsError` .. method:: GetSubVisibility() Returns subtitle visibility (1 == on, 0 == off). .. method:: GetTimeLength() Returns the length of the current file in seconds. .. method:: GetTimePos() Returns the current position in the file in seconds, as float. .. method:: GetVideoBitrate() Returns the video bitrate of the current file. .. method:: GetVideoCodec() Returns out the video codec name of the current file. .. method:: GetVideoResolution() Returns the video resolution of the current file. .. method:: GetVoFullscreen() Returns fullscreen status (1 == fullscreened, 0 == windowed). .. method:: Hue(value[, abs]) Set/adjust video hue. If [abs] is not given or is zero, modifies parameter by . If [abs] is non-zero, parameter is set to . is in the range [-100, 100]. .. method:: is_alive() Returns True if the process is still alive otherwise False. .. versionchanged:: 0.2.0 Method removed in version, is now a property (process_alive) .. method:: KeyDownEvent(value) Inject key code event into MPlayer. .. method:: Loadfile(file_url[, append]) Load the given file/URL, stopping playback of the current file/URL. If is nonzero playback continues and the file/URL is appended to the current playlist instead. .. method:: Loadlist(file[, append]) Load the given playlist file, stopping playback of the current file. If is nonzero playback continues and the playlist file is appended to the current playlist instead. .. method:: Loop(value[, abs]) Adjust/set how many times the movie should be looped. -1 means no loop, and 0 forever. .. method:: 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. .. method:: Mute([value]) Toggle sound output muting or set it to [value] when [value] >= 0 (1 == on, 0 == off). .. method:: Osd([level]) Toggle OSD mode or set it to [level] when [level] >= 0. .. method:: 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). .. method:: OsdShowText(string[, duration[, level]]) Show on the OSD. .. method:: Panscan(value, abs) Increase or decrease the pan-and-scan range by , 1.0 is the maximum. Negative values decrease the pan-and-scan range. If is != 0, then the pan-and scan range is interpreted as an absolute range. .. method:: Pause() Pause/unpause the playback. .. method:: PtStep(value[, force]) Go to the next/previous entry in the playtree. The sign of tells the direction. If no entry is available in the given direction it will do nothing unless [force] is non-zero. .. method:: 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. .. method:: 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 .. method:: RadioSetChannel(channel) Switch to . The 'channels' radio parameter needs to be set. .. method:: RadioSetFreq(freq) Set the radio tuner frequency. freq in Mhz .. method:: RadioStepChannel(value) Step forwards (1) or backwards (-1) in channel list. Works only when the 'channels' radio parameter was set. .. method:: RadioStepFreq(value) Tune frequency by the (positive - up, negative - down). .. method:: Saturation(value[, abs]) Set/adjust video saturation. If [abs] is not given or is zero, modifies parameter by . If [abs] is non-zero, parameter is set to . is in the range [-100, 100]. .. method:: 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. .. method:: Seek(value[, type_]) Seek to some place in the movie. * 0 is a relative seek of +/- seconds (default). * 1 is a seek to % in the movie. * 2 is a seek to an absolute position of seconds. .. method:: SeekChapter(value[, type_]) Seek to the start of a chapter. * 0 is a relative seek of +/- chapters (default). * 1 is a seek to chapter . .. method:: SetMenu(menu_name) Display the menu named . .. method:: SetMousePos(x, y) Tells MPlayer the coordinates of the mouse in the window. This command doesn't move the mouse! .. method:: SetProperty(property, value) Sets a property. All possible properties => :ref:`reference-props` If property isn't a "set-property", raises :exc:`~MplayerCtrl.AnsError` .. method:: SpeedIncr(value) Add to the current playback speed. .. method:: SpeedMult(value) Multiply the current speed by . .. method:: SpeedSet(value) Set the speed to . .. method:: Start([media_file[, mplayer_args]]) Builds a new process, if the old process got killed by :meth:`~MplayerCtrl.Quit`. Returns True if the process is created successfully, otherwise False. .. versionadded:: 0.1.2 .. method:: 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 => :ref:`reference-props` If property isn't a "step-property", raises :exc:`~MplayerCtrl.AnsError` .. method:: Stop() Stop playback. .. method:: SubAlignment([value]) Toggle/set subtitle alignment. * 0 top alignment * 1 center alignment * 2 bottom alignment .. method:: SubDelay(value[, abs]) Adjust the subtitle delay by +/- seconds or set it to seconds when [abs] is nonzero. .. method:: 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. .. method:: 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. .. method:: SubLoad(subtitle_file) Loads subtitles from . .. method:: 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. .. method:: SubPos(value[, abs]) Adjust/set subtitle position. .. method:: 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. .. method:: SubScale(value[, abs]) Adjust the subtitle size by +/- or set it to when [abs] is nonzero. .. method:: 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. .. method:: 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. .. method:: SubStep(value) Step forward in the subtitle list by steps or backwards if is negative. .. method:: SubVisibility([value]) Toggle/set subtitle visibility. .. method:: 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. .. method:: SwitchAngle([value]) Switch to the DVD angle with the ID [value]. Cycle through the available angles if [value] is omitted or negative. .. method:: SwitchAudio([value]) Switch to the audio track with the ID [value]. Cycle through the available tracks if [value] is omitted or negative. .. method:: 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. .. method:: SwitchTitle([value]) Switch to the DVD title with the ID [value]. Cycle through the available titles if [value] is omitted or negative. .. method:: SwitchVsync([value]) Toggle vsync (1 == on, 0 == off). If [value] is not provided, vsync status is inverted. .. method:: 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.) .. method:: TeletextGoLink(value) Follow given link on current teletext page. value must be 1,2,3,4,5 or 6 .. method:: TvLastChannel() Set the current TV channel to the last one. .. method:: TvSetBrightness(value[, abs]) Set TV tuner brightness or adjust it if [abs] is set to 0. value from -100 to 100 .. method:: TvSetChannel(channel) Set the current TV channel. .. method:: TvSetContrast(value[, abs]) Set TV tuner contrast or adjust it if [abs] is set to 0. value from -100 to 100 .. method:: TvSetFreq(freq) Set the TV tuner frequency. freq offset in Mhz .. method:: TvSetHue(value[, abs]) Set TV tuner hue or adjust it if [abs] is set to 0. value from -100 to 100 .. method:: TvSetNorm(norm) Set the TV tuner norm (PAL, SECAM, NTSC, ...). .. method:: TvSetSaturation(value[, abs]) Set TV tuner saturation or adjust it if [abs] is set to 0. value from -100 to 100 .. method:: TvStartScan() Start automatic TV channel scanning. .. method:: TvStepChanlist() Change channel list. .. method:: TvStepChannel(channel) Select next/previous TV channel. .. method:: TvStepFreq(freq) Set the TV tuner frequency relative to current value. freq offset in Mhz .. method:: TvStepNorm() Change TV norm. .. method:: UseMaster() Switch volume control between master and PCM. .. method:: VoBorder([value]) Toggle/set borderless display. .. method:: VobsubLang(*args) This is a stub linked to SubSelect for backwards compatibility. .. method:: VoFullscreen([value]) Toggle/set fullscreen mode .. method:: VoOntop([value]) Toggle/set stay-on-top. .. method:: VoRootwin([value]) Toggle/set playback on the root window. .. _reference-props: Properties ========== .. attribute:: MplayerCtrl.mplayer_path A string containing the current path to the Mplayer(.exe). .. attribute:: MplayerCtrl.keep_pause If True it tells the mplayer to keep pause if another command is executed. .. attribute:: MplayerCtrl.playing True if the a file is playing, otherwise False. .. attribute:: MplayerCtrl.process_alive returns True if a mplayer process if not False. If process_alive returns False you have to build another process with :meth:`~MplayerCtrl.Start` before you can use the methods of the mpc again. .. _reference-mprops: .. versionadded: 0.2.0 More properties, this properties are accessible through MplayerCtrl.the_prop *and* MplayerCtrl.GetProperty('the_prop') (or :meth:`~MplayerCtrl.SetProperty` or :meth:`~MplayerCtrl.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 ================== ========= ======= ======= === === ==== ========================================= .. _reference-events: Events ------ .. data:: EVT_MEDIA_STARTED The event is posted to the `Parent` of the MplayerCtrl, when a new playback begins .. data:: EVT_MEDIA_FINISHED The event is posted to the `Parent` of the MplayerCtrl, when the mediafile is finished .. data:: EVT_PROCESS_STARTED The event is posted to the `Parent` of the MplayerCtrl, when the mplayer process is built and started .. data:: 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 .. data:: 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 :attr:`MplayerCtrl.Stderr.data` .. data:: 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 :attr:`MplayerCtrl.Stdout.data` .. versionadded:: 0.2.3 Event Interface --------------- .. attribute:: MplayerCtrl.Stderr.data A string containing the data read from the stderr of the mplayer process .. attribute:: MplayerCtrl.Stdout.data A string containing the data read from the stdout of the mplayer process .. versionadded:: 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 :doc:`tutorial`.