1e41f4b71Sopenharmony_ci# video
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ci>  **NOTE**
5e41f4b71Sopenharmony_ci>
6e41f4b71Sopenharmony_ci>  This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version.
7e41f4b71Sopenharmony_ci
8e41f4b71Sopenharmony_ciThe **\<video>** component provides a video player.
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci## Child Components
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ciNot supported
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci## Attributes
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ciIn addition to the [universal attributes](js-components-common-attributes.md), the following attributes are supported.
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci| Name      | Type     | Default Value  | Mandatory  | Description                                      |
21e41f4b71Sopenharmony_ci| -------- | ------- | ----- | ---- | ---------------------------------------- |
22e41f4b71Sopenharmony_ci| muted    | boolean | false | No   | Whether the video is muted.                               |
23e41f4b71Sopenharmony_ci| src      | string  | -     | No   | Path of the video content to play.                              |
24e41f4b71Sopenharmony_ci| autoplay | boolean | false | No   | Whether the video is played automatically after being rendered.                               |
25e41f4b71Sopenharmony_ci| controls | boolean | true  | No   | Whether the control bar is displayed during video playback. If the value is set to **false**, the control bar is not displayed. The default value is **true**, indicating that the platform can either show or hide the control bar.|
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci## Styles
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ciIn addition to the [universal styles](js-components-common-styles.md), the following styles are supported.
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci| Name        | Type    | Default Value    | Mandatory  | Description                                      |
33e41f4b71Sopenharmony_ci| ---------- | ------ | ------- | ---- | ---------------------------------------- |
34e41f4b71Sopenharmony_ci| object-fit | string | contain | No   | Video scale type. If **poster** has been assigned a value, the setting of this style will affect the scaling type of the video poster. For details, see object-fit enums.|
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci**Table 1** object-fit enums
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci| Type  | Description                       |
39e41f4b71Sopenharmony_ci| ---- | ------------------------- |
40e41f4b71Sopenharmony_ci| fill | The image is resized to fill the display area, and its aspect ratio is not retained.|
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci## Events
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ciIn addition to the [universal events](js-components-common-events.md), the following events are supported.
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci| Name        | Parameter                                      | Description                                   |
48e41f4b71Sopenharmony_ci| ---------- | ---------------------------------------- | ------------------------------------- |
49e41f4b71Sopenharmony_ci| prepared   | { duration: value }<sup>5+</sup> | Triggered when the video preparation is complete. The video duration (in seconds) is obtained from **duration**.|
50e41f4b71Sopenharmony_ci| start      | -                                        | Triggered when the video is played.                            |
51e41f4b71Sopenharmony_ci| pause      | -                                        | Triggered when the video playback is paused.                            |
52e41f4b71Sopenharmony_ci| finish     | -                                        | Triggered when the video playback is finished.                          |
53e41f4b71Sopenharmony_ci| error      | -                                        | Triggered when the video playback fails.                          |
54e41f4b71Sopenharmony_ci| seeking    | { currenttime: value }    | Triggered to report the time (in seconds) when the progress bar is being dragged.                 |
55e41f4b71Sopenharmony_ci| seeked     | { currenttime: value }    | Triggered to report the playback time (in seconds) when the user finishes dragging the progress bar.              |
56e41f4b71Sopenharmony_ci| timeupdate | { currenttime: value }    | Triggered once per 250 ms when the playback progress changes. The unit of the current playback time is second.      |
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci## Methods
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ciIn addition to the [universal methods](js-components-common-methods.md), the following methods are supported.
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ci| Name            | Parameter                                   | Description               |
64e41f4b71Sopenharmony_ci| -------------- | ------------------------------------- | ----------------- |
65e41f4b71Sopenharmony_ci| start          | -                                     | Starts playing a video.          |
66e41f4b71Sopenharmony_ci| pause          | -                                     | Pauses a video.        |
67e41f4b71Sopenharmony_ci| setCurrentTime | { currenttime: value } | Sets the video playback position, in seconds.|
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci>  **NOTE**
70e41f4b71Sopenharmony_ci>
71e41f4b71Sopenharmony_ci>  The methods in the above table can be called after the **attached** callback is invoked.
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci## Example
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci```html
76e41f4b71Sopenharmony_ci<!-- xxx.hml -->
77e41f4b71Sopenharmony_ci<div class="container">
78e41f4b71Sopenharmony_ci  <video id='videoId' src='/common/myDeram.mp4' muted='false' autoplay='false'
79e41f4b71Sopenharmony_ci         controls='true' onprepared='preparedCallback' onstart='startCallback'
80e41f4b71Sopenharmony_ci         onpause='pauseCallback' onfinish='finishCallback' onerror='errorCallback'
81e41f4b71Sopenharmony_ci         onseeking='seekingCallback' onseeked='seekedCallback' 
82e41f4b71Sopenharmony_ci         ontimeupdate='timeupdateCallback'
83e41f4b71Sopenharmony_ci         style="object-fit:fill; width:80%; height:400px;"
84e41f4b71Sopenharmony_ci         onclick="change_start_pause">
85e41f4b71Sopenharmony_ci   </video>
86e41f4b71Sopenharmony_ci</div>
87e41f4b71Sopenharmony_ci```
88e41f4b71Sopenharmony_ci
89e41f4b71Sopenharmony_ci```css
90e41f4b71Sopenharmony_ci/* xxx.css */
91e41f4b71Sopenharmony_ci.container {
92e41f4b71Sopenharmony_ci  justify-content: center;
93e41f4b71Sopenharmony_ci  align-items: center;
94e41f4b71Sopenharmony_ci}
95e41f4b71Sopenharmony_ci```
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ci```js
98e41f4b71Sopenharmony_ci// xxx.js
99e41f4b71Sopenharmony_ciexport default {
100e41f4b71Sopenharmony_ci  data: {
101e41f4b71Sopenharmony_ci    event:'',
102e41f4b71Sopenharmony_ci    seekingtime:'',
103e41f4b71Sopenharmony_ci    timeupdatetime:'',
104e41f4b71Sopenharmony_ci    seekedtime:'',
105e41f4b71Sopenharmony_ci    isStart: true,
106e41f4b71Sopenharmony_ci    duration: '',
107e41f4b71Sopenharmony_ci  },
108e41f4b71Sopenharmony_ci  preparedCallback:function(e){ this.event = 'Video successfully connected'; this.duration = e.duration;},
109e41f4b71Sopenharmony_ci  startCallback:function(){this.event = 'Playback starts.';},
110e41f4b71Sopenharmony_ci  pauseCallback:function(){this.event = 'Playback pauses.';},
111e41f4b71Sopenharmony_ci  finishCallback:function(){this.event = 'Playback ends.';},
112e41f4b71Sopenharmony_ci  errorCallback:function(){this.event = 'Playback error.';},
113e41f4b71Sopenharmony_ci  seekingCallback:function(e){ this.seekingtime = e.currenttime; },
114e41f4b71Sopenharmony_ci  timeupdateCallback:function(e){ this.timeupdatetime = e.currenttime;},
115e41f4b71Sopenharmony_ci  change_start_pause: function() {
116e41f4b71Sopenharmony_ci    if(this.isStart) {
117e41f4b71Sopenharmony_ci      this.$element('videoId').pause();
118e41f4b71Sopenharmony_ci      this.isStart = false;
119e41f4b71Sopenharmony_ci    } else {
120e41f4b71Sopenharmony_ci      this.$element('videoId').start();
121e41f4b71Sopenharmony_ci      this.isStart = true; 
122e41f4b71Sopenharmony_ci    }
123e41f4b71Sopenharmony_ci  },
124e41f4b71Sopenharmony_ci}
125e41f4b71Sopenharmony_ci```
126