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