blob: 4180767e4763fcc1181bafccfabb30fdab1d60a4 [file] [log] [blame]
Adam Pardyl367cc8c2019-07-16 12:20:13 +02001<!-- Copyright (C) 2019 The Android Open Source Project
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14-->
15<template>
Pablo Gamito95d84212020-06-02 20:12:03 +010016 <video
17 class="md-elevation-2 screen"
Pablo Gamito95d84212020-06-02 20:12:03 +010018 :src="file.data"
19 :style="style"
Pablo Gamitof25221c2020-08-06 18:26:42 +010020 ref="video"
Pablo Gamito95d84212020-06-02 20:12:03 +010021 />
Adam Pardyl367cc8c2019-07-16 12:20:13 +020022</template>
23<script>
Pablo Gamitod8266be2020-08-03 15:22:19 +010024const EPSILON = 0.00001;
Adam Pardyl367cc8c2019-07-16 12:20:13 +020025
26function uint8ToString(array) {
Pablo Gamitod8266be2020-08-03 15:22:19 +010027 const chunk = 0x8000;
28 const out = [];
29 for (let i = 0; i < array.length; i += chunk) {
Adam Pardyl367cc8c2019-07-16 12:20:13 +020030 out.push(String.fromCharCode.apply(null, array.subarray(i, i + chunk)));
31 }
Pablo Gamitod8266be2020-08-03 15:22:19 +010032 return out.join('');
Adam Pardyl367cc8c2019-07-16 12:20:13 +020033}
34
35export default {
36 name: 'videoview',
Pablo Gamito95d84212020-06-02 20:12:03 +010037 props: ['file', 'height'],
Adam Pardyl367cc8c2019-07-16 12:20:13 +020038 data() {
Pablo Gamito95d84212020-06-02 20:12:03 +010039 return {};
40 },
41 computed: {
42 selectedIndex() {
43 return this.file.selectedIndex;
44 },
45 style() {
Pablo Gamitob46238c2020-05-25 11:42:09 +010046 if (typeof this.height == 'number') {
47 return `height: ${this.height}px`;
48 } else {
49 return `height: ${this.height}`;
50 }
Pablo Gamitod8266be2020-08-03 15:22:19 +010051 },
Adam Pardyl367cc8c2019-07-16 12:20:13 +020052 },
53 methods: {
54 arrowUp() {
Pablo Gamitod8266be2020-08-03 15:22:19 +010055 return true;
Adam Pardyl367cc8c2019-07-16 12:20:13 +020056 },
57 arrowDown() {
58 return true;
59 },
Pablo Gamitod8266be2020-08-03 15:22:19 +010060 selectFrameAtTime(timestamp) {
61 const time = (timestamp - this.file.timeline[0]) / 1000000000 + EPSILON;
Pablo Gamitof25221c2020-08-06 18:26:42 +010062 this.$refs.video.currentTime = time;
Adam Pardyl367cc8c2019-07-16 12:20:13 +020063 },
Pablo Gamitod8266be2020-08-03 15:22:19 +010064 selectFrame(idx) {
65 this.selectFrameAtTime(this.file.timeline[idx]);
66 },
67 jumpToSelectedIndex() {
68 this.selectFrame(this.file.selectedIndex);
69 },
Adam Pardyl367cc8c2019-07-16 12:20:13 +020070 },
71 watch: {
72 selectedIndex() {
73 this.selectFrame(this.file.selectedIndex);
Pablo Gamitod8266be2020-08-03 15:22:19 +010074 },
Adam Pardyl367cc8c2019-07-16 12:20:13 +020075 },
Pablo Gamito94b816e2020-06-10 12:42:56 +010076 mounted() {
77 this.$el.addEventListener('canplay', (e) => {
78 this.$emit('loaded');
79 });
80 },
Pablo Gamitod8266be2020-08-03 15:22:19 +010081};
Adam Pardyl367cc8c2019-07-16 12:20:13 +020082
83</script>
84<style>
Adam Pardyl367cc8c2019-07-16 12:20:13 +020085</style>