|
@@ -0,0 +1,178 @@
|
|
1
|
+# Video Player
|
|
2
|
+
|
|
3
|
+An A-Frame solution for playing videos in AR. `<ar-video-player>` is tailored for AR with encantar.js. Unlike A-Frame's standard `<a-video>`, `<ar-video-player>` handles corner cases for AR and includes easy-to-use controls, so you can focus on creating your projects rather than dealing with the various technicalities and edge cases of video playback on the browser.
|
|
4
|
+
|
|
5
|
+<div style="text-align: center">
|
|
6
|
+<iframe width="560" height="315" src="https://www.youtube.com/embed/sz4Fmf3zyho?si=e4Ry5jcYAvxPfAKe" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
|
|
7
|
+</div>
|
|
8
|
+
|
|
9
|
+!!! tip "It's easy to use!"
|
|
10
|
+
|
|
11
|
+ The Video Player Add-On includes a working demo that you can easily modify. This page documents it in depth and is meant to be used as a reference.
|
|
12
|
+
|
|
13
|
+## Properties
|
|
14
|
+
|
|
15
|
+| Property | Description | Default |
|
|
16
|
+| -------- | ----------- | ------- |
|
|
17
|
+| `src` | Query selector of a `<video>` element. | `""` |
|
|
18
|
+| `width` | Width of the player. | `2` |
|
|
19
|
+| `height` | Height of the player. | `1.125` |
|
|
20
|
+
|
|
21
|
+!!! tip
|
|
22
|
+
|
|
23
|
+ Place your `<video>` tag(s) inside `<a-assets>`:
|
|
24
|
+
|
|
25
|
+ ```html
|
|
26
|
+ <ar-root>
|
|
27
|
+ <ar-video-player src="#my-video">
|
|
28
|
+ <!-- ... video controls ... -->
|
|
29
|
+ </ar-video-player>
|
|
30
|
+ </ar-root>
|
|
31
|
+
|
|
32
|
+ <!-- ... -->
|
|
33
|
+
|
|
34
|
+ <a-assets>
|
|
35
|
+ <video id="my-video" playsinline>
|
|
36
|
+ <source src="assets/my-video.mp4" type="video/mp4" />
|
|
37
|
+ <source src="assets/my-video.webm" type="video/webm" />
|
|
38
|
+ </video>
|
|
39
|
+ </a-assets>
|
|
40
|
+ ```
|
|
41
|
+
|
|
42
|
+!!! tip "Aspect ratio"
|
|
43
|
+
|
|
44
|
+ Make sure that the `width` and the `height` of your `<ar-video-player>` match the aspect ratio of your video. The default size is appropriate for the commonly used 16:9 widescreen ratio.
|
|
45
|
+
|
|
46
|
+## Video controls
|
|
47
|
+
|
|
48
|
+### Overview
|
|
49
|
+
|
|
50
|
+You may attach the `ar-video-control` component to any [AR Button](./ar-button.md) (typically) or to any [AR Clickable](./ar-clickable.md) (in general) in order to let the user control the video with a click. What exactly happens with a click depends on the selected [action](#actions).
|
|
51
|
+
|
|
52
|
+Add the `ar-video-control` component to a descendant of `<ar-video-player>` as in this example:
|
|
53
|
+
|
|
54
|
+```html
|
|
55
|
+<ar-video-player src="#my-video">
|
|
56
|
+
|
|
57
|
+ <!-- The play button is a descendant of ar-video-player -->
|
|
58
|
+ <ar-button id="play-button" position="0 0.9 0"
|
|
59
|
+ ar-video-control="action: play"
|
|
60
|
+ ></ar-button>
|
|
61
|
+
|
|
62
|
+</ar-video-player>
|
|
63
|
+```
|
|
64
|
+
|
|
65
|
+### Properties
|
|
66
|
+
|
|
67
|
+| Property | Description | Default |
|
|
68
|
+| -------- | ----------- | ------- |
|
|
69
|
+| `action` | The [action](#actions) to be performed. | `""` |
|
|
70
|
+
|
|
71
|
+### Actions
|
|
72
|
+
|
|
73
|
+| Action | Description |
|
|
74
|
+| ------ | ----------- |
|
|
75
|
+| `"play"` | Play the video. |
|
|
76
|
+| `"pause"` | Pause the video. |
|
|
77
|
+| `"toggle"` | Toggle the video playback. |
|
|
78
|
+| `"stop"` | Pause and rewind the video. |
|
|
79
|
+| `"rewind"` | Rewind the video without pausing it. |
|
|
80
|
+| `"mute"` | Mute the video. |
|
|
81
|
+| `"unmute"` | Unmute the video. |
|
|
82
|
+| `"toggleAudio"` | Toggle the audio. |
|
|
83
|
+
|
|
84
|
+## Declarative handlers
|
|
85
|
+
|
|
86
|
+### Overview
|
|
87
|
+
|
|
88
|
+Declarative event handlers are components used to register event listeners that set properties. They provide an easy way to create interactivity within your HTML page. There is a component for each [event](#event):
|
|
89
|
+
|
|
90
|
+| Handler | Description |
|
|
91
|
+| ------- | ----------- |
|
|
92
|
+| `ar-onvideoplay` | Triggered when the video is played. |
|
|
93
|
+| `ar-onvideopause` | Triggered when the video is paused. |
|
|
94
|
+| `ar-onvideoended` | Triggered when the video reaches its end. |
|
|
95
|
+
|
|
96
|
+These handlers can be added to `<ar-video-player>` itself or to any of its descendants:
|
|
97
|
+
|
|
98
|
+```html
|
|
99
|
+<!-- Make the video player translucent when not playing a video -->
|
|
100
|
+<ar-video-player src="#my-video" transparent="true" opacity="0.5"
|
|
101
|
+ ar-onvideoplay="opacity: 1"
|
|
102
|
+ ar-onvideopause="opacity: 0.5"
|
|
103
|
+ ar-onvideoended="opacity: 0.5"
|
|
104
|
+>
|
|
105
|
+ <!-- ... video controls ... -->
|
|
106
|
+</ar-video-player>
|
|
107
|
+```
|
|
108
|
+
|
|
109
|
+[Video controls](#video-controls) may be combined with declarative handlers for easy customization:
|
|
110
|
+
|
|
111
|
+```html
|
|
112
|
+<!-- Make the pause button appear when the video starts playing.
|
|
113
|
+ Make it disappear when the video ends or is paused. -->
|
|
114
|
+<ar-video-player src="#my-video">
|
|
115
|
+
|
|
116
|
+ <!-- The pause button is a descendant of ar-video-player -->
|
|
117
|
+ <ar-button id="pause-button" position="0 -0.9 0"
|
|
118
|
+ visible="false" enabled="false"
|
|
119
|
+ ar-onvideoplay="visible: true; ar-button.enabled: true"
|
|
120
|
+ ar-onvideopause="visible: false; ar-button.enabled: false"
|
|
121
|
+ ar-onvideoended="visible: false; ar-button.enabled: false"
|
|
122
|
+ ar-video-control="action: pause"
|
|
123
|
+ ></ar-button>
|
|
124
|
+
|
|
125
|
+</ar-video-player>
|
|
126
|
+```
|
|
127
|
+
|
|
128
|
+### Special properties
|
|
129
|
+
|
|
130
|
+The following special properties are used to further customize the declarative handlers:
|
|
131
|
+
|
|
132
|
+| Property | Description |
|
|
133
|
+| -------- | ----------- |
|
|
134
|
+| `_target` | Query selector to be used when setting properties on a different entity. |
|
|
135
|
+| `_delay` | Delay, in milliseconds, before setting the properties. |
|
|
136
|
+
|
|
137
|
+!!! question "What about event-set?"
|
|
138
|
+
|
|
139
|
+ Declarative handlers are similar to A-Frame's event-set in their usage, but there are differences behind the scenes. Whenever working with the Video Player, usage of the declarative handlers presented in this page is preferred.
|
|
140
|
+
|
|
141
|
+### Multiple handlers
|
|
142
|
+
|
|
143
|
+Use double-underscores (`__`) to attach multiple handlers of the same type to a single entity:
|
|
144
|
+
|
|
145
|
+```html
|
|
146
|
+<!-- Make two animated characters show up as soon as the video reaches its end -->
|
|
147
|
+<ar-video-player src="#my-video"
|
|
148
|
+ ar-onvideoended__1="_target: #animated-character-1; visible: true"
|
|
149
|
+ ar-onvideoended__2="_target: #animated-character-2; visible: true"
|
|
150
|
+>
|
|
151
|
+ <!-- ... video controls ... -->
|
|
152
|
+</ar-video-player>
|
|
153
|
+
|
|
154
|
+<!-- ... -->
|
|
155
|
+
|
|
156
|
+<a-entity id="animated-character-1" visible="false" ... ></a-entity>
|
|
157
|
+<a-entity id="animated-character-2" visible="false" ... ></a-entity>
|
|
158
|
+```
|
|
159
|
+
|
|
160
|
+## Events
|
|
161
|
+
|
|
162
|
+The `<ar-video-player>` emits the following events based on the state of the underlying `<video>` element:
|
|
163
|
+
|
|
164
|
+| Event name | Description |
|
|
165
|
+| ---------- | ----------- |
|
|
166
|
+| `"videoplay"` | Triggered whenever the video is played. |
|
|
167
|
+| `"videopause"` | Triggered whenever the video is paused. |
|
|
168
|
+| `"videoended"` | Triggered whenever the video reaches its end. |
|
|
169
|
+
|
|
170
|
+## Methods
|
|
171
|
+
|
|
172
|
+| Method | Description |
|
|
173
|
+| ------ | ----------- |
|
|
174
|
+| `invoke(action)` | Perform an [action](#video-controls). |
|
|
175
|
+
|
|
176
|
+## Autoplay
|
|
177
|
+
|
|
178
|
+Usage of the `autoplay` attribute on the `<video>` tag is discouraged. Video playback may be blocked due to browser policies and the Video Player will not show up in AR as soon as the page is loaded. It's typically better to wait for user input in order to initiate the playback, e.g., have the user click on a play button. If the page receives no user interaction, then you may still play your video as long as it's muted. See also: [artargetfound](../api/plugin-aframe.md#artargetfound) event.
|