Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add html5 media example

  • Loading branch information...
commit a9bffcab3bd652c2f88b0009904104894f14fdaf 1 parent d89ac67
Luke Leighton authored
24 examples/media/Media.py
View
@@ -0,0 +1,24 @@
+import pyjd # this is dummy in pyjs.
+from pyjamas.ui.RootPanel import RootPanel
+from pyjamas.media.Video import Video
+from pyjamas.media.Audio import Audio
+from pyjamas import Window
+
+if __name__ == '__main__':
+ pyjd.setup("public/Media.html?fred=foo#me")
+ v = Video(Width="640px", Height="480px",
+ StyleName="vteststyle",
+ Autoplay=True,
+ Controls=True,
+ src="http://127.0.0.1/home/kiss.the.girl.mp4")
+
+ a = Audio(Width="640px", Height="50px",
+ StyleName="ateststyle",
+ Autoplay=True,
+ Controls=True,
+ src="http://127.0.0.1/home/Lry_Crane_Copy.mp3")
+
+ RootPanel().add(a)
+ #RootPanel().add(v)
+
+ pyjd.run()
53 examples/media/__main__.py
View
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+
+TARGETS = [
+ 'Media.py',
+]
+
+
+PACKAGE = {
+ 'title': 'helloworld',
+ 'desc': 'Port of GWT hello world example',
+}
+
+
+def setup(targets):
+ '''Setup example for translation, MUST call util.setup(targets).'''
+ util.setup(targets)
+
+
+def translate():
+ '''Translate example, MUST call util.translate().'''
+ util.translate()
+
+
+def install(package):
+ '''Install and cleanup example module. MUST call util.install(package)'''
+ util.install(package)
+
+
+##---------------------------------------##
+# --------- (-: DO NOT EDIT :-) --------- #
+##---------------------------------------##
+
+
+import sys
+import os
+
+
+examples = head = os.path.abspath(os.path.dirname(__file__))
+while os.path.split(examples)[1].lower() != 'examples':
+ examples = os.path.split(examples)[0]
+ if not examples:
+ raise ValueError("Cannot determine examples directory")
+sys.path.insert(0, os.path.join(examples))
+from _examples import util
+sys.path.pop(0)
+
+util.init(head)
+
+setup(TARGETS)
+translate()
+install(PACKAGE)
7 examples/media/build.sh
View
@@ -0,0 +1,7 @@
+#!/bin/sh
+# you will need to read the top level README, and run boostrap.py
+# and buildout in order to make pyjsbuild
+
+options="$*"
+#if [ -z $options ] ; then options="-O";fi
+../../bin/pyjsbuild --print-statements $options Media
7 examples/media/public/Media.css
View
@@ -0,0 +1,7 @@
+.teststyle {
+ font-size: 200%;
+ margin: 20px;
+ padding: 20px;
+ background-color: #00ff00;
+}
+
12 examples/media/public/Media.html
View
@@ -0,0 +1,12 @@
+<html>
+<!-- auto-generated html - You should consider editing and adapting this
+ to suit your requirements. No doctype used here to force quirks mode; see
+ wiki for details: http://pyjs.org/wiki/csshellandhowtodealwithit/
+-->
+<head>
+ <link rel="stylesheet" href="Media.css">
+ <title>Media (Pyjamas Auto-Generated HTML file)</title>
+</head>
+<body style="background-color:white">
+</body>
+</html>
3  library/pyjamas/media/Audio.py
View
@@ -22,9 +22,10 @@
"""
class Audio(Media):
- def __init__(self, src=None):
+ def __init__(self, src=None, **kwargs):
self.setElement(DOM.createElement("audio"))
if src:
self.setSrc(src)
+ Media.__init__(self, **kwargs)
45 library/pyjamas/media/Media.py
View
@@ -15,9 +15,8 @@
"""
-from pyjamas import Event
+from pyjamas.ui import Event
from pyjamas import DOM
-from pyjamas import EventListener
from pyjamas.ui.Widget import Widget
class Media(Widget):
@@ -33,6 +32,12 @@ class Media(Widget):
HasVolumeChangeHandlers, HasWaitingHandlers, HasAllMouseHandlers,
HasClickHandlers"""
+ def __init__(self, **kwargs):
+ self.mediaEventsToSink = 0
+ self.mediaEventsInitialized = False
+
+ Widget.__init__(self, **kwargs)
+
def setSrc(self, src):
DOM.setAttribute(self.getElement(), 'src', src)
@@ -140,10 +145,10 @@ def setLoop(self, loop):
* @param controls Whether the browser should show playback controls
"""
def setControls(self, controls):
- DOM.setBooleanAttr(self.getElement(), "controls", controls)
+ DOM.setBooleanAttribute(self.getElement(), "controls", controls)
def hasControls(self):
- DOM.getBooleanAttr(self.getElement(), "controls")
+ DOM.getBooleanAttribute(self.getElement(), "controls")
def isMuted(self):
return self.getElement().muted
@@ -194,14 +199,12 @@ def addCanPlayHandler(self, handler):
* @param handler the {@link CanPlayThroughHandler} to be called
"""
- HandlerRegistration addCanPlayThroughHandler(
- CanPlayThroughHandler handler) {
+ def addCanPlayThroughHandler(self, handler):
return self.addMediaEventHandler(handler, CanPlayThroughEvent.getType())
- HandlerRegistration addDurationChangeHandler(
- DurationChangeHandler handler) {
+ def addDurationChangeHandle(self, handler):
return self.addMediaEventHandler(handler, DurationChangeEvent.getType())
@@ -270,8 +273,7 @@ def addLoadedDataHandler(self, handler):
* @param handler the {@link LoadedMetadataHandler} to be called
"""
- HandlerRegistration addLoadedMetadataHandler(
- LoadedMetadataHandler handler) {
+ def addLoadedMetadataHandler(self, handler):
return self.addMediaEventHandler(handler, LoadedMetadataEvent.getType())
@@ -402,11 +404,9 @@ def addWaitingHandler(self, handler):
return self.addMediaEventHandler(handler, WaitingEvent.getType())
- int mediaEventsToSink = 0
-
def addMediaEventHandler(self, handler, etype):
- assert handler is not None : "handler must not be None"
- assert etype is not None : "type must not be None"
+ assert handler is not None, "handler must not be None"
+ assert etype is not None, "type must not be None"
self.maybeInitMediaEvents()
self.sinkMediaEvents(mediaEventGetTypeInt(etype.getName()))
return addHandler(handler, etype)
@@ -446,10 +446,10 @@ def mediaEventGetTypeInt(self, eventType):
def sinkMediaEvents(self, eventBitsToAdd):
- if isOrWasAttached():
- nativeSinkMediaEvents(self.getElement(), eventBitsToAdd)
- else:
- mediaEventsToSink |= eventBitsToAdd
+ if self.isOrWasAttached():
+ self.nativeSinkMediaEvents(self.getElement(), eventBitsToAdd)
+ else:
+ self.mediaEventsToSink |= eventBitsToAdd
@@ -459,13 +459,12 @@ def sinkMediaEvents(self, eventBitsToAdd):
* element.
"""
def doAttachChildren(self):
- int bitsToAdd = mediaEventsToSink
- mediaEventsToSink = -1
+ bitsToAdd = self.mediaEventsToSink
+ self.mediaEventsToSink = -1
if bitsToAdd > 0:
- nativeSinkMediaEvents(self.getElement(), bitsToAdd)
+ self.nativeSinkMediaEvents(self.getElement(), bitsToAdd)
-
def nativeSinkMediaEvents(self, elem, bits):
JS("""
var chMask = (elem.__mediaEventBits || 0) ^ bits;
@@ -576,8 +575,6 @@ def addClickHandler(self, handler):
return addDomHandler(handler, ClickEvent.getType())
- boolean mediaEventsInitialized = False
-
def maybeInitMediaEvents(self):
if not mediaEventsInitialized:
initMediaEvents()
Please sign in to comment.
Something went wrong with that request. Please try again.