Dashboard > Development > Home > PyPlayer Documentation
Development Log In   View a printable version of the current page.
PyPlayer Documentation
Added by Peter Krenesky, last edited by Peter Krenesky on Feb 22, 2007  (view change)
Labels: 
(None)

atlas code http://staff.osuosl.org/~peter/myfiles/helix/pyplayer_atlas.tar.gz

updated code http://staff.osuosl.org/~peter/myfiles/helix/pyplayer.tar.gz

gtk and pyplayer

this is a simple example on how to use GTK and pyplayer:

#create window
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.show()

#create drawingarea
draw = gtk.DrawingArea()
draw.set_size_request(1000, 500)
window.add(window)
draw.show()

#create site which is a tuple of info about how to find the drawing area or window
site = (draw.window.get_screen().make_display_name(),draw.window.xid)

#no callbacks for this example
callbacks = ''

#create player
player = hxplay.open(URL, callbacks, site=site)

notes:

  • you could draw directly to a window but a drawarea lets us include other elements such as buttons
  • window and drawarea must be displayed before they will have an XID

GTK main iteration loop with doevent

self.run=1	
self.play=0	
while(self.run):	    
    while gtk.events_pending():
        gtk.main_iteration()
    if (self.play):		
        hxplay.doevent();

notes:

  • when the program is terminated from the X or alt-f4 set self.run=0
  • when stop button is pressed set self.play=0

aspectSafeResize

how to resize a window and maintain the aspect ratio. this assumes that width>height which in most cases is true

def aspectSafeResize(player, width, height):
	oldWidth,oldHeight = player.getsize()	
	ratio =float(oldWidth)/float(oldHeight)
	newWidth = width
	newHeight = (newWidth / ratio)	
	player.setsize(newWidth,int(newHeight))

Files and their purposes

  • HxModule - main python bindings
  • HXPyCore - handles engine setup:  preferences, codec/dll/so locations
  • PyHxPlayerObject - python bindings for player object
  • PyPlayer - wrapper object for IHXPlayer
  • PyClientContext - implements IHXClientAdviseSink (handles callbacks like onbuffer),  IHXSiteSupplier (handles creation of windows for video playback)
      

  

 Basic Program Flow

  1. Module loaded in Python with command "import hxplay"
    1. HxModule is instantiated - this is the main python binding "hxplay"
      1. HxPyCore is instantiated - This loads the engine. 
  2. hxplay.open(url) is called from python which corresponds to HXModule::hx_open
    1. PyHxPlayerObject::PyHxPlayer_New(...) - instantiates a python bound object to be returned to python program
      1. PyPlayer::Create(...) - instantiates a new pyplayer object
        1. HxPyCore::CreatePlayer(m_piPlayer) creates IHXPlayer
          1. IHXClientEngine::CreatePlayer - engine is member variable of core.  
        2. new PyClientContext(...) - new context is created
        3. PyClientContext::Init() - context is initialized
          1. Player sets context as its context
        4. IHXPlayer::OpenURL(url) - url is opened
    2. PyHXPlayerObject is returned to python program
  3. player.start() called from python which corresponds to PyHXPlayerObject::Start() - this starts the player
    1. PyPlayer::Start()
      1. IHXPlayer::Begin()
  1. hxplay.run() is called from python - this keeps the python program running until all players are complete.
    1. HXModule::hx_run()

  

known problems

Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.7 Build:#524 Jul 28, 2006) - Bug/feature request - Contact Administrators