360° video

@mattebox/player-360@0.1.0Needs @mattebox/player >=0.16.0 and mattebox ^0.18.0.

@mattebox/player-360 shows a 360° video from inside. The picture is drawn onto the inside of a sphere around the viewer, and the viewer looks around it. It needs WebGL, which every browser down to Chromium 76 has.

The element

<mattebox-player src="https://example.com/vod/360/master.m3u8" controls="custom">
  <mbx-360></mbx-360>
  <mbx-control-bar>
    <mbx-play-button></mbx-play-button>
    <mbx-seek-bar></mbx-seek-bar>
  </mbx-control-bar>
</mattebox-player>

<script type="module">
  import '@mattebox/player';
  import '@mattebox/player-360';
</script>

Place <mbx-360> first, right after the video. It covers the whole player, and the controls placed after it stay on top.

Over Safari’s own HLS the video shows flat. So while <mbx-360> is inside a player, the player’s default for native-hls is off: Safari plays HLS through the engine. Set native-hls="on" to give Safari its own HLS back, for a player whose sources are all flat.

The viewer What happens
Drags the picture The view turns. The picture follows the pointer
Taps without a drag The video plays or pauses, as a click on a flat video does
Turns the wheel The view zooms in or out, from 30° to 100° tall
Leans the right stick A game controller turns the view, faster the further it leans

While the view shows, the video keeps a 16:9 box. A 360° picture is 2:1, and the view is a window into it.

The poster shows as on a flat video: until the programme plays or seeks. Before that the sphere stays hidden. On a new source, the last programme’s picture goes as soon as the video empties.

How the player knows

The player carries projection while its source is 360°. It comes from the first of these that says so.

  1. The projection attribute on <mbx-360>. It wins over everything. none keeps a 360° source flat.
  2. The source’s projection, which your page or your connector sets. Use it when your content API knows: the stream often does not say.
  3. The manifest: the engine reads HLS REQ-VIDEO-LAYOUT (engine guide, chapter 03).
player.sources = [{ url: 'https://example.com/360/master.m3u8', projection: 'equirectangular' }];
projection The picture
equirectangular The whole sphere, 2:1
half-equirectangular The half in front of the viewer, 1:1. The back is black

A connector

SRG SSR’s content API marks a 360° resource with presentation: 'VIDEO_360', and its streams carry no projection of their own. The demo’s connector turns the one into the other:

const sphere = resource.presentation === 'VIDEO_360' ? { projection: 'equirectangular' } : {};
return { url, type: resource.mimeType, ...sphere };

When the view does not show

The flat video plays instead, and unavailable on <mbx-360> says why.

unavailable Why
drm The source is encrypted. A browser does not let a page draw a DRM picture: no player can
source Another site’s video, served without CORS. Set crossorigin on the player and allow CORS
webgl The browser gives no WebGL

Attributes and properties

Name Kind What it does
projection attribute Forces a projection, or none. See How the player knows
fov attribute The field of view a source starts with, in degrees, 75 by default
active attribute Set by the element while the view shows
unavailable attribute Set by the element. See When the view does not show
yaw property Degrees the view is turned right of the picture’s centre
pitch property Degrees the view looks up
fov property The vertical field of view in degrees, from 30 to 100

A new source starts straight ahead, at fov.

Subtitles

The browser draws subtitles inside the video, under the view. The element writes the active cues of the showing track over the view instead, without their styling.

Parts

Part What it is
view The canvas the sphere is drawn on
subtitles The subtitles written over the view

Not yet

  • VR headsets, through WebXR.
  • Turning the view with the phone’s motion.
  • Turning the view with the keyboard. The arrows move focus between the controls, so the view needs keys of its own. Set yaw and pitch from your own keys meanwhile.
  • The projection boxes of an MP4 init segment, and DASH.

Read this page's source on GitHub