Wt: Wt::WVideo Class Reference

Wt 3.3.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Hierarchy
- Class Members

Public Member Functions
Wt::WVideo Class Reference

A video-playing widget. More...

`#include <Wt/WVideo>`

Inheritance diagram for Wt::WVideo:
[legend]

List of all members.

## Public Member Functions
| WVideo (WContainerWidget *parent=0)
| Creates a 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 video-playing widget.

This is a low-level widget, mapping directly onto a `<video>` element available in HTML5 compliant browsers.

In almost every situation you should use the WMediaPlayer widget instead, which has fallback and flexible user-interface options.

Usage of the video element consists of adding one or more video sources and setting some options. 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:

     WVideo *v = new WVideo(parent);
     v->setOptions(WVideo::Autoplay | WVideo::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).

The addSource() and setAlternativeContent() may not be called after the widget is rendered.

See also:
  WMediaPlayer

Note:
  Before Wt 3.1.11, this was called WHTML5Video, which still exists as a (deprecated) typedef.

## Constructor & Destructor Documentation

WVideo::WVideo | ( | WContainerWidget * | parent = `0` | ) |

Creates a video widget.

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

A freshly constructed video 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 WVideo::jsVideoRef | ( |  | ) | const

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

It is possible, for compatibility reasons, that jsRef() is not the 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 WVideo::resize | ( | const WLength & | width,
|  | const WLength & | height
| ) |  | `[virtual]`

Resizes the widget.

Specifies a fixed size for this widget, setting CSS `width` and `height` properties. By default a widget has automatic width and height, which sets a size for the widget following CSS rules.

When the widget is not managed by a layout manager, the automatic (natural) size of a widget depends on whether they widget is a block or inline widget:

- a block widget takes by default the width of the parent, and the height that it needs based on its contents
- an inline widget takes the width and height that it needs based on its contents (possibly wrapping over multiple lines). The width and height of an inline widget cannot be changed (by the letter of CSS, although most browsers will react to it in varying ways).

When inserted in a layout manager, the size set will be used as a widget's preferred size, but the widget may be given a different size by the layout manager based on available space and stretch factors. The actual size given by a layout manager may be retrieved by making the widget "layout size aware", using setLayoutSizeAware(). If you have defined a `"wtResize()"` JavaScript method for the widget, then this method will also be called.

The default width and height of a widget is WLength::Auto.

See also:
  width(), height()

Reimplemented from Wt::WWebWidget.

void WVideo::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