• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Video
2
3The **Video** component is used to play a video and control its playback.
4
5>  **NOTE**
6>
7>  This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
8>
9>  The **Video** component provides only simple video playback features. For complex video playback control scenarios, consider using the [AVPlayer](../../apis-media-kit/js-apis-media.md#avplayer9) API in conjunction with the [XComponent](ts-basic-components-xcomponent.md) component.
10
11## Required Permissions
12
13To use online videos, you must apply for the ohos.permission.INTERNET permission. For details about how to apply for a permission, see [Declaring Permissions](../../../security/AccessToken/declare-permissions.md).
14
15
16## Child Components
17
18Not supported
19
20
21## APIs
22
23### Video
24
25Video(value: VideoOptions)
26
27**Atomic service API**: This API can be used in atomic services since API version 11.
28
29**System capability**: SystemCapability.ArkUI.ArkUI.Full
30
31**Parameters**
32
33| Name| Type| Mandatory| Description|
34| -------- | -------- | -------- | -------- |
35| value | [VideoOptions](#videooptions) | Yes| Video information.|
36
37##  VideoOptions
38
39**Atomic service API**: This API can be used in atomic services since API version 11.
40
41**System capability**: SystemCapability.ArkUI.ArkUI.Full
42
43| Name             | Type                                                    | Mandatory| Description                                                    |
44| ------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
45| src                 | string \| [Resource](ts-types.md#resource)                            | No  | Video source, which can be either a local or a network video.<br>The Resource type allows cross-package and cross-module access to resource files and is commonly used for accessing local videos.<br>- Resources in the rawfile folder are supported, which means that you can reference video files with **$rawfile**.<br>The string type is used for loading local videos and, more frequently, network videos.<br>- Network video URLs are supported.<br>- Strings with the **file://** prefix, that is, [application sandbox URIs](../../apis-core-file-kit/js-apis-file-fileuri.md#constructor10): **file://\<bundleName>/\<sandboxPath>**, are supported. They are used to access resources in the application sandbox path. Ensure that the application has the read permission to the files in the specified path.<br>**NOTE**<br>The supported video formats are MP4, MKV, and TS.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
46| currentProgressRate | number \| string \| [PlaybackSpeed<sup>8+</sup>](#playbackspeed8) | No  | Video playback speed.<br>**NOTE**<br>The value of the number type can only be **0.75**, **1.0**, **1.25**, **1.75**, or **2.0**.<br>For the string type, numeric string values, for example **0.75**, **1.0**, **1.25**, **1.75**, and **2.0**, are supported.<br>Default value: 1.0 \| PlaybackSpeed.Speed_Forward_1_00_X<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
47| previewUri          | string \| [PixelMap](../../apis-image-kit/js-apis-image.md#pixelmap7) \| [Resource](ts-types.md#resource)  | No  | Path of the preview image displayed before the video playback starts. By default, no preview image is displayed.<br>The string type can be used to load online images and local images.<br>- URLs are supported for loading online images.<br>- Relative paths are supported for loading local images, for example, **previewUri: "common/test.jpg"**. When using an image referenced using a relative path, the component cannot be called across bundles or modules.<br>- Strings with the **file://** prefix, that is, [application sandbox URIs](../../apis-core-file-kit/js-apis-file-fileuri.md#constructor10): **file://\<bundleName>/\<sandboxPath>**, are supported. They are used to access resources in the application sandbox path. Ensure that the application has the read permission to the files in the specified path.<br>The Resource type allows cross-package and cross-module access to resource files.<br>- Resources in the **rawfile** folder are supported, which means that you can reference video files with **\\$rawfile**.<br>- You can use **\\$r** to reference images in system or application resources.<br>**Atomic service API**: This API can be used in atomic services since API version 11.                |
48| controller          | [VideoController](#videocontroller)                          | No  | Video controller to control the video playback status.<br>**Atomic service API**: This API can be used in atomic services since API version 11.                    |
49| imageAIOptions<sup>12+</sup>  | [ImageAIOptions](ts-image-common.md#imageaioptions) | No  | AI image analysis options. You can configure the analysis type or bind an analyzer controller through this parameter.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
50| posterOptions<sup>18+</sup>  | [PosterOptions](#posteroptions18) | No  | Display options for the first frame of the video.<br>**Atomic service API**: This API can be used in atomic services since API version 18.|
51
52## PlaybackSpeed<sup>8+</sup>
53
54**Atomic service API**: This API can be used in atomic services since API version 11.
55
56**System capability**: SystemCapability.ArkUI.ArkUI.Full
57
58| Name                | Description          |
59| -------------------- | -------------- |
60| Speed_Forward_0_75_X | 0.75x playback speed.|
61| Speed_Forward_1_00_X | 1x playback speed.   |
62| Speed_Forward_1_25_X | 1.25x playback speed.|
63| Speed_Forward_1_75_X | 1.75x playback speed.|
64| Speed_Forward_2_00_X | 2x playback speed.   |
65
66## Attributes
67
68In addition to the [universal attributes](ts-component-general-attributes.md), the following attributes are supported.
69
70### muted
71
72muted(value: boolean)
73
74Specifies whether to mute the video.
75
76**Atomic service API**: This API can be used in atomic services since API version 11.
77
78**System capability**: SystemCapability.ArkUI.ArkUI.Full
79
80**Parameters**
81
82| Name| Type   | Mandatory| Description                        |
83| ------ | ------- | ---- | ---------------------------- |
84| value  | boolean | Yes  | Whether to mute the video.<br>**true**: Mute the video.<br>**false**: Unmute the video.<br>Default value: **false**|
85
86### autoPlay
87
88autoPlay(value: boolean)
89
90Specifies whether to enable autoplay.
91
92**Atomic service API**: This API can be used in atomic services since API version 11.
93
94**System capability**: SystemCapability.ArkUI.ArkUI.Full
95
96**Parameters**
97
98| Name| Type   | Mandatory| Description                            |
99| ------ | ------- | ---- | -------------------------------- |
100| value  | boolean | Yes  | Whether to enable autoplay.<br>**true**: Enable autoplay.<br>**false**: Disable autoplay.<br>Default value: **false**|
101
102### controls
103
104controls(value: boolean)
105
106Specifies whether to display the video playback control bar.
107
108**Atomic service API**: This API can be used in atomic services since API version 11.
109
110**System capability**: SystemCapability.ArkUI.ArkUI.Full
111
112**Parameters**
113
114| Name| Type   | Mandatory| Description                                           |
115| ------ | ------- | ---- | ----------------------------------------------- |
116| value  | boolean | Yes  | Whether to display the video playback control bar.<br>**true**: Display the video playback control bar.<br>**false**: Do not display the video playback control bar.<br>Default value: **true**|
117
118### objectFit
119
120objectFit(value: ImageFit)
121
122Sets the video scale type.
123
124**Atomic service API**: This API can be used in atomic services since API version 11.
125
126**System capability**: SystemCapability.ArkUI.ArkUI.Full
127
128**Parameters**
129
130| Name| Type                                     | Mandatory| Description                            |
131| ------ | ----------------------------------------- | ---- | -------------------------------- |
132| value  | [ImageFit](ts-appendix-enums.md#imagefit) | Yes  | Video scale type.<br>Default value: **Cover**|
133
134### loop
135
136loop(value: boolean)
137
138Specifies whether to repeat the video.
139
140**Atomic service API**: This API can be used in atomic services since API version 11.
141
142**System capability**: SystemCapability.ArkUI.ArkUI.Full
143
144**Parameters**
145
146| Name| Type   | Mandatory| Description                                    |
147| ------ | ------- | ---- | ---------------------------------------- |
148| value  | boolean | Yes  | Whether to repeat the video.<br>**true**: Repeat the video.<br>**false**: Do not repeat the video.<br>Default value: **false**|
149
150### enableAnalyzer<sup>12+</sup>
151
152enableAnalyzer(enable: boolean)
153
154Sets whether to enable the AI analyzer, which supports subject recognition, text recognition, and object lookup.
155After this feature is enabled, the video automatically enters an analysis state to process the current frame when playback is paused, and exits the analysis state when playback is resumed.
156Note that if this attribute and the [overlay](ts-universal-attributes-overlay.md) attribute are both set, [CustomBuilder](ts-types.md#custombuilder8) specified in [overlay](ts-universal-attributes-overlay.md) has no effect.
157
158**Atomic service API**: This API can be used in atomic services since API version 12.
159
160**System capability**: SystemCapability.ArkUI.ArkUI.Full
161
162**Parameters**
163
164| Name| Type| Mandatory| Description|
165| -------- | -------- | -------- | -------- |
166| enable | boolean | Yes| Whether to enable the AI analyzer.<br>**true**: Enable the AI analyzer.<br>**false**: Disable the AI analyzer.<br>Default value: **false**|
167
168> **NOTE**
169>
170> This feature is available only when the custom control bar is used (that is, when the [controls](#controls) attribute is set to **false**).
171>
172> This feature depends on device capabilities.
173
174### analyzerConfig<sup>12+</sup>
175
176analyzerConfig(config: ImageAnalyzerConfig)
177
178Provides AI analyzer configuration.
179
180**Atomic service API**: This API can be used in atomic services since API version 12.
181
182**System capability**: SystemCapability.ArkUI.ArkUI.Full
183
184| Name| Type| Mandatory| Description|
185| -------- | -------- | -------- | -------- |
186| config | [ImageAnalyzerConfig](ts-image-common.md#imageanalyzerconfig) | Yes| AI analysis type.|
187
188### enableShortcutKey<sup>15+</sup>
189
190enableShortcutKey(enabled: boolean)
191
192Sets whether the component responds to keyboard shortcuts when it has focus.
193
194Currently, the component can respond to the following keys when it is in focus: spacebar for playing or pausing the video, up or down arrow key for adjusting the video volume, and left or right arrow key for fast forwarding or rewinding the video.
195
196**Atomic service API**: This API can be used in atomic services since API version 15.
197
198**System capability**: SystemCapability.ArkUI.ArkUI.Full
199
200| Name | Type   | Mandatory| Description                                  |
201| ------- | ------- | ---- | -------------------------------------- |
202| enabled | boolean | Yes  | Whether to enable the shortcut key response.<br>**true**: Enable the shortcut key response.<br>**false**: Disable the shortcut key response.<br>Default value: **false**|
203
204## Events
205
206In addition to the [universal events](ts-component-general-events.md), the following events are supported.
207
208### onStart
209
210onStart(event: VoidCallback)
211
212Triggered when the video playback starts.
213
214**Atomic service API**: This API can be used in atomic services since API version 11.
215
216**System capability**: SystemCapability.ArkUI.ArkUI.Full
217
218**Parameters**
219
220| Name| Type                                          | Mandatory| Description                                |
221| ------ | --------------------------------------------- | ---- | ----------------------------------- |
222| event  | [VoidCallback](ts-types.md#voidcallback12)    | Yes  | Callback invoked when the video playback starts.       |
223
224### onPause
225
226onPause(event: VoidCallback)
227
228Triggered when the video playback is paused.
229
230**Atomic service API**: This API can be used in atomic services since API version 11.
231
232**System capability**: SystemCapability.ArkUI.ArkUI.Full
233
234**Parameters**
235
236| Name| Type                                          | Mandatory| Description                                |
237| ------ | --------------------------------------------- | ---- | ----------------------------------- |
238| event  | [VoidCallback](ts-types.md#voidcallback12)    | Yes  | Callback invoked when the video playback is paused.       |
239
240### onFinish
241
242onFinish(event: VoidCallback)
243
244Triggered when the video playback is finished.
245
246**Atomic service API**: This API can be used in atomic services since API version 11.
247
248**System capability**: SystemCapability.ArkUI.ArkUI.Full
249
250**Parameters**
251
252| Name| Type                                          | Mandatory| Description                                |
253| ------ | --------------------------------------------- | ---- | ----------------------------------- |
254| event  | [VoidCallback](ts-types.md#voidcallback12)    | Yes  | Callback invoked when the video playback is finished.       |
255
256### onError
257
258onError(event: () => void)
259
260Triggered when the video playback fails.
261
262**Atomic service API**: This API can be used in atomic services since API version 11.
263
264**System capability**: SystemCapability.ArkUI.ArkUI.Full
265
266### onStop<sup>12+</sup>
267
268onStop(event: Callback&lt;void&gt;)
269
270Triggered when the video playback is stopped (after **stop()** is called).
271
272**Atomic service API**: This API can be used in atomic services since API version 12.
273
274**System capability**: SystemCapability.ArkUI.ArkUI.Full
275
276### onPrepared
277
278onPrepared(callback: Callback\<PreparedInfo>)
279
280Triggered when video preparation is complete.
281
282**Atomic service API**: This API can be used in atomic services since API version 11.
283
284**System capability**: SystemCapability.ArkUI.ArkUI.Full
285
286**Parameters**
287
288| Name  | Type  | Mandatory| Description                      |
289| -------- | ------ | ---- | -------------------------- |
290| callback | Callback\<[PreparedInfo](#preparedinfo18)> | Yes  | Duration of the video.|
291
292### onSeeking
293
294onSeeking(callback: Callback\<PlaybackInfo>)
295
296Triggered to report the current time when the progress bar is being dragged.
297
298**Atomic service API**: This API can be used in atomic services since API version 11.
299
300**System capability**: SystemCapability.ArkUI.ArkUI.Full
301
302**Parameters**
303
304| Name| Type  | Mandatory| Description                          |
305| ------ | ------ | ---- | ------------------------------ |
306| callback   | Callback\<[PlaybackInfo](#playbackinfo18)> | Yes  | Callback that provides the current playback progress.|
307
308### onSeeked
309
310onSeeked(callback: Callback\<PlaybackInfo>)
311
312Triggered to report the playback time when the user finishes dragging the progress bar.
313
314**Atomic service API**: This API can be used in atomic services since API version 11.
315
316**System capability**: SystemCapability.ArkUI.ArkUI.Full
317
318**Parameters**
319
320| Name| Type  | Mandatory| Description                          |
321| ------ | ------ | ---- | ------------------------------ |
322| callback   | Callback\<[PlaybackInfo](#playbackinfo18)> | Yes  | Callback that provides the current playback progress.|
323
324### onUpdate
325
326onUpdate(callback: Callback\<PlaybackInfo>)
327
328Triggered when the playback progress changes.
329
330**Atomic service API**: This API can be used in atomic services since API version 11.
331
332**System capability**: SystemCapability.ArkUI.ArkUI.Full
333
334**Parameters**
335
336| Name| Type  | Mandatory| Description                          |
337| ------ | ------ | ---- | ------------------------------ |
338| callback   | Callback\<[PlaybackInfo](#playbackinfo18)> | Yes  | Callback that provides the current playback progress.|
339
340### onFullscreenChange
341
342onFullscreenChange(callback: Callback\<FullscreenInfo>)
343
344Triggered when the video playback is switched between full-screen mode and non-full-screen mode.
345
346**Atomic service API**: This API can be used in atomic services since API version 11.
347
348**System capability**: SystemCapability.ArkUI.ArkUI.Full
349
350**Parameters**
351
352| Name    | Type   | Mandatory| Description                                                 |
353| ---------- | ------- | ---- | ----------------------------------------------------- |
354| callback | Callback\<[FullscreenInfo](#fullscreeninfo18)> | Yes  | Callback that indicates whether the video playback is in full-screen mode.|
355
356### FullscreenInfo<sup>18+</sup>
357
358Describes whether the video playback is in full-screen mode.
359
360**Atomic service API**: This API can be used in atomic services since API version 18.
361
362**System capability**: SystemCapability.ArkUI.ArkUI.Full
363
364| Name      | Type   | Read Only| Optional| Description                        |
365| ----------- | ------- | ---- | ----  | ---------------------------- |
366| fullscreen<sup>10+</sup>  | boolean | No| No | Callback that indicates whether the video playback is in full-screen mode.<br>**true**: The video playback is in full-screen mode.<br>**false**: The video playback is not in full-screen mode.<br>Default value: **false**<br>**Atomic service API**: This API can be used in atomic services since API version 11. |
367
368### PreparedInfo<sup>18+</sup>
369
370Describes the duration of the video.
371
372**Atomic service API**: This API can be used in atomic services since API version 18.
373
374**System capability**: SystemCapability.ArkUI.ArkUI.Full
375
376| Name      | Type   | Read Only| Optional| Description                        |
377| ----------- | ------- | ---- | ----  | ---------------------------- |
378| duration<sup>10+</sup> | number  | No| No | Duration of the video.<br>Unit: second<br>Value range: [0, +∞)<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
379
380### PlaybackInfo<sup>18+</sup>
381
382Describes the current progress of video playback.
383
384**Atomic service API**: This API can be used in atomic services since API version 18.
385
386**System capability**: SystemCapability.ArkUI.ArkUI.Full
387
388| Name      | Type   | Read Only| Optional| Description                        |
389| ----------- | ------- | ---- | ---- | ---------------------------- |
390| time<sup>10+</sup> | number  | No| No | Callback that provides the current playback progress.<br>Unit: second<br>Value range: [0, +∞)<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
391
392### PosterOptions<sup>18+</sup>
393
394Defines display options for the first frame of the video.
395
396**Atomic service API**: This API can be used in atomic services since API version 18.
397
398**System capability**: SystemCapability.ArkUI.ArkUI.Full
399
400| Name      | Type   | Read Only| Optional| Description                        |
401| ----------- | ------- | ---- | ---- | ---------------------------- |
402| showFirstFrame   | boolean | No| Yes| Whether the first frame of the video is displayed as a preview.<br>**true**: The first frame of the video is displayed as a preview.<br>**false**: The first frame of the video is not displayed as a preview.<br>Default value: **false**     |
403
404## VideoController
405
406Defines a **VideoController** object to control one or more videos. For details about available video playback examples, see [@ohos.multimedia.media](../../apis-media-kit/js-apis-media.md).
407
408**Atomic service API**: This API can be used in atomic services since API version 11.
409
410**System capability**: SystemCapability.ArkUI.ArkUI.Full
411
412### Objects to Import
413
414```ts
415let controller: VideoController = new VideoController()
416```
417
418### constructor
419
420constructor()
421
422A constructor used to create a **VideoController** object.
423
424**Atomic service API**: This API can be used in atomic services since API version 11.
425
426**System capability**: SystemCapability.ArkUI.ArkUI.Full
427
428### start
429
430start()
431
432Starts playback.
433
434**Atomic service API**: This API can be used in atomic services since API version 11.
435
436**System capability**: SystemCapability.ArkUI.ArkUI.Full
437
438### pause
439
440pause()
441
442Pauses playback. The current frame is then displayed, and playback will be resumed from this paused position.
443
444**Atomic service API**: This API can be used in atomic services since API version 11.
445
446**System capability**: SystemCapability.ArkUI.ArkUI.Full
447
448### stop
449
450stop()
451
452Stops playback. The current frame is then displayed, and playback will restart from the very beginning.
453
454**Atomic service API**: This API can be used in atomic services since API version 11.
455
456**System capability**: SystemCapability.ArkUI.ArkUI.Full
457
458### reset<sup>12+</sup>
459
460reset(): void
461
462Resets the **AVPlayer** instance of this component, which displays the current frame and sets the playback to start from the beginning for subsequent playbacks.
463
464**Atomic service API**: This API can be used in atomic services since API version 12.
465
466**System capability**: SystemCapability.ArkUI.ArkUI.Full
467
468### setCurrentTime
469
470setCurrentTime(value: number)
471
472Sets the video playback position.
473
474**Atomic service API**: This API can be used in atomic services since API version 11.
475
476**System capability**: SystemCapability.ArkUI.ArkUI.Full
477
478**Parameters**
479
480| Name  | Type  | Mandatory  | Description          |
481| ----- | ------ | ---- | -------------- |
482| value | number | Yes   | Video playback position.<br>Value range: [0, [duration](ts-media-components-video.md#preparedinfo18)], in seconds|
483
484### requestFullscreen
485
486requestFullscreen(value: boolean)
487
488Requests full-screen mode.
489
490**Atomic service API**: This API can be used in atomic services since API version 11.
491
492**System capability**: SystemCapability.ArkUI.ArkUI.Full
493
494**Parameters**
495
496| Name| Type| Mandatory| Description                        |
497| ------ | -------- | ---- | -------------------------------- |
498| value  | boolean  | Yes  | Whether to play the video in full screen mode within the application window.<br>**true**: Play the video in full screen mode within the application window.<br>**false**: Do not play the video in full screen mode within the application window.<br>Default value: **false**|
499
500### exitFullscreen
501
502exitFullscreen()
503
504Exits full-screen mode.
505
506**Atomic service API**: This API can be used in atomic services since API version 11.
507
508**System capability**: SystemCapability.ArkUI.ArkUI.Full
509
510### setCurrentTime<sup>8+</sup>
511
512setCurrentTime(value: number, seekMode: SeekMode)
513
514Sets the video playback position with the specified seek mode.
515
516**Atomic service API**: This API can be used in atomic services since API version 11.
517
518**System capability**: SystemCapability.ArkUI.ArkUI.Full
519
520**Parameters**
521
522| Name     | Type    | Mandatory  | Description          |
523| -------- | -------- | ---- | -------------- |
524| value    | number   | Yes   | Video playback position, in seconds.|
525| seekMode | [SeekMode](#seekmode8) | Yes   | Seek mode.         |
526
527## SeekMode<sup>8+</sup>
528
529**Atomic service API**: This API can be used in atomic services since API version 11.
530
531**System capability**: SystemCapability.ArkUI.ArkUI.Full
532
533| Name            | Description                        |
534| ---------------- | ---------------------------- |
535| PreviousKeyframe | Seeks to the nearest previous keyframe.  |
536| NextKeyframe     | Seeks to the nearest next keyframe.  |
537| ClosestKeyframe  | Seeks to the nearest keyframe.        |
538| Accurate         | Seeks to a specific frame, regardless of whether the frame is a keyframe.|
539
540## Example
541
542### Example 1: Implementing Basic Video Playback Features
543
544This example covers the basic aspects of video playback, including how to manage the control bar, use preview images, handle autoplay, adjust the playback speed, and operate the controller for playback control. Additionally, it demonstrates how to implement callbacks for various playback states.
545
546```ts
547// xxx.ets
548@Entry
549@Component
550struct VideoCreateComponent {
551  @State videoSrc: Resource = $rawfile('video1.mp4')
552  @State previewUri: Resource = $r('app.media.poster1')
553  @State curRate: PlaybackSpeed = PlaybackSpeed.Speed_Forward_1_00_X
554  @State isAutoPlay: boolean = false
555  @State showControls: boolean = true
556  @State isShortcutKeyEnabled: boolean = false
557  @State showFirstFrame: boolean = false
558  controller: VideoController = new VideoController()
559
560  build() {
561    Column() {
562      Video({
563        src: this.videoSrc,
564        previewUri: this.previewUri,
565        currentProgressRate: this.curRate,
566        controller: this.controller,
567        posterOptions: { showFirstFrame: this.showFirstFrame }
568      })
569        .width('100%')
570        .height(600)
571        .autoPlay(this.isAutoPlay)
572        .controls(this.showControls)
573        .enableShortcutKey(this.isShortcutKeyEnabled)
574        .onStart(() => {
575          console.info('onStart')
576        })
577        .onPause(() => {
578          console.info('onPause')
579        })
580        .onFinish(() => {
581          console.info('onFinish')
582        })
583        .onError(() => {
584          console.info('onError')
585        })
586        .onStop(() => {
587          console.info('onStop')
588        })
589        .onPrepared((e?: DurationObject) => {
590          if (e != undefined) {
591            console.info('onPrepared is ' + e.duration)
592          }
593        })
594        .onSeeking((e?: TimeObject) => {
595          if (e != undefined) {
596            console.info('onSeeking is ' + e.time)
597          }
598        })
599        .onSeeked((e?: TimeObject) => {
600          if (e != undefined) {
601            console.info('onSeeked is ' + e.time)
602          }
603        })
604        .onUpdate((e?: TimeObject) => {
605          if (e != undefined) {
606            console.info('onUpdate is ' + e.time)
607          }
608        })
609        .onFullscreenChange((e?: FullscreenObject) => {
610          if (e != undefined) {
611            console.info('onFullscreenChange is ' + e.fullscreen)
612          }
613        })
614
615      Row() {
616        Button('src').onClick(() => {
617          this.videoSrc = $rawfile('video2.mp4') // Switch the video source.
618        }).margin(5)
619        Button('previewUri').onClick(() => {
620          this.previewUri = $r('app.media.poster2') // Switch the preview image.
621        }).margin(5)
622        Button('controls').onClick(() => {
623          this.showControls = !this.showControls // Specify whether to show the control bar.
624        }).margin(5)
625      }
626
627      Row() {
628        Button('start').onClick(() => {
629          this.controller.start() // Start playback.
630        }).margin(2)
631        Button('pause').onClick(() => {
632          this.controller.pause() // Pause playback.
633        }).margin(2)
634        Button('stop').onClick(() => {
635          this.controller.stop() // Stop playback.
636        }).margin(2)
637        Button('reset').onClick(() => {
638          this.controller.reset () // Reset the AVPlayer instance.
639        }).margin(2)
640        Button('setTime').onClick(() => {
641          this.controller.setCurrentTime(10, SeekMode.Accurate) // Seek to the 10s position of the video.
642        }).margin(2)
643      }
644
645      Row() {
646        Button('rate 0.75').onClick(() => {
647          this.curRate = PlaybackSpeed.Speed_Forward_0_75_X // Play the video at the 0.75x speed.
648        }).margin(5)
649        Button('rate 1').onClick(() => {
650          this.curRate = PlaybackSpeed.Speed_Forward_1_00_X // Play the video at the 1x speed.
651        }).margin(5)
652        Button('rate 2').onClick(() => {
653          this.curRate = PlaybackSpeed.Speed_Forward_2_00_X // Play the video at the 2x speed.
654        }).margin(5)
655      }
656    }
657  }
658}
659
660interface DurationObject {
661  duration: number;
662}
663
664interface TimeObject {
665  time: number;
666}
667
668interface FullscreenObject {
669  fullscreen: boolean;
670}
671```
672
673### Example 2: Enabling AI Image Analyzer
674
675This example shows how to use the **enableAnalyzer** attribute to enable AI image analyzer.
676
677```ts
678// xxx.ets
679@Entry
680@Component
681struct ImageAnalyzerExample {
682  @State videoSrc: Resource = $rawfile('video1.mp4')
683  @State previewUri: Resource = $r('app.media.poster1')
684  @State showControls: boolean = true
685  controller: VideoController = new VideoController()
686  config: ImageAnalyzerConfig = {
687    types: [ImageAnalyzerType.SUBJECT, ImageAnalyzerType.TEXT]
688  }
689  private aiController: ImageAnalyzerController = new ImageAnalyzerController()
690  private options: ImageAIOptions = {
691    types: [ImageAnalyzerType.SUBJECT, ImageAnalyzerType.TEXT],
692    aiController: this.aiController
693  }
694
695  build() {
696    Column() {
697      Video({
698        src: this.videoSrc,
699        previewUri: this.previewUri,
700        controller: this.controller,
701        imageAIOptions: this.options
702      })
703        .width('100%')
704        .height(600)
705        .controls(false)
706        .enableAnalyzer(true)
707        .analyzerConfig(this.config)
708        .onStart(() => {
709          console.info('onStart')
710        })
711        .onPause(() => {
712          console.info('onPause')
713        })
714
715      Row() {
716        Button('start').onClick(() => {
717          this.controller.start() // Start playback.
718        }).margin(5)
719        Button('pause').onClick(() => {
720          this.controller.pause() // Pause playback.
721        }).margin(5)
722        Button('getTypes').onClick(() => {
723            this.aiController.getImageAnalyzerSupportTypes()
724        }).margin(5)
725      }
726    }
727  }
728}
729```
730
731### Example 3: Playing a Dragged-in Video
732
733This example demonstrates how to enable the **Video** component to play a video that is dragged into it.
734
735```ts
736// xxx.ets
737import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData';
738
739@Entry
740@Component
741struct Index {
742  @State videoSrc: Resource | string = $rawfile('video1.mp4');
743  private controller: VideoController = new VideoController();
744
745  build() {
746    Column() {
747      Video({
748        src: this.videoSrc,
749        controller: this.controller
750      })
751        .width('100%')
752        .height(600)
753        .onPrepared(() => {
754          // Start playing the video when it is prepared.
755          this.controller.start();
756        })
757        .onDrop((e: DragEvent) => {
758          // Handle the drop event when a video is dragged into the component.
759          // The DragEvent contains the information about the dragged-in video source. After the information is obtained, assign a value to the state variable videoSrc to change the video source of the video.
760          let record = e.getData().getRecords()[0];
761          if (record.getType() == uniformTypeDescriptor.UniformDataType.VIDEO) {
762            let videoInfo = record as unifiedDataChannel.Video;
763            this.videoSrc = videoInfo.videoUri;
764          }
765        })
766    }
767  }
768}
769```
770