Adam Pardyl | 367cc8c | 2019-07-16 12:20:13 +0200 | [diff] [blame] | 1 | <!-- 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 Gamito | 95d8421 | 2020-06-02 20:12:03 +0100 | [diff] [blame] | 16 | <video |
| 17 | class="md-elevation-2 screen" |
Pablo Gamito | 95d8421 | 2020-06-02 20:12:03 +0100 | [diff] [blame] | 18 | :src="file.data" |
| 19 | :style="style" |
Pablo Gamito | f25221c | 2020-08-06 18:26:42 +0100 | [diff] [blame] | 20 | ref="video" |
Pablo Gamito | 95d8421 | 2020-06-02 20:12:03 +0100 | [diff] [blame] | 21 | /> |
Adam Pardyl | 367cc8c | 2019-07-16 12:20:13 +0200 | [diff] [blame] | 22 | </template> |
| 23 | <script> |
Pablo Gamito | d8266be | 2020-08-03 15:22:19 +0100 | [diff] [blame] | 24 | const EPSILON = 0.00001; |
Adam Pardyl | 367cc8c | 2019-07-16 12:20:13 +0200 | [diff] [blame] | 25 | |
| 26 | function uint8ToString(array) { |
Pablo Gamito | d8266be | 2020-08-03 15:22:19 +0100 | [diff] [blame] | 27 | const chunk = 0x8000; |
| 28 | const out = []; |
| 29 | for (let i = 0; i < array.length; i += chunk) { |
Adam Pardyl | 367cc8c | 2019-07-16 12:20:13 +0200 | [diff] [blame] | 30 | out.push(String.fromCharCode.apply(null, array.subarray(i, i + chunk))); |
| 31 | } |
Pablo Gamito | d8266be | 2020-08-03 15:22:19 +0100 | [diff] [blame] | 32 | return out.join(''); |
Adam Pardyl | 367cc8c | 2019-07-16 12:20:13 +0200 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | export default { |
| 36 | name: 'videoview', |
Pablo Gamito | 95d8421 | 2020-06-02 20:12:03 +0100 | [diff] [blame] | 37 | props: ['file', 'height'], |
Adam Pardyl | 367cc8c | 2019-07-16 12:20:13 +0200 | [diff] [blame] | 38 | data() { |
Pablo Gamito | 95d8421 | 2020-06-02 20:12:03 +0100 | [diff] [blame] | 39 | return {}; |
| 40 | }, |
| 41 | computed: { |
| 42 | selectedIndex() { |
| 43 | return this.file.selectedIndex; |
| 44 | }, |
| 45 | style() { |
Pablo Gamito | b46238c | 2020-05-25 11:42:09 +0100 | [diff] [blame] | 46 | if (typeof this.height == 'number') { |
| 47 | return `height: ${this.height}px`; |
| 48 | } else { |
| 49 | return `height: ${this.height}`; |
| 50 | } |
Pablo Gamito | d8266be | 2020-08-03 15:22:19 +0100 | [diff] [blame] | 51 | }, |
Adam Pardyl | 367cc8c | 2019-07-16 12:20:13 +0200 | [diff] [blame] | 52 | }, |
| 53 | methods: { |
| 54 | arrowUp() { |
Pablo Gamito | d8266be | 2020-08-03 15:22:19 +0100 | [diff] [blame] | 55 | return true; |
Adam Pardyl | 367cc8c | 2019-07-16 12:20:13 +0200 | [diff] [blame] | 56 | }, |
| 57 | arrowDown() { |
| 58 | return true; |
| 59 | }, |
Pablo Gamito | d8266be | 2020-08-03 15:22:19 +0100 | [diff] [blame] | 60 | selectFrameAtTime(timestamp) { |
| 61 | const time = (timestamp - this.file.timeline[0]) / 1000000000 + EPSILON; |
Pablo Gamito | f25221c | 2020-08-06 18:26:42 +0100 | [diff] [blame] | 62 | this.$refs.video.currentTime = time; |
Adam Pardyl | 367cc8c | 2019-07-16 12:20:13 +0200 | [diff] [blame] | 63 | }, |
Pablo Gamito | d8266be | 2020-08-03 15:22:19 +0100 | [diff] [blame] | 64 | selectFrame(idx) { |
| 65 | this.selectFrameAtTime(this.file.timeline[idx]); |
| 66 | }, |
| 67 | jumpToSelectedIndex() { |
| 68 | this.selectFrame(this.file.selectedIndex); |
| 69 | }, |
Adam Pardyl | 367cc8c | 2019-07-16 12:20:13 +0200 | [diff] [blame] | 70 | }, |
| 71 | watch: { |
| 72 | selectedIndex() { |
| 73 | this.selectFrame(this.file.selectedIndex); |
Pablo Gamito | d8266be | 2020-08-03 15:22:19 +0100 | [diff] [blame] | 74 | }, |
Adam Pardyl | 367cc8c | 2019-07-16 12:20:13 +0200 | [diff] [blame] | 75 | }, |
Pablo Gamito | 94b816e | 2020-06-10 12:42:56 +0100 | [diff] [blame] | 76 | mounted() { |
| 77 | this.$el.addEventListener('canplay', (e) => { |
| 78 | this.$emit('loaded'); |
| 79 | }); |
| 80 | }, |
Pablo Gamito | d8266be | 2020-08-03 15:22:19 +0100 | [diff] [blame] | 81 | }; |
Adam Pardyl | 367cc8c | 2019-07-16 12:20:13 +0200 | [diff] [blame] | 82 | |
| 83 | </script> |
| 84 | <style> |
Adam Pardyl | 367cc8c | 2019-07-16 12:20:13 +0200 | [diff] [blame] | 85 | </style> |