-
Notifications
You must be signed in to change notification settings - Fork 1
/
live-photo.html
352 lines (293 loc) · 8.37 KB
/
live-photo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<link rel="import" href="../polymer/polymer-element.html">
<script src="https://cdn.apple-livephotoskit.com/lpk/1/livephotoskit.js"></script>
<!--<link rel="import" href="../polymer/lib/elements/dom-if.html">-->
<!--<link rel="import" href="../polymer/lib/elements/dom-repeat.html">-->
<!--
`live-photo`
Live Photo from Apple implemented in Polymer
@demo demo/index.html
-->
<dom-module id="live-photo">
<template>
<style>
:host(:not([hidden])) {
display: block;
width: 216px;
height: 162px;
}
div {
display: block;
width: 100%;
height: 100%;
}
</style>
</template>
<script>
/** @polymerElement */
class LivePhoto extends Polymer.Element {
static get is() { return 'live-photo'; }
static get properties() {
return {
player: Object,
/**
* A boolean value that indicates whether the Player downloads
* bytes before the user begins playback.
*/
preload: Boolean,
/**
* The value of this property indicates whether
* the Apple-provided playback controls are not enabled for the user.
*/
noControls: Boolean,
/**
* Play a short section of the motion content.
*/
hint: Boolean,
/**
* The current time, in seconds, of the play head.
*/
currentTime: Number,
/**
* The duration, in seconds, of the entire Live Photo.
*/
duration: Number,
/**
* The height, in pixels, of the photo component.
*/
photoHeight: Number,
/**
* The width, in pixels, of the photo component.
*/
photoWidth: Number,
/**
* The MIME type of a photo asset.
*/
photoMimeType: String,
/** The nominated time, in seconds, of where the photo component
* should be within the Live Photo video component.
*/
photoTime: Number,
/**
* The source of the photo component of the Live Photo.
*/
photoSrc: String,
/**
* A Boolean value that indicates whether
* the Player is able to begin playback.
*/
canPlay: Boolean,
/**
* An array of errors that occurred when attempting to load resources.
*/
errors: Array,
/**
* An array of timestamps for each second from the beginning of
* a Live Photo for which the frames reside in the Live Photo.
*/
frameTimes: Array,
/**
* A Boolean value that indicates whether or not
* the Player is playing.
*/
isPlaying: Boolean,
/**
* A numeric value that indicates the progress of
* loading the Live Photo.
*/
loadProgress: Number,
/**
* A string or array buffer that contains metadata about
* the properties of a Live Photo.
*/
metadataVideoSrc: String,
/**
* The current timestamp, as a floating-point number of seconds
* from the beginning of the animation,
* that is truly displayed on the screen.
*/
renderedTime: Number,
/**
* The playable HTMLVideoElement that the Player consumes to obtain video frame data to render to the screen while animating a Live Photo.
*/
video: Object,
/**
* The height, in pixels, of the underlying video asset provided to the this.player.
*/
videoHeight: Number,
/**
* The MIME type of the video asset.
*/
videoMimeType: String,
/**
* The angle that the video is displayed.
*/
videoRotation: Number,
/**
* A reference to the source of the video component of this Live Photo.
*/
videoSrc: String,
/**
* The width, in pixels, of an underlying video asset provided to the this.player.
*/
videoWidth: Number,
/**
* A boolean that indicates whether the Player has been instructed to play.
*/
wantsToPlay: Boolean,
};
}
get hint() {
return this.player.playbackStyle === LivePhotosKit.PlaybackStyle.HINT;
}
set hint(hint) {
this.player.playbackStyle = hint ?
LivePhotosKit.PlaybackStyle.HINT :
LivePhotosKit.PlaybackStyle.FULL;
}
get preload() {
return this.player.proactivelyLoadsVideo;
}
set preload(preload) {
this.player.proactivelyLoadsVideo = preload;
}
get noControls() {
return !this.player.showsNativeControls;
}
set noControls(noControls) {
this.player.showsNativeControls = !noControls;
}
get currentTime() {
return this.player.currentTime;
}
set currentTime(currentTime) {
this.player.currentTime = currentTime;
}
get duration() {
return this.player.duration;
}
get photoHeight() {
return this.player.photoHeight;
}
get photoWidth() {
return this.player.photoWidth;
}
get photoTime() {
return this.player.photoTime;
}
get canPlay() {
return this.player.canPlay;
}
get errors() {
return this.player.errors
}
get frameTimes() {
return this.player.frameTimes
}
get isPlaying() {
return this.player.isPlaying
}
get loadProgress() {
return this.player.loadProgress
}
get metadataVideoSrc() {
return this.player.metadataVideoSrc
}
get photo() {
return this.player.photo
}
get photoMimeType() {
return this.player.photoMimeType
}
get photoSrc() {
return this.player.photoSrc;
}
set photoSrc(photoSrc) {
this.player.photoSrc = photoSrc;
}
get playbackStyle() {
return this.player.playbackStyle
}
get proactivelyLoadsVideo() {
return this.player.proactivelyLoadsVideo
}
get renderedTime() {
return this.player.renderedTime
}
get showsNativeControls() {
return this.player.showsNativeControls
}
get video() {
return this.player.video;
}
get videoHeight() {
return this.player.videoHeight;
}
get videoMimeType() {
return this.player.videoMimeType;
}
get videoRotation() {
return this.player.videoRotation;
}
get videoSrc() {
return this.player.videoSrc;
}
set videoSrc(videoSrc) {
this.player.videoSrc = videoSrc;
}
get videoWidth() {
return this.player.videoWidth;
}
get wantsToPlay() {
return this.player.wantsToPlay;
}
constructor() {
super();
this.player = LivePhotosKit.Player();
}
connectedCallback () {
super.connectedCallback();
this.shadowRoot.appendChild(this.player);
}
/**
* Clips the duration of the renderer early so that the animation begins
* to fade back to the photo component earlier than it would ordinarily.
*/
beginFinishingPlaybackEarly() {
this.player.beginFinishingPlaybackEarly();
}
/**
* Pauses playback at the current time.
*/
pause() {
this.player.pause();
}
/**
* Starts playback if the player is ready,
* or resumes playback if the player is paused.
*/
play() {
this.player.play();
}
/**
* Stops playback and rewinds to the current time of zero.
*/
stop() {
this.player.stop();
}
/**
* Starts playing the video component of Live Photo
* if the video is paused, or pauses the video if it is playing.
*/
toggle() {
this.player.toggle();
}
/**
* Updates the size of the this.player.
*/
updateSize() {
this.player.updateSize();
}
}
window.customElements.define(LivePhoto.is, LivePhoto);
</script>
</dom-module>