Create a video player UI object * @param {Vector2} pos * @param {Vector2} size * @param {string} src - Video file path or URL * @param {boolean} [autoplay=false] - Start playing immediately? * @param {boolean} [loop=false] - Loop the video? * @param {number} [volu
(pos, size, src, autoplay=false, loop=false, volume=1)
| 1425 | * @param {number} [volume=1] - Volume percent scaled by global volume (0-1) |
| 1426 | */ |
| 1427 | constructor(pos, size, src, autoplay=false, loop=false, volume=1) |
| 1428 | { |
| 1429 | super(pos, size || vec2()); |
| 1430 | |
| 1431 | ASSERT(isStringLike(src), 'video src must be a string'); |
| 1432 | ASSERT(isNumber(volume), 'video volume must be a number'); |
| 1433 | |
| 1434 | this.color = BLACK; // default to black background |
| 1435 | this.cornerRadius = 0; // default to no corner radius |
| 1436 | |
| 1437 | /** @property {number} - The video volume */ |
| 1438 | this.volume = volume; |
| 1439 | |
| 1440 | // create video element |
| 1441 | /** @property {HTMLVideoElement} - The video player */ |
| 1442 | this.video = document.createElement('video'); |
| 1443 | this.video.loop = loop; |
| 1444 | this.video.volume = clamp(volume * soundVolume); |
| 1445 | this.video.muted = !soundEnable; |
| 1446 | this.video.style.display = 'none'; |
| 1447 | this.video.src = src; |
| 1448 | document.body.appendChild(this.video); |
| 1449 | autoplay && this.play(); |
| 1450 | } |
| 1451 | |
| 1452 | /** Play or resume the video |
| 1453 | * @return {Promise} Promise that resolves when playback starts */ |