Public Member Functions

Wt::WHTML5Video Class Reference

A widget that renders video using the HTML5 video element. More...

#include <Wt/WHTML5Video>

Inheritance diagram for Wt::WHTML5Video:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 WHTML5Video (WContainerWidget *parent=0)
 Creates a HTML5 video widget.
void setPoster (const std::string &url)
 Set the poster image.
std::string jsVideoRef () const
 Returns the JavaScript reference to the video object, or null.
virtual void resize (const WLength &width, const WLength &height)
 Resizes the widget.

Detailed Description

A widget that renders video using the HTML5 video element.

This class renders HTML5 video. In a typical usage scenario, you instantiate the class, set options, add one or multiple video sources. Since not every browser supports HTML5 video, the class provides a mechanism to display alternative content in browsers that cannot play the video.

Usage example:

 WHTML5Video *v = new WHTML5Video(parent);
 v->setOptions(WHTML5Video::Autoplay | WHTML5Video::Controls);
 // Addsources may be called multiple times for different formats:
 // Firefox only plays ogg
 v->addSource("wt.ogv");
 // many others play mp4
 v->addSource("wt.mp4", "video/mp4");
 // Image to be displayed before playback starts
 v->setPoster("wt.jpg");
 // You may display a simple text to explain that you need html5 support...
 // v->setAlternativeContent(new WText("You have no HTML5 Video!"));
 // ... or provide an alternative player, e.g. Flash-based
 WFlashObject *f = new WFlashObject("player.swf", root());
 f->setFlashVariable("startimage", "wt.jpg");
 f->setFlashVariable("flv", "wt.mp4");
 f->resize(640, 384);
 v->setAlternativeContent(f);

There are two reasons why the a browser may use the alternative content: either because the browser does not support the HTML5 video tag (alternative content is displayed even when JavaScript is not available), or because none of the specified sources contain a video format that is understood by the browser (requires JavaScript to display the alternative content).

addSource() and setAlternativeContent() must not be called after the WHTML5Video was rendered. This can easily be avoided by calling these functions right after construction.

This is a technology-specific class. To let Wt choose a technology (and fallback technologies) to display your videos, use the WVideo class.


Constructor & Destructor Documentation

WHTML5Video::WHTML5Video ( WContainerWidget parent = 0 )

Creates a HTML5 video widget.

The constructor sets the 'controls' option, which causes the browser to display a bar with play/pauze/volume/... controls.

A freshly constructed HTML5Video widget has no poster image, no media sources, has preload mode set to PreloadAuto, and only the Controls flag is set.


Member Function Documentation

std::string WHTML5Video::jsVideoRef (  ) const

Returns the JavaScript reference to the video object, or null.

It is possible, for compatibility reasons, that jsRef() is not the HTML5 video element. jsVideoRef() is guaranteed to be an expression that evaluates to the video object. This expression may yield null, if the video object is not rendered at all (e.g. on older versions of Internet Explorer).

void WHTML5Video::resize ( const WLength width,
const WLength height 
) [virtual]

Resizes the widget.

Specify a new size for this widget, by specifying width and height. By default a widget has automatic width and height, see WLength::isAuto().

This applies to CSS-based layout, and only block widgets can be given a size reliably.

When inserted in a layout manager, the widget may be informed about its current size using setLayoutSizeAware(). If you have defined a "wtResize()" JavaScript method for the widget, then this method will also be called. operation.

See also:
width(), height()

Reimplemented from Wt::WWebWidget.

void WHTML5Video::setPoster ( const std::string &  url )

Set the poster image.

On browsers that support it, the poster image is displayed before the video is playing. Some browsers display the first frame of the video stream once the video stream is loaded; it is therefore a good idea to include the poster image as first frame in the video feed too.

 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator

Generated on Fri Feb 4 2011 for the C++ Web Toolkit (Wt) by doxygen 1.7.2